补全 realtime scheme 中的复合 存储、查询方法
This commit is contained in:
@@ -25,7 +25,7 @@ class ScadaRepository:
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
async def get_scada_by_id_time(
|
||||
async def get_scada_by_id_time_range(
|
||||
conn: AsyncConnection, device_id: str, start_time: datetime, end_time: datetime
|
||||
) -> List[dict]:
|
||||
async with conn.cursor() as cur:
|
||||
@@ -36,19 +36,23 @@ class ScadaRepository:
|
||||
return await cur.fetchall()
|
||||
|
||||
@staticmethod
|
||||
async def get_scada_field_by_id_time(
|
||||
conn: AsyncConnection, time: datetime, device_id: str, field: str
|
||||
async def get_scada_field_by_id_time_range(
|
||||
conn: AsyncConnection,
|
||||
device_id: str,
|
||||
start_time: datetime,
|
||||
end_time: datetime,
|
||||
field: str,
|
||||
) -> Any:
|
||||
valid_fields = {"monitored_value", "cleaned_value"}
|
||||
if field not in valid_fields:
|
||||
raise ValueError(f"Invalid field: {field}")
|
||||
|
||||
query = sql.SQL(
|
||||
"SELECT {} FROM scada.scada_data WHERE time = %s AND device_id = %s"
|
||||
"SELECT {} FROM scada.scada_data WHERE time >= %s AND time <= %s AND device_id = %s"
|
||||
).format(sql.Identifier(field))
|
||||
|
||||
async with conn.cursor() as cur:
|
||||
await cur.execute(query, (time, device_id))
|
||||
await cur.execute(query, (start_time, end_time, device_id))
|
||||
row = await cur.fetchone()
|
||||
return row[field] if row else None
|
||||
|
||||
@@ -68,7 +72,7 @@ class ScadaRepository:
|
||||
await cur.execute(query, (value, time, device_id))
|
||||
|
||||
@staticmethod
|
||||
async def delete_scada_by_id_time(
|
||||
async def delete_scada_by_id_time_range(
|
||||
conn: AsyncConnection, device_id: str, start_time: datetime, end_time: datetime
|
||||
):
|
||||
async with conn.cursor() as cur:
|
||||
|
||||
Reference in New Issue
Block a user