refactor(backend)!: separate algorithm and data layers

Reorganize algorithm packages by business responsibility, move orchestration into services, and keep database access behind pooled repositories.

Harden analysis API validation, remove unsafe legacy simulation endpoints, and add regression and architecture boundary coverage.

BREAKING CHANGE: legacy algorithm module paths and obsolete simulation endpoints are removed.
This commit is contained in:
2026-09-04 17:30:55 +08:00
parent 9b095c7439
commit 5966d039de
91 changed files with 1418 additions and 4020 deletions
+8 -8
View File
@@ -3,7 +3,7 @@ from datetime import datetime
from psycopg import AsyncConnection
from uuid import UUID
from app.infra.db.timescaledb.composite_queries import CompositeQueries
from app.services.timeseries_analysis import TimeseriesAnalysisService
from .dependencies import get_timescale_connection, get_postgres_connection
router = APIRouter()
@@ -46,7 +46,7 @@ async def get_scada_associated_simulation_data(
)
if run_id is not None:
result = await CompositeQueries.get_scada_associated_analysis_simulation_data(
result = await TimeseriesAnalysisService.get_scada_associated_analysis_simulation_data(
timescale_conn,
postgres_conn,
device_ids_list,
@@ -56,7 +56,7 @@ async def get_scada_associated_simulation_data(
)
else:
result = (
await CompositeQueries.get_scada_associated_realtime_simulation_data(
await TimeseriesAnalysisService.get_scada_associated_realtime_simulation_data(
timescale_conn,
postgres_conn,
device_ids_list,
@@ -116,7 +116,7 @@ async def get_feature_simulation_data(
raise HTTPException(status_code=400, detail="feature_infos cannot be empty")
if run_id is not None:
result = await CompositeQueries.get_analysis_simulation_data(
result = await TimeseriesAnalysisService.get_analysis_simulation_data(
timescale_conn,
feature_infos_list,
start_time,
@@ -124,7 +124,7 @@ async def get_feature_simulation_data(
run_id,
)
else:
result = await CompositeQueries.get_realtime_simulation_data(
result = await TimeseriesAnalysisService.get_realtime_simulation_data(
timescale_conn,
feature_infos_list,
start_time,
@@ -168,7 +168,7 @@ async def get_element_associated_scada_data(
HTTPException: 当查询参数无效时返回400错误,未找到关联数据返回404错误
"""
try:
result = await CompositeQueries.get_element_associated_scada_data(
result = await TimeseriesAnalysisService.get_element_associated_scada_data(
timescale_conn, postgres_conn, element_id, start_time, end_time, use_cleaned
)
if result is None:
@@ -216,7 +216,7 @@ async def clean_scada_data(
if device_ids
else []
)
return await CompositeQueries.clean_scada_data(
return await TimeseriesAnalysisService.clean_scada_data(
timescale_conn, postgres_conn, device_ids_list, start_time, end_time
)
except ValueError as e:
@@ -246,7 +246,7 @@ async def predict_pipeline_health(
HTTPException: 当模型文件不存在返回404错误,其他错误返回400或500错误
"""
try:
return await CompositeQueries.predict_pipeline_health(
return await TimeseriesAnalysisService.predict_pipeline_health(
timescale_conn, postgres_conn, query_time
)
except ValueError as e: