X-Git-Url: http://www.average.org/gitweb/?a=blobdiff_plain;f=gps303%2Fopencellid.py;h=436d559bd6ca4699e2fa97d041410d4318f9ae8d;hb=ac0ca5aab2dbc4ce035cfc0e0f7175110ea180a5;hp=dc0daaee4bde2e201651dba2b3028484350208d0;hpb=45e5cd8ce6f931b3bfb291394336cf8d94d895c3;p=loctrkd.git diff --git a/gps303/opencellid.py b/gps303/opencellid.py index dc0daae..436d559 100644 --- a/gps303/opencellid.py +++ b/gps303/opencellid.py @@ -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") @@ -56,17 +58,17 @@ def qry_cell(dbname, mcc, gsm_cells): if __name__.endswith("__main__"): from datetime import datetime, timezone import sys - from .GT06mod import * + from .gps303proto import * db = connect(sys.argv[1]) c = db.cursor() c.execute( - """select timestamp, imei, clntaddr, length, proto, payload from events + """select select tstamp, packet from events where proto in (?, ?)""", (WIFI_POSITIONING.PROTO, WIFI_OFFLINE_POSITIONING.PROTO), ) - for timestamp, imei, clntaddr, length, proto, payload in c: - obj = make_object(length, proto, payload) + for timestamp, imei, clntaddr, proto, payload in c: + obj = parse_message(packet) avlat, avlon = qry_cell(sys.argv[2], obj.mcc, obj.gsm_cells) print( "{} {:+#010.8g},{:+#010.8g}".format(