]> www.average.org Git - loctrkd.git/commitdiff
lookaside returns accuracy too
authorEugene Crosser <crosser@average.org>
Thu, 4 Aug 2022 22:42:38 +0000 (00:42 +0200)
committerEugene Crosser <crosser@average.org>
Thu, 4 Aug 2022 22:42:38 +0000 (00:42 +0200)
loctrkd/googlemaps.py
loctrkd/opencellid.py
loctrkd/rectifier.py

index 6838324bd1c95062df2b4db4a62eb532bc41c8f4..b84b64d18bdb1e19e4ca668f631dccd7ba051c26 100644 (file)
@@ -53,10 +53,14 @@ def lookup(
     mnc: int,
     gsm_cells: List[Tuple[int, int, int]],
     wifi_aps: List[Tuple[str, int]],
-) -> Tuple[float, float]:
+) -> Tuple[float, float, float]:
     result = _lookup(mcc, mnc, gsm_cells, wifi_aps)
     if "location" in result:
-        return result["location"]["lat"], result["location"]["lng"]
+        return (
+            result["location"]["lat"],
+            result["location"]["lng"],
+            result["accuracy"],
+        )
     else:
         raise ValueError("google geolocation: " + str(result))
 
index ff193fd27a5f511787c9b3b671a22ce217f06a58..e05648e2d50bcbfd48c671a57d507bf82acdc7ef 100644 (file)
@@ -23,7 +23,7 @@ def shut() -> None:
 
 def lookup(
     mcc: int, mnc: int, gsm_cells: List[Tuple[int, int, int]], __: Any
-) -> Tuple[float, float]:
+) -> Tuple[float, float, float]:
     assert ldb is not None
     lc = ldb.cursor()
     lc.execute("""attach database ":memory:" as mem""")
@@ -52,4 +52,4 @@ def lookup(
     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)])
-    return avlat, avlon
+    return avlat, avlon, 99.9  # TODO estimate accuracy for real
index c8f9912c621f6c8234d5a9125c61a1e556d0df5d..585eb793d223ad37eab4fc7a2a04864f3d673c3e 100644 (file)
@@ -31,7 +31,7 @@ class QryModule:
         mnc: int,
         gsm_cells: List[Tuple[int, int, int]],
         wifi_aps: List[Tuple[str, int]],
-    ) -> Tuple[float, float]:
+    ) -> Tuple[float, float, float]:
         ...
 
 
@@ -74,14 +74,18 @@ def runserver(conf: ConfigParser) -> None:
                 zpub.send(Rept(imei=zmsg.imei, payload=rect.json).packed)
             elif isinstance(rect, HintReport):
                 try:
-                    lat, lon = qry.lookup(
+                    lat, lon, acc = qry.lookup(
                         rect.mcc,
                         rect.mnc,
                         rect.gsm_cells,
                         list((mac, strng) for _, mac, strng in rect.wifi_aps),
                     )
                     log.debug(
-                        "Approximated lat=%s, lon=%s for %s", lat, lon, rect
+                        "Approximated lat=%s, lon=%s, acc=%s for %s",
+                        lat,
+                        lon,
+                        acc,
+                        rect,
                     )
                     if proto_needanswer.get(zmsg.proto, False):
                         resp = Resp(
@@ -94,7 +98,7 @@ def runserver(conf: ConfigParser) -> None:
                     rept = CoordReport(
                         devtime=rect.devtime,
                         battery_percentage=rect.battery_percentage,
-                        accuracy=None,
+                        accuracy=acc,
                         altitude=None,
                         speed=None,
                         direction=None,