diff --git a/api/s21_times.py b/api/s21_times.py index e3c38c6..e3f6398 100644 --- a/api/s21_times.py +++ b/api/s21_times.py @@ -65,3 +65,25 @@ def set_time_cache(name: str, cs: ChangeSet) -> SqlChangeSet: def set_time(name: str, cs: ChangeSet) -> ChangeSet: return execute_command(name, set_time_cache(name, cs)) + + +def inp_in_time(section: list[str]) -> ChangeSet: + cs = g_update_prefix | { 'type' : 'time' } + keys = ['DURATION', 'HYDRAULIC TIMESTEP', 'QUALITY TIMESTEP', 'RULE TIMESTEP', 'PATTERN TIMESTEP', 'PATTERN START', 'REPORT TIMESTEP', 'REPORT START', 'START CLOCKTIME', 'STATISTIC'] + for s in section: + line = s.upper().strip() + for key in keys: + if line.startswith(key): + value = line.removeprefix(key).strip() + cs |= { key : value } + return ChangeSet(cs) + + +def inp_out_time(name: str) -> list[str]: + lines = [] + objs = read_all(name, f"select * from times") + for obj in objs: + key = obj['key'] + value = obj['value'] + lines.append(f'{key} {value}') + return lines