convert fallback location estimators to be iterators

This commit is contained in:
Sean Breckenridge 2023-02-21 19:37:27 -08:00
parent 1cf9dfe5dd
commit da8f541cdc
4 changed files with 32 additions and 20 deletions

View file

@ -1,17 +1,24 @@
# TODO: add config here which passes kwargs to estimate_from (under_accuracy)
# overwritable by passing the kwarg name here to the top-level estimate_location
from typing import Union
from datetime import datetime
from typing import Iterator
from my.location.fallback.common import estimate_from, FallbackLocation
from my.core.source import import_source
from my.location.fallback.common import estimate_from, FallbackLocation, DateExact
def estimate_location(dt: Union[datetime, float, int]) -> FallbackLocation:
# note: the import_source returns an iterator
@import_source(module_name="my.location.fallback.via_home")
def _home_estimate(dt: DateExact) -> Iterator[FallbackLocation]:
from my.location.fallback.via_home import estimate_location as via_home
yield from via_home(dt)
def estimate_location(dt: DateExact) -> FallbackLocation:
loc = estimate_from(
dt,
estimators=(via_home,)
estimators=(_home_estimate,)
)
if loc is None:
raise ValueError("Could not estimate location")