57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
from units import Value, Unit
|
|
from vec import Vec2
|
|
|
|
|
|
class GPSLoader:
|
|
@staticmethod
|
|
def load_data(filename: str) -> dict:
|
|
data = {
|
|
"times": [],
|
|
"points": [],
|
|
"altitudes": [],
|
|
"altitudes_wgs84": [],
|
|
"speeds": [],
|
|
"directions": [],
|
|
"distances": [],
|
|
"accuracies": [],
|
|
"satellites": []
|
|
}
|
|
|
|
# time [s], lat, lon, alt [m], alt_wgs84 [m], speed [m/s], dir [°], dist [km], x_acc [m], y_acc [m], sats
|
|
|
|
with open(filename, "r") as f:
|
|
content = f.read()
|
|
lines = content.splitlines()
|
|
headers, lines = lines[0], lines[1:]
|
|
|
|
for line in lines:
|
|
values = line.split(",")
|
|
values = list(map(lambda v: None if v == "NaN" else float(v), values))
|
|
|
|
if None in values:
|
|
continue
|
|
|
|
time = Value(values[0], Unit.SEC)
|
|
lat = Value(values[1], Unit.DEG)
|
|
lon = Value(values[2], Unit.DEG)
|
|
alt = Value(values[3], Unit.M)
|
|
alt_wgs84 = Value(values[4], Unit.M)
|
|
speed = Value(values[5], Unit.M_S)
|
|
dir_ = Value(values[6], Unit.DEG)
|
|
dist = Value(values[7], Unit.KM)
|
|
x_acc = Value(values[8], Unit.M)
|
|
y_acc = Value(values[9], Unit.M)
|
|
sats = Value(values[10], Unit.NONE)
|
|
|
|
data["times"].append(time)
|
|
data["points"].append(Vec2(lon.value, lat.value))
|
|
data["altitudes"].append(alt)
|
|
data["altitudes_wgs84"].append(alt_wgs84)
|
|
data["speeds"].append(speed)
|
|
data["directions"].append(dir_)
|
|
data["distances"].append(dist)
|
|
data["accuracies"].append(Vec2(x_acc.value, y_acc.value))
|
|
data["satellites"].append(sats.value)
|
|
|
|
return data
|