Support inp in quality, source, reaction, mixing
This commit is contained in:
@@ -17,6 +17,10 @@ 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 .s17_quality import inp_in_quality_new
|
||||
from .s18_sources import inp_in_source_new
|
||||
from .s19_reactions import inp_in_reaction_new
|
||||
from .s20_mixing import inp_in_mixing_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
|
||||
@@ -42,10 +46,10 @@ _handler = {
|
||||
RULES : (_L, inp_in_rule_new),
|
||||
ENERGY : (_L, inp_in_energy_new),
|
||||
EMITTERS : (_L, inp_in_emitter_new),
|
||||
QUALITY : (_L, None),
|
||||
SOURCES : (_L, None),
|
||||
REACTIONS : (_L, None),
|
||||
MIXING : (_L, None),
|
||||
QUALITY : (_L, inp_in_quality_new),
|
||||
SOURCES : (_L, inp_in_source_new),
|
||||
REACTIONS : (_L, inp_in_reaction_new),
|
||||
MIXING : (_L, inp_in_mixing_new),
|
||||
TIMES : (_S, inp_in_time_new),
|
||||
REPORT : (_S, inp_in_report_new),
|
||||
OPTIONS : (_S, inp_in_option_new),
|
||||
@@ -96,9 +100,6 @@ _level_4 = [
|
||||
]
|
||||
|
||||
|
||||
_UNKNOWN = 'UNKNOWN'
|
||||
|
||||
|
||||
def _get_offset(inp: str) -> dict[str, list[int]]:
|
||||
offset: dict[str, list[int]] = {}
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ def inp_in_emitter_new(name: str, line: str) -> None:
|
||||
junction = str(tokens[0])
|
||||
coefficient = float(tokens[1])
|
||||
|
||||
write(name, f"\ninsert into emitters (junction, coefficient) values ('{junction}', {coefficient});")
|
||||
write(name, f"insert into emitters (junction, coefficient) values ('{junction}', {coefficient});")
|
||||
|
||||
|
||||
def inp_out_emitter(name: str) -> list[str]:
|
||||
|
||||
@@ -86,6 +86,19 @@ def inp_in_quality(section: list[str]) -> ChangeSet:
|
||||
return cs
|
||||
|
||||
|
||||
def inp_in_quality_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
|
||||
|
||||
node = str(tokens[0])
|
||||
quality = float(tokens[1])
|
||||
|
||||
write(name, f"insert into quality (node, quality) values ('{node}', {quality});")
|
||||
|
||||
|
||||
def inp_out_quality(name: str) -> list[str]:
|
||||
lines = []
|
||||
objs = read_all(name, 'select * from quality')
|
||||
|
||||
@@ -131,6 +131,23 @@ def inp_in_source(section: list[str]) -> ChangeSet:
|
||||
return cs
|
||||
|
||||
|
||||
def inp_in_source_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
|
||||
|
||||
node = str(tokens[0])
|
||||
s_type = str(tokens[1].upper())
|
||||
strength = float(tokens[2])
|
||||
pattern = str(tokens[3]) if num_without_desc >= 4 else None
|
||||
pattern = f"'{pattern}'" if pattern != None else 'null'
|
||||
|
||||
write(name, f"insert into sources (node, type, strength, pattern) values ('{node}', '{s_type}', {strength}, {pattern});")
|
||||
|
||||
|
||||
|
||||
def inp_out_source(name: str) -> list[str]:
|
||||
lines = []
|
||||
objs = read_all(name, 'select * from sources')
|
||||
|
||||
@@ -222,6 +222,28 @@ def inp_in_reaction(section: list[str]) -> ChangeSet:
|
||||
return cs
|
||||
|
||||
|
||||
def inp_in_reaction_new(name: str, line: str) -> None:
|
||||
tokens = line.split()
|
||||
token0 = tokens[0].upper()
|
||||
if token0 == 'BULK' or token0 == 'WALL':
|
||||
pipe = tokens[1]
|
||||
key = token0.lower()
|
||||
value = tokens[2]
|
||||
write(name, f"insert into reactions_pipe_{key} (pipe, value) values ('{pipe}', {value});")
|
||||
|
||||
elif token0 == 'TANK':
|
||||
tank = tokens[1]
|
||||
value = tokens[2]
|
||||
write(name, f"insert into reactions_tank (tank, value) values ('{tank}', {value});")
|
||||
|
||||
else:
|
||||
line = line.upper().strip()
|
||||
for key in get_reaction_schema('').keys():
|
||||
if line.startswith(key):
|
||||
value = line.removeprefix(key).strip()
|
||||
write(name, f"update reactions set value = '{value}' where key = '{key}';")
|
||||
|
||||
|
||||
def inp_out_reaction(name: str) -> list[str]:
|
||||
lines = []
|
||||
|
||||
|
||||
@@ -125,6 +125,21 @@ def inp_in_mixing(section: list[str]) -> ChangeSet:
|
||||
return cs
|
||||
|
||||
|
||||
def inp_in_mixing_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
|
||||
|
||||
tank = str(tokens[0])
|
||||
model = str(tokens[1].upper())
|
||||
value = float(tokens[3]) if num_without_desc >= 4 else None
|
||||
value = value if value != None else 'null'
|
||||
|
||||
write(name, f"insert into mixing (tank, model, value) values ('{tank}', '{model}', {value});")
|
||||
|
||||
|
||||
def inp_out_mixing(name: str) -> list[str]:
|
||||
lines = []
|
||||
objs = read_all(name, 'select * from mixing')
|
||||
|
||||
Reference in New Issue
Block a user