移除旧的InternalQueries类,更新管道查询逻辑
This commit is contained in:
@@ -130,7 +130,14 @@ from .s4_tanks import get_tank_schema, add_tank, get_tank, set_tank, get_all_tan
|
||||
from .batch_api import delete_tank_cascade
|
||||
|
||||
from .s5_pipes import PIPE_STATUS_OPEN, PIPE_STATUS_CLOSED, PIPE_STATUS_CV
|
||||
from .s5_pipes import get_pipe_schema, add_pipe, get_pipe, set_pipe, get_all_pipes
|
||||
from .s5_pipes import (
|
||||
get_pipe_schema,
|
||||
add_pipe,
|
||||
get_pipe,
|
||||
set_pipe,
|
||||
get_all_pipes,
|
||||
get_pipes_by_property,
|
||||
)
|
||||
from .batch_api import delete_pipe_cascade
|
||||
|
||||
from .s6_pumps import get_pump_schema, add_pump, get_pump, set_pump, get_all_pumps
|
||||
|
||||
@@ -54,6 +54,52 @@ def get_all_pipes(name: str) -> list[dict[str, Any]]:
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def get_pipes_by_property(
|
||||
name: str,
|
||||
fields: list[str] | None = None,
|
||||
property_conditions: dict[str, Any] | None = None,
|
||||
) -> list[dict[str, Any]]:
|
||||
if not fields:
|
||||
fields = [
|
||||
'id',
|
||||
'node1',
|
||||
'node2',
|
||||
'length',
|
||||
'diameter',
|
||||
'roughness',
|
||||
'minor_loss',
|
||||
'status',
|
||||
]
|
||||
|
||||
rows = read_all(name, "select * from pipes")
|
||||
if rows == None:
|
||||
return []
|
||||
|
||||
result = []
|
||||
for row in rows:
|
||||
if property_conditions:
|
||||
matched = True
|
||||
for key, value in property_conditions.items():
|
||||
if row[key] != value:
|
||||
matched = False
|
||||
break
|
||||
if not matched:
|
||||
continue
|
||||
|
||||
d = {}
|
||||
for field in fields:
|
||||
value = row[field]
|
||||
if field in ('length', 'diameter', 'roughness', 'minor_loss') and value is not None:
|
||||
d[field] = float(value)
|
||||
elif field in ('id', 'node1', 'node2', 'status') and value is not None:
|
||||
d[field] = str(value)
|
||||
else:
|
||||
d[field] = value
|
||||
result.append(d)
|
||||
|
||||
return result
|
||||
|
||||
class Pipe(object):
|
||||
def __init__(self, input: dict[str, Any]) -> None:
|
||||
self.type = 'pipe'
|
||||
|
||||
Reference in New Issue
Block a user