52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
from typing import Any
|
|
|
|
from psycopg import AsyncConnection
|
|
|
|
|
|
def _optional_text(value: Any) -> str | None:
|
|
return str(value).strip() if value is not None else None
|
|
|
|
|
|
def _optional_float(value: Any) -> float | None:
|
|
return float(value) if value is not None else None
|
|
|
|
|
|
class ScadaInfoRepository:
|
|
"""Read SCADA metadata from the current project's business database."""
|
|
|
|
@staticmethod
|
|
async def get_scadas(conn: AsyncConnection) -> list[dict[str, Any]]:
|
|
async with conn.cursor() as cur:
|
|
await cur.execute(
|
|
"""
|
|
SELECT id,
|
|
type,
|
|
associated_element_id,
|
|
api_query_id,
|
|
transmission_mode,
|
|
transmission_frequency,
|
|
reliability,
|
|
x_coor,
|
|
y_coor
|
|
FROM public.scada_info
|
|
"""
|
|
)
|
|
records = await cur.fetchall()
|
|
|
|
return [
|
|
{
|
|
"id": str(record["id"]).strip(),
|
|
"type": str(record["type"]).strip().lower(),
|
|
"associated_element_id": _optional_text(
|
|
record["associated_element_id"]
|
|
),
|
|
"api_query_id": record["api_query_id"],
|
|
"transmission_mode": record["transmission_mode"],
|
|
"transmission_frequency": record["transmission_frequency"],
|
|
"reliability": _optional_float(record["reliability"]),
|
|
"x": _optional_float(record["x_coor"]),
|
|
"y": _optional_float(record["y_coor"]),
|
|
}
|
|
for record in records
|
|
]
|