Fill demand with junction data
This commit is contained in:
@@ -149,8 +149,8 @@ def execute_update_command(name: str, cs: ChangeSet) -> ChangeSet:
|
|||||||
return set_valve(name, cs)
|
return set_valve(name, cs)
|
||||||
elif type == _s8_tag:
|
elif type == _s8_tag:
|
||||||
return set_tag(name, cs)
|
return set_tag(name, cs)
|
||||||
elif type == _s9_demand: # exception, batch command ...
|
elif type == _s9_demand:
|
||||||
return ChangeSet()
|
return set_demand(name, cs)
|
||||||
elif type == _s10_status:
|
elif type == _s10_status:
|
||||||
return set_status(name, cs)
|
return set_status(name, cs)
|
||||||
elif type == _s11_pattern:
|
elif type == _s11_pattern:
|
||||||
|
|||||||
@@ -171,6 +171,10 @@ def _read_inp(inp: str) -> ChangeSet:
|
|||||||
elif name == 'END':
|
elif name == 'END':
|
||||||
pass # :)
|
pass # :)
|
||||||
|
|
||||||
|
# if demand section is empty, fill it with junction data
|
||||||
|
demands_cs = fill_demand(file_cs['JUNCTIONS'], file_cs['DEMANDS'])
|
||||||
|
file_cs['DEMANDS'].merge(demands_cs)
|
||||||
|
|
||||||
# release file
|
# release file
|
||||||
file = {}
|
file = {}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ def get_demand_schema(name: str) -> dict[str, dict[str, Any]]:
|
|||||||
return { 'junction' : {'type': 'str' , 'optional': False , 'readonly': True },
|
return { 'junction' : {'type': 'str' , 'optional': False , 'readonly': True },
|
||||||
'demands' : {'type': 'list' , 'optional': False , 'readonly': False,
|
'demands' : {'type': 'list' , 'optional': False , 'readonly': False,
|
||||||
'element': { 'demand' : {'type': 'float' , 'optional': False , 'readonly': False },
|
'element': { 'demand' : {'type': 'float' , 'optional': False , 'readonly': False },
|
||||||
'patten' : {'type': 'str' , 'optional': True , 'readonly': False },
|
'pattern' : {'type': 'str' , 'optional': True , 'readonly': False },
|
||||||
'category': {'type': 'str' , 'optional': True , 'readonly': False }}}}
|
'category': {'type': 'str' , 'optional': True , 'readonly': False }}}}
|
||||||
|
|
||||||
|
|
||||||
@@ -120,13 +120,37 @@ def inp_in_demand(section: list[str]) -> ChangeSet:
|
|||||||
return cs
|
return cs
|
||||||
|
|
||||||
|
|
||||||
|
def fill_demand(junction_cs : ChangeSet, demand_cs : ChangeSet) -> ChangeSet:
|
||||||
|
cs = ChangeSet()
|
||||||
|
|
||||||
|
for j_cs in junction_cs.operations:
|
||||||
|
if 'demand' not in j_cs:
|
||||||
|
continue
|
||||||
|
|
||||||
|
in_demand = False
|
||||||
|
for d_cs in demand_cs.operations:
|
||||||
|
if j_cs['id'] == d_cs['junction']:
|
||||||
|
in_demand = True
|
||||||
|
break
|
||||||
|
|
||||||
|
if not in_demand:
|
||||||
|
obj_cs : dict[str, Any] = g_update_prefix | {'type': 'demand', 'junction' : j_cs['id'], 'demands' : []}
|
||||||
|
j_demand = j_cs['demand']
|
||||||
|
j_pattern = j_cs['pattern'] if 'pattern' in j_cs else None
|
||||||
|
obj_cs['demands'].append({'demand': j_demand, 'pattern' : j_pattern, 'category': None})
|
||||||
|
cs.append(obj_cs)
|
||||||
|
|
||||||
|
return cs
|
||||||
|
|
||||||
|
|
||||||
def inp_out_demand(name: str) -> list[str]:
|
def inp_out_demand(name: str) -> list[str]:
|
||||||
lines = []
|
lines = []
|
||||||
objs = read_all(name, f"select * from demands order by _order")
|
objs = read_all(name, f"select * from demands order by _order")
|
||||||
for obj in objs:
|
for obj in objs:
|
||||||
junction = obj['junction']
|
junction = obj['junction']
|
||||||
demand = obj['demand']
|
demand = obj['demand']
|
||||||
patten = obj['patten'] if obj['patten'] != None else ''
|
pattern = obj['pattern'] if obj['pattern'] != None else ''
|
||||||
category = f";{obj['category']}" if obj['category'] != None else ';'
|
category = f";{obj['category']}" if obj['category'] != None else ';'
|
||||||
lines.append(f'{junction} {demand} {patten} {category}')
|
lines.append(f'{junction} {demand} {pattern} {category}')
|
||||||
|
print(lines[-1])
|
||||||
return lines
|
return lines
|
||||||
|
|||||||
Reference in New Issue
Block a user