修复路由多id的格式问题
This commit is contained in:
@@ -19,18 +19,18 @@ class ScadaRepository:
|
||||
"""
|
||||
)
|
||||
records = await cur.fetchall()
|
||||
|
||||
# 将查询结果转换为字典列表
|
||||
records_list = []
|
||||
# 将查询结果转换为字典列表(假设 record 是字典)
|
||||
scada_infos = []
|
||||
for record in records:
|
||||
record_dict = {
|
||||
"id": record[0],
|
||||
"type": record[1],
|
||||
"associated_element_id": record[2],
|
||||
"transmission_mode": record[3],
|
||||
"transmission_frequency": record[4],
|
||||
"reliability": record[5],
|
||||
}
|
||||
records_list.append(record_dict)
|
||||
scada_infos.append(
|
||||
{
|
||||
"id": record["id"], # 使用字典键
|
||||
"type": record["type"],
|
||||
"associated_element_id": record["associated_element_id"],
|
||||
"transmission_mode": record["transmission_mode"],
|
||||
"transmission_frequency": record["transmission_frequency"],
|
||||
"reliability": record["reliability"],
|
||||
}
|
||||
)
|
||||
|
||||
return records_list
|
||||
return scada_infos
|
||||
|
||||
@@ -1206,7 +1206,7 @@ def run_simulation(
|
||||
)
|
||||
)
|
||||
# DingZQ 下面这几句一定要这样,不然读取不了
|
||||
time.sleep(5) # wait 5 seconds
|
||||
# time.sleep(5) # wait 5 seconds
|
||||
|
||||
# TODO: 2025/03/24
|
||||
# DingZQ 这个名字要用随机数来处理
|
||||
|
||||
@@ -20,7 +20,6 @@ class CompositeQueries:
|
||||
device_ids: List[str],
|
||||
start_time: datetime,
|
||||
end_time: datetime,
|
||||
field: str,
|
||||
) -> List[Optional[Any]]:
|
||||
"""
|
||||
获取 SCADA 关联的 link/node 模拟值
|
||||
@@ -64,12 +63,12 @@ class CompositeQueries:
|
||||
if scada_type.lower() == "pipe_flow":
|
||||
# 查询 link 模拟数据
|
||||
res = await RealtimeRepository.get_link_field_by_time_range(
|
||||
timescale_conn, start_time, end_time, element_id, field
|
||||
timescale_conn, start_time, end_time, element_id, "flow"
|
||||
)
|
||||
elif scada_type.lower() == "pressure":
|
||||
# 查询 node 模拟数据
|
||||
res = await RealtimeRepository.get_node_field_by_time_range(
|
||||
timescale_conn, start_time, end_time, element_id, field
|
||||
timescale_conn, start_time, end_time, element_id, "pressure"
|
||||
)
|
||||
else:
|
||||
raise ValueError(f"Unknown SCADA type: {scada_type}")
|
||||
|
||||
@@ -363,27 +363,35 @@ async def insert_scada_data(
|
||||
|
||||
@router.get("/scada/by-ids-time-range")
|
||||
async def get_scada_by_ids_time_range(
|
||||
device_ids: List[str],
|
||||
start_time: datetime,
|
||||
end_time: datetime,
|
||||
device_ids: str,
|
||||
conn: AsyncConnection = Depends(get_database_connection),
|
||||
):
|
||||
device_ids_list = (
|
||||
[id.strip() for id in device_ids.split(",") if id.strip()] if device_ids else []
|
||||
)
|
||||
return await ScadaRepository.get_scada_by_ids_time_range(
|
||||
conn, device_ids, start_time, end_time
|
||||
conn, device_ids_list, start_time, end_time
|
||||
)
|
||||
|
||||
|
||||
@router.get("/scada/by-ids-field-time-range")
|
||||
async def get_scada_field_by_ids_time_range(
|
||||
device_ids: List[str],
|
||||
start_time: datetime,
|
||||
end_time: datetime,
|
||||
field: str,
|
||||
device_ids: str,
|
||||
conn: AsyncConnection = Depends(get_database_connection),
|
||||
):
|
||||
try:
|
||||
device_ids_list = (
|
||||
[id.strip() for id in device_ids.split(",") if id.strip()]
|
||||
if device_ids
|
||||
else []
|
||||
)
|
||||
return await ScadaRepository.get_scada_field_by_id_time_range(
|
||||
conn, device_ids, start_time, end_time, field
|
||||
conn, device_ids_list, start_time, end_time, field
|
||||
)
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
@@ -422,9 +430,9 @@ async def delete_scada_data(
|
||||
|
||||
@router.get("/composite/scada-simulation")
|
||||
async def get_scada_associated_simulation_data(
|
||||
device_ids: List[str],
|
||||
start_time: datetime,
|
||||
end_time: datetime,
|
||||
device_ids: str,
|
||||
scheme_type: str = Query(None, description="指定方案名称,若为空则查询实时数据"),
|
||||
scheme_name: str = Query(None, description="指定方案名称,若为空则查询实时数据"),
|
||||
timescale_conn: AsyncConnection = Depends(get_database_connection),
|
||||
@@ -437,11 +445,18 @@ async def get_scada_associated_simulation_data(
|
||||
并根据对应的 type,查询对应的模拟数据
|
||||
"""
|
||||
try:
|
||||
# 手动解析 device_ids 为 List[str],去除空格
|
||||
device_ids_list = (
|
||||
[id.strip() for id in device_ids.split(",") if id.strip()]
|
||||
if device_ids
|
||||
else []
|
||||
)
|
||||
|
||||
if scheme_type and scheme_name:
|
||||
result = await CompositeQueries.get_scada_associated_scheme_simulation_data(
|
||||
timescale_conn,
|
||||
postgres_conn,
|
||||
device_ids,
|
||||
device_ids_list, # 使用解析后的列表
|
||||
start_time,
|
||||
end_time,
|
||||
scheme_type,
|
||||
@@ -452,7 +467,7 @@ async def get_scada_associated_simulation_data(
|
||||
await CompositeQueries.get_scada_associated_realtime_simulation_data(
|
||||
timescale_conn,
|
||||
postgres_conn,
|
||||
device_ids,
|
||||
device_ids_list, # 使用解析后的列表
|
||||
start_time,
|
||||
end_time,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user