feat(burst-detection): update scada analysis flow
This commit is contained in:
@@ -54,6 +54,27 @@ class ScadaRepository:
|
||||
)
|
||||
return cur.fetchall()
|
||||
|
||||
@staticmethod
|
||||
def get_latest_scada_time_sync(
|
||||
conn: Connection,
|
||||
device_ids: List[str],
|
||||
before_time: datetime | None = None,
|
||||
) -> datetime | None:
|
||||
with conn.cursor(row_factory=dict_row) as cur:
|
||||
if before_time is None:
|
||||
cur.execute(
|
||||
"SELECT max(time) AS time FROM scada.scada_data WHERE device_id = ANY(%s)",
|
||||
(device_ids,),
|
||||
)
|
||||
else:
|
||||
cur.execute(
|
||||
"SELECT max(time) AS time FROM scada.scada_data "
|
||||
"WHERE device_id = ANY(%s) AND time <= %s",
|
||||
(device_ids, before_time),
|
||||
)
|
||||
row = cur.fetchone()
|
||||
return row["time"] if row else None
|
||||
|
||||
@staticmethod
|
||||
async def get_scada_field_by_id_time_range(
|
||||
conn: AsyncConnection,
|
||||
|
||||
Reference in New Issue
Block a user