added GPSLoader
This commit is contained in:
parent
c5ac5f48ad
commit
ca393c6678
54
gps_loader.py
Normal file
54
gps_loader.py
Normal file
@ -0,0 +1,54 @@
|
||||
from units import Value, Unit
|
||||
from vec import Vec2
|
||||
|
||||
|
||||
class GPSLoader:
|
||||
@staticmethod
|
||||
def load_data(filename: str) -> dict:
|
||||
data = {
|
||||
"times": [],
|
||||
"points": [],
|
||||
"altitudes": [],
|
||||
"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["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
|
Loading…
Reference in New Issue
Block a user