feat(scada): serve project devices through pooled API
This commit is contained in:
@@ -9,7 +9,9 @@ from app.native.wndb.core.database import read_all, try_read
|
||||
|
||||
_SCADA_VIEW_SELECT = """
|
||||
SELECT id AS device_id, device_type, node_id, link_id, api_query_id,
|
||||
transmission_mode, transmission_frequency, reliability, x, y
|
||||
transmission_mode, transmission_frequency, reliability, x, y,
|
||||
ST_X(ST_Transform(geom, 4326)) AS longitude,
|
||||
ST_Y(ST_Transform(geom, 4326)) AS latitude
|
||||
FROM gis.scada_devices
|
||||
"""
|
||||
|
||||
@@ -60,6 +62,8 @@ def _device(record: dict[str, Any]) -> dict[str, Any]:
|
||||
"reliability": _optional_int(record["reliability"]),
|
||||
"x": _optional_float(record["x"]),
|
||||
"y": _optional_float(record["y"]),
|
||||
"longitude": _optional_float(record["longitude"]),
|
||||
"latitude": _optional_float(record["latitude"]),
|
||||
}
|
||||
|
||||
|
||||
@@ -76,6 +80,18 @@ class ScadaInfoRepository:
|
||||
|
||||
return [_device(record) for record in records]
|
||||
|
||||
@staticmethod
|
||||
async def get_scada(
|
||||
conn: AsyncConnection, device_id: str
|
||||
) -> dict[str, Any] | None:
|
||||
async with conn.cursor() as cur:
|
||||
await cur.execute(
|
||||
_SCADA_VIEW_SELECT + " WHERE id = %s",
|
||||
(device_id,),
|
||||
)
|
||||
record = await cur.fetchone()
|
||||
return _device(record) if record else None
|
||||
|
||||
@staticmethod
|
||||
async def get_existing_device_ids(
|
||||
conn: AsyncConnection, device_ids: list[str]
|
||||
@@ -102,6 +118,8 @@ def get_scada_info_schema(name: str) -> dict[str, dict[str, Any]]:
|
||||
"reliability": {"type": "int", "optional": False, "readonly": True},
|
||||
"x": {"type": "float", "optional": True, "readonly": True},
|
||||
"y": {"type": "float", "optional": True, "readonly": True},
|
||||
"longitude": {"type": "float", "optional": True, "readonly": True},
|
||||
"latitude": {"type": "float", "optional": True, "readonly": True},
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user