Files
dougal-software/bin/preplots.py

42 lines
831 B
Python
Raw Normal View History

import fwr
2020-08-08 23:59:13 +02:00
"""
Preplot importing functions.
"""
def from_file (file, realpath = None):
"""
Return a list of dicts, where each dict has the structure:
{
"line_name": <int>,
"points": [
{
"line_name": <int>,
"point_number": <int>,
"easting": <float>,
"northing": <float>
},
]
}
On error, return a string describing the error condition.
"""
filepath = realpath or file["path"]
records = fwr.from_file(filepath, file)
if type(records) == str:
# This is an error message
return records
2020-08-08 23:59:13 +02:00
lines = []
line_names = set([r["line_name"] for r in records])
for line_name in line_names:
line = dict(line_name=line_name)
line_points = [r for r in records if r["line_name"] == line_name]
if line_points:
line["points"] = line_points
lines.append(line)
return lines