Setting of valve [GPV] should be string

This commit is contained in:
WQY\qiong
2023-03-01 23:20:04 +08:00
parent 628258ef52
commit 3665e15c92
3 changed files with 21 additions and 21 deletions

View File

@@ -16,7 +16,7 @@ def get_valve_schema(name: str) -> dict[str, dict[str, Any]]:
'node2' : {'type': 'str' , 'optional': False , 'readonly': False},
'diameter' : {'type': 'float' , 'optional': False , 'readonly': False},
'v_type' : {'type': 'str' , 'optional': False , 'readonly': False},
'setting' : {'type': 'float' , 'optional': False , 'readonly': False},
'setting' : {'type': 'str' , 'optional': False , 'readonly': False},
'minor_loss' : {'type': 'float' , 'optional': False , 'readonly': False} }
@@ -28,7 +28,7 @@ def get_valve(name: str, id: str) -> dict[str, Any]:
d['node2'] = str(p['node2'])
d['diameter'] = float(p['diameter'])
d['v_type'] = str(p['type'])
d['setting'] = float(p['setting'])
d['setting'] = str(p['setting'])
d['minor_loss'] = float(p['minor_loss'])
return d
@@ -41,7 +41,7 @@ class Valve(object):
self.node2 = str(input['node2'])
self.diameter = float(input['diameter'])
self.v_type = str(input['v_type'])
self.setting = float(input['setting'])
self.setting = str(input['setting'])
self.minor_loss = float(input['minor_loss'])
self.f_type = f"'{self.type}'"
@@ -50,7 +50,7 @@ class Valve(object):
self.f_node2 = f"'{self.node2}'"
self.f_diameter = self.diameter
self.f_v_type = f"'{self.v_type}'"
self.f_setting = self.setting
self.f_setting = f"'{self.setting}'"
self.f_minor_loss = self.minor_loss
def as_dict(self) -> dict[str, Any]:
@@ -126,7 +126,7 @@ def delete_valve(name: str, cs: ChangeSet) -> ChangeSet:
# [EPANET2][IN][OUT]
# id node1 node2 diam type setting (lcoeff lcurve)
# for GPV, setting is string = head curve id
# for PCV, add loss curve if present
# [NOT SUPPORT] for PCV, add loss curve if present
#--------------------------------------------------------------
class InpValve:
def __init__(self, line: str) -> None:
@@ -141,7 +141,7 @@ class InpValve:
self.node2 = str(tokens[2])
self.diameter = float(tokens[3])
self.v_type = str(tokens[4].upper())
self.setting = float(tokens[5])
self.setting = str(tokens[5])
self.minor_loss = float(tokens[6])
self.desc = str(tokens[-1]) if has_desc else None

View File

@@ -9,7 +9,7 @@ create table valves
, node2 varchar(32) references _node(id) not null
, diameter numeric not null
, type valves_type not null
, setting numeric not null
, setting text not null
, minor_loss numeric not null
);

View File

