X-Git-Url: http://average.org/gitweb/?a=blobdiff_plain;f=gps303%2Fmkgpx.py;h=ef63e04bbc17e3054ab7bc235db5e8103f2e5eb9;hb=5d269ed1a4e097d1c52ee7d7dd784d81dbd3757a;hp=e0084c3ced1002ecd2fd114e5b9979a97de8c74d;hpb=cd38837268d9df3de523be7d42d0ba358c95fbbb;p=loctrkd.git diff --git a/gps303/mkgpx.py b/gps303/mkgpx.py index e0084c3..ef63e04 100644 --- a/gps303/mkgpx.py +++ b/gps303/mkgpx.py @@ -1,17 +1,28 @@ +""" Example that produces gpx from events in evstore """ + +# run as: +# python -m gps303.mkgpx +# Generated gpx is emitted to stdout + from datetime import datetime, timezone from sqlite3 import connect import sys -from .GT06mod import * -from .opencellid import qry_cell +from .gps303proto import * db = connect(sys.argv[1]) c = db.cursor() c.execute( - "select timestamp, imei, clntaddr, length, proto, payload from events" + """select tstamp, is_incoming, packet from events + where imei = ? + and ((is_incoming = false and proto = ?) + or (is_incoming = true and proto = ?)) + order by tstamp""", + (sys.argv[2], WIFI_POSITIONING.PROTO, GPS_POSITIONING.PROTO), ) -print(""" +print( + """ @@ -19,31 +30,31 @@ xmlns="http://www.topografix.com/GPX/1/1"> Location Data -""") +""" +) -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" +for tstamp, is_incoming, packet in c: + msg = parse_message(packet, is_incoming=is_incoming) + lat, lon = msg.latitude, msg.longitude + isotime = ( + datetime.fromtimestamp(tstamp).astimezone(tz=timezone.utc).isoformat() + ) + isotime = isotime[: isotime.rfind(".")] + "Z" trkpt = """ - """.format(lat, lon, isotime) + """.format( + lat, lon, isotime + ) print(trkpt) if False: print( - datetime.fromtimestamp(timestamp) + datetime.fromtimestamp(tstamp) .astimezone(tz=timezone.utc) .isoformat(), msg, ) -print(""" +print( + """ -""") +""" +)