]> www.average.org Git - loctrkd.git/commitdiff
drop unresolvable points in mkgpx
authorEugene Crosser <crosser@average.org>
Thu, 31 Mar 2022 22:07:27 +0000 (00:07 +0200)
committerEugene Crosser <crosser@average.org>
Thu, 31 Mar 2022 22:07:27 +0000 (00:07 +0200)
gps303/mkgpx.py [new file with mode: 0644]
gps303/opencellid.py
gps303/qry.py [deleted file]

diff --git a/gps303/mkgpx.py b/gps303/mkgpx.py
new file mode 100644 (file)
index 0000000..e0084c3
--- /dev/null
@@ -0,0 +1,49 @@
+from datetime import datetime, timezone
+from sqlite3 import connect
+import sys
+
+from .GT06mod import *
+from .opencellid import qry_cell
+
+db = connect(sys.argv[1])
+c = db.cursor()
+c.execute(
+    "select timestamp, imei, clntaddr, length, proto, payload from events"
+)
+
+print("""<?xml version="1.0"?>
+<gpx version="1.1"
+creator="gps303"
+xmlns="http://www.topografix.com/GPX/1/1">
+  <name>Location Data</name>
+  <trk>
+    <name>Location Data</name>
+    <trkseg>
+""")
+
+for timestamp, imei, clntaddr, length, proto, payload in c:
+    msg = make_object(length, proto, payload)
+    if isinstance(msg, (WIFI_POSITIONING, WIFI_OFFLINE_POSITIONING)):
+        lat, lon = qry_cell(sys.argv[2], msg.mcc, msg.gsm_cells)
+        if lat is None or lon is None:
+            continue
+    elif isinstance(msg, (GPS_POSITIONING, GPS_OFFLINE_POSITIONING)):
+        lat, lon = msg.latitude, msg.longitude
+    else:
+        continue
+    isotime = datetime.fromtimestamp(timestamp).astimezone(tz=timezone.utc).isoformat()
+    isotime = isotime[:isotime.rfind(".")] + "Z"
+    trkpt = """      <trkpt lat="{}" lon="{}">
+          <time>{}</time>
+      </trkpt>""".format(lat, lon, isotime)
+    print(trkpt)
+    if False:
+        print(
+            datetime.fromtimestamp(timestamp)
+            .astimezone(tz=timezone.utc)
+            .isoformat(),
+            msg,
+        )
+print("""    </trkseg>
+  </trk>
+</gpx>""")
index dc0daaee4bde2e201651dba2b3028484350208d0..192409a5952786397ba8876865b674307694afac 100644 (file)
@@ -44,8 +44,10 @@ def qry_cell(dbname, mcc, gsm_cells):
             (mcc,),
         )
         data = list(lc.fetchall())
-        sumsig = sum([sig for _, _, sig in data])
-        nsigs = [sig / sumsig for _, _, sig in data]
+        if not data:
+            return None, None
+        sumsig = sum([1 / sig for _, _, sig in data])
+        nsigs = [1 / sig / sumsig for _, _, sig in data]
         avlat = sum([lat * nsig for (lat, _, _), nsig in zip(data, nsigs)])
         avlon = sum([lon * nsig for (_, lon, _), nsig in zip(data, nsigs)])
         # lc.execute("drop table mem.seen")
diff --git a/gps303/qry.py b/gps303/qry.py
deleted file mode 100644 (file)
index 2a8e266..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-from datetime import datetime, timezone
-from sqlite3 import connect
-import sys
-
-from .GT06mod import *
-
-db = connect(sys.argv[1])
-c = db.cursor()
-c.execute(
-    "select timestamp, imei, clntaddr, length, proto, payload from events"
-)
-for timestamp, imei, clntaddr, length, proto, payload in c:
-    print(
-        datetime.fromtimestamp(timestamp)
-        .astimezone(tz=timezone.utc)
-        .isoformat(),
-        make_object(length, proto, payload),
-    )