X-Git-Url: http://average.org/gitweb/?a=blobdiff_plain;f=loctrkd%2Fopencellid.py;h=e05648e2d50bcbfd48c671a57d507bf82acdc7ef;hb=refs%2Ftags%2F1.94;hp=22aedcf6e777fa44c2b97ea4039fbc23fb2a7a45;hpb=456fcc5a8964c84385d34a6687e83ae05ab2ddc3;p=loctrkd.git diff --git a/loctrkd/opencellid.py b/loctrkd/opencellid.py index 22aedcf..e05648e 100644 --- a/loctrkd/opencellid.py +++ b/loctrkd/opencellid.py @@ -2,6 +2,7 @@ Lookaside backend to query local opencellid database """ +from configparser import ConfigParser from sqlite3 import connect from typing import Any, Dict, List, Tuple @@ -10,7 +11,7 @@ __all__ = "init", "lookup" ldb = None -def init(conf: Dict[str, Any]) -> None: +def init(conf: ConfigParser) -> None: global ldb ldb = connect(conf["opencellid"]["dbfn"]) @@ -22,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""") @@ -42,13 +43,13 @@ def lookup( (mcc,), ) data = list(lc.fetchall()) + # lc.execute("drop table mem.seen") + lc.execute("""detach database mem""") + lc.close() if not data: - return 0.0, 0.0 + raise ValueError("No location data found in opencellid") 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") - lc.execute("""detach database mem""") - lc.close() - return avlat, avlon + return avlat, avlon, 99.9 # TODO estimate accuracy for real