location fallback (#263)
see https://github.com/karlicoss/HPI/issues/262 * move home to fallback/via_home.py * move via_ip to fallback * add fallback model * add stub via_ip file * add fallback_locations for via_ip * use protocol for locations * estimate_from helper, via_home estimator, all.py * via_home: add accuracy, cache history * add datasources to gpslogger/google_takeout * tz/via_location.py: update import to fallback * denylist docs/installation instructions * tz.via_location: let user customize cachew refresh time * add via_ip.estimate_location using binary search * use estimate_location in via_home.get_location * tests: add gpslogger to location config stub * tests: install tz related libs in test env * tz: add regression test for broken windows dates * vendorize bisect_left from python src doesnt have a 'key' parameter till python3.10
This commit is contained in:
parent
6dc5e7575f
commit
98b086f746
25 changed files with 1166 additions and 190 deletions
65
tests/shared_config.py
Normal file
65
tests/shared_config.py
Normal file
|
@ -0,0 +1,65 @@
|
|||
# Defines some shared config for tests
|
||||
|
||||
from datetime import datetime, date, timezone
|
||||
from pathlib import Path
|
||||
|
||||
from typing import Any, NamedTuple
|
||||
import my.time.tz.via_location as LTZ
|
||||
from more_itertools import one
|
||||
|
||||
|
||||
class SharedConfig(NamedTuple):
|
||||
google: Any
|
||||
location: Any
|
||||
time: Any
|
||||
|
||||
|
||||
def _prepare_google_config(tmp_path: Path):
|
||||
from .common import testdata
|
||||
try:
|
||||
track = one(testdata().rglob('italy-slovenia-2017-07-29.json'))
|
||||
except ValueError:
|
||||
raise RuntimeError('testdata not found, setup git submodules?')
|
||||
|
||||
|
||||
# todo ugh. unnecessary zipping, but at the moment takeout provider doesn't support plain dirs
|
||||
import zipfile
|
||||
with zipfile.ZipFile(tmp_path / 'takeout.zip', 'w') as zf:
|
||||
zf.writestr('Takeout/Location History/Location History.json', track.read_bytes())
|
||||
|
||||
class google_config:
|
||||
takeout_path = tmp_path
|
||||
return google_config
|
||||
|
||||
|
||||
# pass tmp_path from pytest to this helper function
|
||||
# see tests/tz.py as an example
|
||||
def temp_config(temp_path: Path) -> Any:
|
||||
from .common import reset_modules
|
||||
reset_modules()
|
||||
|
||||
LTZ.config.fast = True
|
||||
|
||||
class location:
|
||||
home_accuracy = 30_000
|
||||
home = (
|
||||
# supports ISO strings
|
||||
('2005-12-04' , (42.697842, 23.325973)), # Bulgaria, Sofia
|
||||
# supports date/datetime objects
|
||||
(date(year=1980, month=2, day=15) , (40.7128 , -74.0060 )), # NY
|
||||
# check tz handling..
|
||||
(datetime.fromtimestamp(1600000000, tz=timezone.utc), (55.7558 , 37.6173 )), # Moscow, Russia
|
||||
)
|
||||
# note: order doesn't matter, will be sorted in the data provider
|
||||
class via_ip:
|
||||
accuracy = 15_000
|
||||
class gpslogger:
|
||||
pass
|
||||
|
||||
class time:
|
||||
class tz:
|
||||
class via_location:
|
||||
pass # just rely on the defaults...
|
||||
|
||||
|
||||
return SharedConfig(google=_prepare_google_config(temp_path), location=location, time=time)
|
Loading…
Add table
Add a link
Reference in a new issue