移除旧的InternalQueries类,更新管道查询逻辑
This commit is contained in:
@@ -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