This commit is contained in:
1 parent
cd7ddd3cf6
commit
89621bc7c3
15 files changed
+289
-74
No files matched your search
@@ -11,7 +11,7 @@ import os
|
||||
from uuid import NAMESPACE_URL, uuid5
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from .config import utc_text
|
||||
from .config import retention_cutoff, utc_text
|
||||
from .coverage import milliseconds
|
||||
from .http import TransportError
|
||||
from .solarweb import ChartDataError, SolarWebClient
|
||||
@@ -92,14 +92,14 @@ class HistoryRecovery:
|
||||
def recover(self, start=None, until=None, *, now=None, stop=None):
|
||||
now = now or datetime.now(timezone.utc)
|
||||
latest = int((now - timedelta(seconds=self.config.lag_seconds)).timestamp()) // 300 * 300
|
||||
# Check the whole retained window, including days before any live observation.
|
||||
# Round up so recovery never requests an interval older than the cutoff.
|
||||
earliest = math.ceil((now - timedelta(days=self.store.retention_days)).timestamp() / 300) * 300
|
||||
# Always include the entire oldest local day, even across a DST change.
|
||||
earliest = int(retention_cutoff(now, self.store.retention_days, self.zone.key).timestamp())
|
||||
lower = milliseconds(start) // 300_000 * 300 if start else earliest
|
||||
upper = min(milliseconds(until) // 300_000 * 300, latest) if until else latest
|
||||
if lower >= upper:
|
||||
return 0
|
||||
if (start is not None or until is not None) and upper - lower > 30 * 86400:
|
||||
manual_limit = datetime.fromtimestamp(lower, self.zone) + timedelta(days=30)
|
||||
if (start is not None or until is not None) and upper > manual_limit.timestamp():
|
||||
raise ValueError("Recover at most 30 days at once")
|
||||
stamp = lambda epoch: utc_text(datetime.fromtimestamp(epoch, timezone.utc))
|
||||
present = self.store.energy_slots(self.source_id, stamp(lower), stamp(upper))
|
||||
|
||||
Reference in new issue
Block a user