X-Git-Url: http://average.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=gps303%2Fmkgpx.py;h=02a08256a10c2e3e692ba68a0ccd5577f467f4e7;hb=bf48ccad4b4b91e7d7e09d1087f5953bc2db97d7;hp=40588a0885791b347d5f3fc2ddb0f43a1b560cb6;hpb=0a3288ad7ed56d995f9e0c15527f1a3af9a6d757;p=loctrkd.git diff --git a/gps303/mkgpx.py b/gps303/mkgpx.py index 40588a0..02a0825 100644 --- a/gps303/mkgpx.py +++ b/gps303/mkgpx.py @@ -1,16 +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 .gps303proto import * -from .opencellid import qry_cell +from .zx303proto import * db = connect(sys.argv[1]) c = db.cursor() -c.execute("select tstamp, packet from events where proto in ({})" - .format(", ".join([str(n) for n in (WIFI_POSITIONING.PROTO, WIFI_OFFLINE_POSITIONING.PROTO, GPS_POSITIONING.PROTO, GPS_OFFLINE_POSITIONING.PROTO)]))) +c.execute( + """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], proto_name(WIFI_POSITIONING), proto_name(GPS_POSITIONING)), +) -print(""" +print( + """ @@ -18,23 +30,21 @@ xmlns="http://www.topografix.com/GPX/1/1"> Location Data -""") +""" +) -for tstamp, packet in c: - msg = parse_message(packet) - 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(tstamp).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( @@ -43,6 +53,8 @@ for tstamp, packet in c: .isoformat(), msg, ) -print(""" +print( + """ -""") +""" +)