Support inp in energy, emitter
This commit is contained in:
@@ -15,6 +15,8 @@ from .s11_patterns import inp_in_pattern_new
|
||||
from .s12_curves import inp_in_curve_new
|
||||
from .s13_controls import inp_in_control_new
|
||||
from .s14_rules import inp_in_rule_new
|
||||
from .s15_energy import inp_in_energy_new
|
||||
from .s16_emitters import inp_in_emitter_new
|
||||
from .s21_times import inp_in_time_new
|
||||
from .s22_report import inp_in_report_new
|
||||
from .s23_options import inp_in_option_new
|
||||
@@ -38,8 +40,8 @@ _handler = {
|
||||
CURVES : (_L, inp_in_curve_new),
|
||||
CONTROLS : (_L, inp_in_control_new),
|
||||
RULES : (_L, inp_in_rule_new),
|
||||
ENERGY : (_L, None),
|
||||
EMITTERS : (_L, None),
|
||||
ENERGY : (_L, inp_in_energy_new),
|
||||
EMITTERS : (_L, inp_in_emitter_new),
|
||||
QUALITY : (_L, None),
|
||||
SOURCES : (_L, None),
|
||||
REACTIONS : (_L, None),
|
||||
|
||||
@@ -169,6 +169,35 @@ def inp_in_energy(section: list[str]) -> ChangeSet:
|
||||
return cs
|
||||
|
||||
|
||||
def inp_in_energy_new(name: str, line: str) -> None:
|
||||
tokens = line.split()
|
||||
|
||||
if tokens[0].upper() == 'PUMP':
|
||||
pump = tokens[1]
|
||||
key = tokens[2].lower()
|
||||
value = tokens[3]
|
||||
if key == 'price':
|
||||
value = float(value)
|
||||
else:
|
||||
value = f"'{value}'"
|
||||
if key == 'efficiency':
|
||||
key = 'effic'
|
||||
|
||||
write(name, f"insert into energy_pump_{key} (pump, {key}) values ('{pump}', {value});")
|
||||
|
||||
else:
|
||||
line = line.upper().strip()
|
||||
for key in get_energy_schema('').keys():
|
||||
if line.startswith(key):
|
||||
value = line.removeprefix(key).strip()
|
||||
|
||||
# exception here
|
||||
if line.startswith('GLOBAL EFFICIENCY'):
|
||||
value = line.removeprefix('GLOBAL EFFICIENCY').strip()
|
||||
|
||||
write(name, f"update energy set value = '{value}' where key = '{key}';")
|
||||
|
||||
|
||||
def inp_out_energy(name: str) -> list[str]:
|
||||
lines = []
|
||||
|
||||
|
||||
@@ -89,6 +89,19 @@ def inp_in_emitter(section: list[str]) -> ChangeSet:
|
||||
return cs
|
||||
|
||||
|
||||
def inp_in_emitter_new(name: str, line: str) -> None:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
has_desc = tokens[-1].startswith(';')
|
||||
num_without_desc = (num - 1) if has_desc else num
|
||||
|
||||
junction = str(tokens[0])
|
||||
coefficient = float(tokens[1])
|
||||
|
||||
write(name, f"\ninsert into emitters (junction, coefficient) values ('{junction}', {coefficient});")
|
||||
|
||||
|
||||
def inp_out_emitter(name: str) -> list[str]:
|
||||
lines = []
|
||||
objs = read_all(name, 'select * from emitters')
|
||||
|
||||
@@ -111,7 +111,7 @@ def inp_in_demand_new(name: str, line: str) -> None:
|
||||
category = str(tokens[3]) if num_without_desc >= 4 else None
|
||||
category = f"'{category}'" if category != None else 'null'
|
||||
|
||||
write(name, f"\ninsert into demands (junction, demand, pattern, category) values ('{junction}', {demand}, {pattern}, {category});")
|
||||
write(name, f"insert into demands (junction, demand, pattern, category) values ('{junction}', {demand}, {pattern}, {category});")
|
||||
|
||||
|
||||
def inp_out_demand(name: str) -> list[str]:
|
||||
|
||||
Reference in New Issue
Block a user