X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=plomtask%2Fmisc.py;h=5759c0d8b6bcc5915f84b2e94a533eefa70954e7;hb=8e1a5416151dbcf506f2435823362e21d85aed2d;hp=efa8898efd97d51ad685307902f135dc920c3ee7;hpb=89624d5e05480c832a079008bbb9992f411be0dd;p=plomtask diff --git a/plomtask/misc.py b/plomtask/misc.py index efa8898..5759c0d 100644 --- a/plomtask/misc.py +++ b/plomtask/misc.py @@ -1,6 +1,7 @@ """Attributes whose values are recorded as a timestamped history.""" from datetime import datetime from typing import Any +from sqlite3 import Row from plomtask.db import DatabaseConnection @@ -32,6 +33,10 @@ class VersionedAttribute: or value != self.history[self._newest_timestamp]: self.history[datetime.now().strftime('%Y-%m-%d %H:%M:%S')] = value + def history_from_row(self, row: Row) -> None: + """Extend self.history from expected table row format.""" + self.history[row[1]] = row[2] + def at(self, queried_time: str) -> str | float: """Retrieve value of timestamp nearest queried_time from the past.""" sorted_timestamps = sorted(self.history.keys())