@@ -1347,13 +1347,13 @@ class TestApi:
assert is_junction(p, 'j3')
assert is_junction(p, 'j4')
add_valve(p, ChangeSet({'id': 'v0', 'node1': 'j1', 'node2': 'j2', 'diameter': 10.0, 'v_type': VALVES_TYPE_FCV, 'setting': 0.1, 'minor_loss': 0.5 }))
add_valve(p, ChangeSet({'id': 'v0', 'node1': 'j1', 'node2': 'j2', 'diameter': 10.0, 'v_type': VALVES_TYPE_FCV, 'setting': '0.1', 'minor_loss': 0.5 }))
v0 = get_valve(p, 'v0')
assert v0['node1'] == 'j1'
assert v0['node2'] == 'j2'
assert v0['diameter'] == 10.0
assert v0['v_type'] == VALVES_TYPE_FCV
assert v0['setting'] == 0.1
assert v0['setting'] == '0.1'
assert v0['minor_loss'] == 0.5
set_valve(p, ChangeSet({'id': 'v0', 'node1': 'j3', 'node2': 'j4'}))
@@ -1369,15 +1369,15 @@ class TestApi:
v0 = get_valve(p, 'v0')
assert v0['v_type'] == VALVES_TYPE_GPV
set_valve(p, ChangeSet({'id': 'v0', 'setting': 0.2}))
set_valve(p, ChangeSet({'id': 'v0', 'setting': '0.2'}))
v0 = get_valve(p, 'v0')
assert v0['setting'] == 0.2
assert v0['setting'] == '0.2'
set_valve(p, ChangeSet({'id': 'v0', 'minor_loss': 0.1}))
v0 = get_valve(p, 'v0')
assert v0['minor_loss'] == 0.1
add_valve(p, ChangeSet({'id': 'v1', 'node1': 'j1', 'node2': 'j2', 'diameter': 10.0, 'v_type': VALVES_TYPE_FCV, 'setting': 0.1, 'minor_loss': 0.5 }))
add_valve(p, ChangeSet({'id': 'v1', 'node1': 'j1', 'node2': 'j2', 'diameter': 10.0, 'v_type': VALVES_TYPE_FCV, 'setting': '0.1', 'minor_loss': 0.5 }))
links = get_links(p)
assert len(links) == 2
assert links[0] == 'v0'
@@ -1410,7 +1410,7 @@ class TestApi:
assert is_junction(p, 'j3')
assert is_junction(p, 'j4')
cs = add_valve(p, ChangeSet({'id': 'v0', 'node1': 'j1', 'node2': 'j2', 'diameter': 10.0, 'v_type': VALVES_TYPE_FCV, 'setting': 0.1, 'minor_loss': 0.5 })).operations[0]
cs = add_valve(p, ChangeSet({'id': 'v0', 'node1': 'j1', 'node2': 'j2', 'diameter': 10.0, 'v_type': VALVES_TYPE_FCV, 'setting': '0.1', 'minor_loss': 0.5 })).operations[0]
assert cs['operation'] == 'add'
assert cs['type'] == VALVE
assert cs['id'] == 'v0'
@@ -1418,7 +1418,7 @@ class TestApi:
assert cs['node2'] == 'j2'
assert cs['diameter'] == 10.0
assert cs['v_type'] == VALVES_TYPE_FCV
assert cs['setting'] == 0.1
assert cs['setting'] == '0.1'
assert cs['minor_loss'] == 0.5
cs = execute_undo(p).operations[0]
@@ -1434,7 +1434,7 @@ class TestApi:
assert cs['node2'] == 'j2'
assert cs['diameter'] == 10.0
assert cs['v_type'] == VALVES_TYPE_FCV
assert cs['setting'] == 0.1
assert cs['setting'] == '0.1'
assert cs['minor_loss'] == 0.5
cs = execute_undo(p, True).operations[0]
@@ -1448,7 +1448,7 @@ class TestApi:
links = get_links(p)
assert len(links) == 0
add_valve(p, ChangeSet({'id': 'v0', 'node1': 'j1', 'node2': 'j2', 'diameter': 10.0, 'v_type': VALVES_TYPE_FCV, 'setting': 0.1, 'minor_loss': 0.5 }))
add_valve(p, ChangeSet({'id': 'v0', 'node1': 'j1', 'node2': 'j2', 'diameter': 10.0, 'v_type': VALVES_TYPE_FCV, 'setting': '0.1', 'minor_loss': 0.5 }))
links = get_links(p)
assert len(links) == 1
@@ -1466,7 +1466,7 @@ class TestApi:
assert cs['node2'] == 'j2'
assert cs['diameter'] == 10.0
assert cs['v_type'] == VALVES_TYPE_FCV
assert cs['setting'] == 0.1
assert cs['setting'] == '0.1'
assert cs['minor_loss'] == 0.5
cs = execute_redo(p).operations[0]
@@ -1482,7 +1482,7 @@ class TestApi:
assert cs['node2'] == 'j2'
assert cs['diameter'] == 10.0
assert cs['v_type'] == VALVES_TYPE_FCV
assert cs['setting'] == 0.1
assert cs['setting'] == '0.1'
assert cs['minor_loss'] == 0.5
cs = execute_redo(p)
@@ -1499,7 +1499,7 @@ class TestApi:
assert cs['node2'] == 'j4'
assert cs['diameter'] == 10.0
assert cs['v_type'] == VALVES_TYPE_FCV
assert cs['setting'] == 0.1
assert cs['setting'] == '0.1'
assert cs['minor_loss'] == 0.5
cs = execute_undo(p).operations[0]
@@ -1510,7 +1510,7 @@ class TestApi:
assert cs['node2'] == 'j2'
assert cs['diameter'] == 10.0
assert cs['v_type'] == VALVES_TYPE_FCV
assert cs['setting'] == 0.1
assert cs['setting'] == '0.1'
assert cs['minor_loss'] == 0.5
self.leave(p)
@@ -1522,7 +1522,7 @@ class TestApi:
add_junction(p, ChangeSet({'id': 'j0', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
add_junction(p, ChangeSet({'id': 'j1', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
add_valve(p, ChangeSet({'id': 'v0', 'node1': 'j0', 'node2': 'j1', 'diameter': 10.0, 'v_type': VALVES_TYPE_FCV, 'setting': 0.1, 'minor_loss': 0.5 }))
add_valve(p, ChangeSet({'id': 'v0', 'node1': 'j0', 'node2': 'j1', 'diameter': 10.0, 'v_type': VALVES_TYPE_FCV, 'setting': '0.1', 'minor_loss': 0.5 }))
set_tag(p, ChangeSet({'t_type': TAG_TYPE_LINK, 'id': 'v0', 'tag': 'v0t' }))
set_status(p, ChangeSet({'link': 'v0', 'status': LINK_STATUS_OPEN, 'setting': 10.0}))
set_vertex(p, ChangeSet({'link' : 'v0', 'coords': [{'x': 1.0, 'y': 2.0}, {'x': 2.0, 'y': 1.0}]}))