refactor(db)!: adopt project-routed pooled databases

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.
This commit is contained in:
2026-08-25 18:35:05 +08:00
parent fdbcc5c033
commit fa188af0b1
181 changed files with 8446 additions and 33546 deletions
+6 -2
View File
@@ -454,8 +454,12 @@ class DataLoader:
"""读取选定pattern的保存的历史pattern信息(flow, factor)"""
factors_list = []
flow_list = []
patterns_info = read_all(project_name,
f"select * from history_patterns_flows where id = '{pattern_name}' order by _order")
patterns_info = read_all(
project_name,
"select flow, factor from network.pattern_flow_samples "
"where pattern_id = %s order by sequence_no",
(pattern_name,),
)
for item in patterns_info:
flow_list.append(float(item['flow']))
factors_list.append(float(item['factor']))
+11 -40
View File
@@ -9,7 +9,6 @@ from app.algorithms.simulation.runner import (
run_simulation_ex,
from_clock_to_seconds_2,
)
from app.services.scheme_management import store_scheme_info
from app.services.tjnetwork import (
ChangeSet,
OPTION_DEMAND_MODEL_PDA,
@@ -111,8 +110,6 @@ def burst_analysis(
datetime.now(pytz.timezone("Asia/Shanghai")).strftime("%Y-%m-%d %H:%M:%S")
+ " -- Start Copying Database."
)
# CopyProjectEx()(name, new_name,
# ['operation', 'current_operation', 'restore_operation', 'batch_operation', 'operation_table'])
copy_project(name + "_template", new_name)
print(
datetime.now(pytz.timezone("Asia/Shanghai")).strftime("%Y-%m-%d %H:%M:%S")
@@ -204,21 +201,15 @@ def burst_analysis(
modify_valve_opening=modify_valve_opening,
scheme_type="burst_analysis",
scheme_name=scheme_name,
result_db_name=name,
scheme_username=username,
scheme_detail=scheme_detail,
)
# step 3. restore the base model status
# execute_undo(name) #有疑惑
if is_project_open(new_name):
close_project(new_name)
delete_project(new_name)
# 存储方案信息到 PG 数据库
store_scheme_info(
name=name,
scheme_name=scheme_name,
scheme_type="burst_analysis",
username=username,
scheme_start_time=modify_pattern_start_time,
scheme_detail=scheme_detail,
)
############################################################
@@ -253,8 +244,6 @@ def valve_close_analysis(
datetime.now(pytz.timezone("Asia/Shanghai")).strftime("%Y-%m-%d %H:%M:%S")
+ " -- Start Copying Database."
)
# CopyProjectEx()(name, new_name,
# ['operation', 'current_operation', 'restore_operation', 'batch_operation', 'operation_table'])
copy_project(name + "_template", new_name)
print(
datetime.now(pytz.timezone("Asia/Shanghai")).strftime("%Y-%m-%d %H:%M:%S")
@@ -293,6 +282,7 @@ def valve_close_analysis(
modify_valve_opening=modify_valve_opening,
scheme_type="valve_close_Analysis",
scheme_name=scheme_name,
result_db_name=name,
)
# step 3. restore the base model
# for valve in valves:
@@ -355,8 +345,6 @@ def flushing_analysis(
datetime.now(pytz.timezone("Asia/Shanghai")).strftime("%Y-%m-%d %H:%M:%S")
+ " -- Start Copying Database."
)
# CopyProjectEx()(name, new_name,
# ['operation', 'current_operation', 'restore_operation', 'batch_operation', 'operation_table'])
copy_project(name + "_template", new_name)
print(
datetime.now(pytz.timezone("Asia/Shanghai")).strftime("%Y-%m-%d %H:%M:%S")
@@ -456,21 +444,15 @@ def flushing_analysis(
valve_control=valve_control,
scheme_type="flushing_analysis",
scheme_name=scheme_name,
result_db_name=name,
scheme_username=username,
scheme_detail=scheme_detail,
)
# step 4. restore the base model
if is_project_open(new_name):
close_project(new_name)
delete_project(new_name)
# return result
# 存储方案信息到 PG 数据库
store_scheme_info(
name=name,
scheme_name=scheme_name,
scheme_type="flushing_analysis",
username=username,
scheme_start_time=modify_pattern_start_time,
scheme_detail=scheme_detail,
)
############################################################
@@ -523,8 +505,6 @@ def contaminant_simulation(
datetime.now(pytz.timezone("Asia/Shanghai")).strftime("%Y-%m-%d %H:%M:%S")
+ " -- Start Copying Database."
)
# CopyProjectEx()(name, new_name,
# ['operation', 'current_operation', 'restore_operation', 'batch_operation', 'operation_table'])
copy_project(name + "_template", new_name)
print(
datetime.now(pytz.timezone("Asia/Shanghai")).strftime("%Y-%m-%d %H:%M:%S")
@@ -612,6 +592,9 @@ def contaminant_simulation(
modify_total_duration=modify_total_duration,
scheme_type="contaminant_analysis",
scheme_name=scheme_name,
result_db_name=name,
scheme_username=username,
scheme_detail=scheme_detail,
)
# for i in range(1,operation_step):
@@ -619,15 +602,6 @@ def contaminant_simulation(
if is_project_open(new_name):
close_project(new_name)
delete_project(new_name)
# 存储方案信息到 PG 数据库
store_scheme_info(
name=name,
scheme_name=scheme_name,
scheme_type="contaminant_analysis",
username=username,
scheme_start_time=modify_pattern_start_time,
scheme_detail=scheme_detail,
)
############################################################
@@ -660,8 +634,6 @@ def age_analysis(
datetime.now(pytz.timezone("Asia/Shanghai")).strftime("%Y-%m-%d %H:%M:%S")
+ " -- Start Copying Database."
)
# CopyProjectEx()(name, new_name,
# ['operation', 'current_operation', 'restore_operation', 'batch_operation', 'operation_table'])
copy_project(name + "_template", new_name)
print(
datetime.now(pytz.timezone("Asia/Shanghai")).strftime("%Y-%m-%d %H:%M:%S")
@@ -743,8 +715,6 @@ def pressure_regulation(
datetime.now(pytz.timezone("Asia/Shanghai")).strftime("%Y-%m-%d %H:%M:%S")
+ " -- Start Copying Database."
)
# CopyProjectEx()(name, new_name,
# ['operation', 'current_operation', 'restore_operation', 'batch_operation', 'operation_table'])
copy_project(name + "_template", new_name)
print(
datetime.now(pytz.timezone("Asia/Shanghai")).strftime("%Y-%m-%d %H:%M:%S")
@@ -779,6 +749,7 @@ def pressure_regulation(
modify_variable_pump_pattern=modify_variable_pump_pattern,
scheme_type="pressure_regulation",
scheme_name=scheme_name,
result_db_name=name,
)
if is_project_open(new_name):
close_project(new_name)