feat: add project-scoped operations
This commit is contained in:
@@ -46,6 +46,25 @@ class ScadaRepository:
|
||||
)
|
||||
return await cur.fetchall()
|
||||
|
||||
@staticmethod
|
||||
async def get_latest_scada_readings(
|
||||
conn: AsyncConnection,
|
||||
device_ids: List[str],
|
||||
) -> dict[str, dict[str, Any]]:
|
||||
"""Return at most one latest row for each requested canonical device ID."""
|
||||
if not device_ids:
|
||||
return {}
|
||||
|
||||
async with conn.cursor() as cur:
|
||||
await cur.execute(
|
||||
f"SELECT DISTINCT ON (device_id) {ScadaRepository.RESULT_COLUMNS} "
|
||||
"FROM scada.measurements WHERE device_id = ANY(%s) "
|
||||
"ORDER BY device_id, time DESC",
|
||||
(device_ids,),
|
||||
)
|
||||
rows = await cur.fetchall()
|
||||
return {str(row["device_id"]): dict(row) for row in rows}
|
||||
|
||||
@staticmethod
|
||||
def get_scada_by_ids_time_range_sync(
|
||||
conn: Connection,
|
||||
|
||||
Reference in New Issue
Block a user