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:
seanbreckenridge 2023-02-27 20:30:06 -08:00 committed by GitHub
parent 6dc5e7575f
commit 98b086f746
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 1166 additions and 190 deletions

View file

@ -1,4 +1,5 @@
from datetime import datetime, timedelta, date, timezone
import sys
from datetime import datetime, timedelta
from pathlib import Path
import pytest # type: ignore
@ -46,8 +47,15 @@ def test_tz() -> None:
tz = LTZ._get_tz(D('20201001 14:15:16'))
assert tz is not None
tz = LTZ._get_tz(datetime.min)
assert tz is not None
on_windows = sys.platform == 'win32'
if not on_windows:
tz = LTZ._get_tz(datetime.min)
assert tz is not None
else:
# seems this fails because windows doesnt support same date ranges
# https://stackoverflow.com/a/41400321/
with pytest.raises(OSError):
LTZ._get_tz(datetime.min)
def test_policies() -> None:
@ -73,36 +81,15 @@ def D(dstr: str) -> datetime:
return datetime.strptime(dstr, '%Y%m%d %H:%M:%S')
# TODO copy pasted from location.py, need to extract some common provider
@pytest.fixture(autouse=True)
def prepare(tmp_path: Path):
from .common import reset_modules
reset_modules()
LTZ.config.fast = True
from .location import _prepare_google_config
google = _prepare_google_config(tmp_path)
class location:
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 time:
class tz:
class via_location:
pass # just rely on the defaults...
from .shared_config import temp_config
conf = temp_config(tmp_path)
import my.core.cfg as C
with C.tmp_config() as config:
config.google = google
config.time = time
config.location = location
config.google = conf.google
config.time = conf.time
config.location = conf.location
yield