add fallback model
This commit is contained in:
parent
a4468a42da
commit
138afb68a7
3 changed files with 38 additions and 3 deletions
33
my/location/fallback/common.py
Normal file
33
my/location/fallback/common.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
from dataclasses import dataclass
|
||||
from typing import Optional
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from ..common import Location
|
||||
|
||||
|
||||
@dataclass
|
||||
class FallbackLocation:
|
||||
lat: float
|
||||
lon: float
|
||||
dt: datetime
|
||||
duration: int # time in seconds for how long this is valid
|
||||
accuracy: Optional[float] = None
|
||||
elevation: Optional[float] = None
|
||||
datasource: Optional[str] = None # which module provided this, useful for debugging
|
||||
|
||||
def to_location(self, end: bool = False) -> Location:
|
||||
"""
|
||||
by default the start date is used for the location
|
||||
If end is True, the start date + duration is used
|
||||
"""
|
||||
dt: datetime = self.dt
|
||||
if end:
|
||||
dt += timedelta(self.duration)
|
||||
return Location(
|
||||
lat=self.lat,
|
||||
lon=self.lon,
|
||||
dt=dt,
|
||||
accuracy=self.accuracy,
|
||||
elevation=self.elevation,
|
||||
datasource=self.datasource,
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue