Files
next-tjwater-server/app/infra/db/postgresql/hydraulic_playback.py
T
jiang 4c441fcbf2
Generic Container CI/CD / test-build-publish (push) Successful in 4m13s
Server CI/CD v2 / build-test-publish-and-deploy (push) Successful in 4m13s
refactor(db): isolate hydraulic playback data access
2026-11-15 23:49:03 +08:00

25 lines
1.1 KiB
Python

"""Published network geometry used to build indexed hydraulic playback packets."""
from typing import Any
from psycopg import AsyncConnection
class HydraulicGeometryRepository:
@staticmethod
async def get_rows(conn: AsyncConnection) -> tuple[list[dict[str, Any]], list[dict[str, Any]]]:
async with conn.cursor() as cursor:
await cursor.execute("""
SELECT n.id, ST_X(ST_Transform(g.geom,4326)) AS longitude,
ST_Y(ST_Transform(g.geom,4326)) AS latitude
FROM gis.network_nodes n JOIN gis.node_geometries g ON g.node_id=n.id
WHERE g.geom IS NOT NULL AND NOT ST_IsEmpty(g.geom) ORDER BY n.id
""")
nodes = await cursor.fetchall()
await cursor.execute("""
SELECT id, start_node_id, diameter, ST_AsGeoJSON(ST_Transform(ST_LineMerge(geom),4326))::json AS geometry
FROM gis.pipes WHERE geom IS NOT NULL AND NOT ST_IsEmpty(geom) ORDER BY id
""")
pipes = await cursor.fetchall()
return nodes, pipes