Reorganize WNDB by responsibility and remove legacy scheme endpoints.\n\nRoute analysis and time-series access through project pools, preserve transactional realtime replacement, and refresh GIS materialized views after writes.\n\nAdd database architecture documentation, live pooling coverage, API contract updates, and executable container verification.\n\nBREAKING CHANGE: legacy scheme APIs and flat app.native.wndb module imports are removed.
55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
from typing import Any
|
|
|
|
from ..core.database import (
|
|
ChangeSet,
|
|
DatabaseCommand,
|
|
execute_command,
|
|
g_update_prefix,
|
|
read_all,
|
|
sql_literal,
|
|
)
|
|
|
|
|
|
def get_control_schema(name: str) -> dict[str, dict[str, Any]]:
|
|
return { 'controls' : {'type': 'str_list' , 'optional': False , 'readonly': False} }
|
|
|
|
|
|
def get_control(name: str) -> dict[str, Any]:
|
|
cs = read_all(name, "select line from network.controls order by sequence_no")
|
|
ds = []
|
|
for c in cs:
|
|
ds.append(c['line'])
|
|
return { 'controls': ds }
|
|
|
|
|
|
def _set_control(name: str, cs: ChangeSet) -> DatabaseCommand:
|
|
statement = 'delete from network.controls;'
|
|
for sequence_no, line in enumerate(cs.operations[0]['controls']):
|
|
statement += f"\ninsert into network.controls (sequence_no, line) values ({sequence_no}, {sql_literal(line)});"
|
|
|
|
change = g_update_prefix | { 'type': 'control', 'controls': cs.operations[0]['controls'] }
|
|
|
|
return DatabaseCommand(statement, [change])
|
|
|
|
|
|
def set_control(name: str, cs: ChangeSet) -> ChangeSet:
|
|
return execute_command(name, _set_control(name, cs))
|
|
|
|
|
|
#--------------------------------------------------------------
|
|
# [EPA2][EPA3]
|
|
# LINK linkID setting IF NODE nodeID {BELOW/ABOVE} level
|
|
# LINK linkID setting AT TIME value (units)
|
|
# LINK linkID setting AT CLOCKTIME value (units)
|
|
# (0) (1) (2) (3) (4) (5) (6) (7)
|
|
# todo...
|
|
#--------------------------------------------------------------
|
|
|
|
|
|
def inp_in_control(line: str) -> str:
|
|
return str(f"insert into network.controls (sequence_no, line) values ((select coalesce(max(sequence_no) + 1, 0) from network.controls), {sql_literal(line)});")
|
|
|
|
|
|
def inp_out_control(name: str) -> list[str]:
|
|
return get_control(name)['controls']
|