X-Git-Url: http://average.org/gitweb/?a=blobdiff_plain;f=loctrkd%2Fopencellid.py;h=e05648e2d50bcbfd48c671a57d507bf82acdc7ef;hb=refs%2Ftags%2F1.94;hp=a70dc26b2ae39c7e8a2b36a28304fa4837a9aedf;hpb=a4e4e193173d24f0f1b2020a61cee432418d5284;p=loctrkd.git diff --git a/loctrkd/opencellid.py b/loctrkd/opencellid.py index a70dc26..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""") @@ -46,9 +47,9 @@ def lookup( 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)]) - return avlat, avlon + return avlat, avlon, 99.9 # TODO estimate accuracy for real