From ca393c6678d182e0cf687b06cbaa71f95b28a794 Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Tue, 16 Apr 2024 18:41:37 +0200 Subject: [PATCH] added GPSLoader --- gps_loader.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 gps_loader.py diff --git a/gps_loader.py b/gps_loader.py new file mode 100644 index 0000000..3c3c4a6 --- /dev/null +++ b/gps_loader.py @@ -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