home · contact · privacy
Refactor VersionedAttributes, ProcessSteps, and Conditions retrieval.
[plomtask] / plomtask / misc.py
index efa8898efd97d51ad685307902f135dc920c3ee7..5759c0d8b6bcc5915f84b2e94a533eefa70954e7 100644 (file)
@@ -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())