Add time api and test
This commit is contained in:
@@ -49,4 +49,7 @@ from .s12_curves import get_curve_schema, get_curve, set_curve
|
||||
|
||||
from .s16_emitters import get_emitter_schema, get_emitter, set_emitter
|
||||
|
||||
from .s21_times import TIME_STATISTIC_NONE, TIME_STATISTIC_AVERAGED, TIME_STATISTIC_MINIMUM, TIME_STATISTIC_MAXIMUM, TIME_STATISTIC_RANGE
|
||||
from .s21_times import get_time_schema, get_time, set_time
|
||||
|
||||
from .s24_coordinates import get_node_coord
|
||||
|
||||
@@ -10,6 +10,7 @@ from .s10_status import *
|
||||
from .s11_patterns import *
|
||||
from .s12_curves import *
|
||||
from .s16_emitters import *
|
||||
from .s21_times import *
|
||||
|
||||
|
||||
def execute_add_command(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
@@ -58,6 +59,8 @@ def execute_update_command(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return set_curve(name, cs)
|
||||
elif type == 'emitter':
|
||||
return set_emitter(name, cs)
|
||||
elif type == 'time':
|
||||
return set_time(name, cs)
|
||||
|
||||
return ChangeSet()
|
||||
|
||||
|
||||
63
api/s21_times.py
Normal file
63
api/s21_times.py
Normal file
@@ -0,0 +1,63 @@
|
||||
from .operation import *
|
||||
|
||||
TIME_STATISTIC_NONE = 'NONE'
|
||||
TIME_STATISTIC_AVERAGED = 'AVERAGED'
|
||||
TIME_STATISTIC_MINIMUM = 'MINIMUM'
|
||||
TIME_STATISTIC_MAXIMUM = 'MAXIMUM'
|
||||
TIME_STATISTIC_RANGE = 'RANGE'
|
||||
|
||||
element_schema = {'type': 'str' , 'optional': True , 'readonly': False}
|
||||
|
||||
def get_time_schema(name: str) -> dict[str, dict[str, Any]]:
|
||||
return { 'DURATION' : element_schema,
|
||||
'HYDRAULIC TIMESTEP' : element_schema,
|
||||
'QUALITY TIMESTEP' : element_schema,
|
||||
'RULE TIMESTEP' : element_schema,
|
||||
'PATTERN TIMESTEP' : element_schema,
|
||||
'PATTERN START' : element_schema,
|
||||
'REPORT TIMESTEP' : element_schema,
|
||||
'REPORT START' : element_schema,
|
||||
'START CLOCKTIME' : element_schema,
|
||||
'STATISTIC' : element_schema}
|
||||
|
||||
|
||||
def get_time(name: str) -> dict[str, Any]:
|
||||
ts = read_all(name, f"select * from times")
|
||||
d = {}
|
||||
for e in ts:
|
||||
d[e['key']] = str(e['value'])
|
||||
return d
|
||||
|
||||
|
||||
def set_time(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
raw_old = get_time(name)
|
||||
|
||||
old = {}
|
||||
new = {}
|
||||
|
||||
new_dict = cs.operations[0]
|
||||
schema = get_time_schema(name)
|
||||
for key in schema.keys():
|
||||
if key in new_dict:
|
||||
old[key] = str(raw_old[key])
|
||||
new[key] = str(new_dict[key])
|
||||
|
||||
redo_cs = g_update_prefix | { 'type' : 'time' }
|
||||
|
||||
redo_sql = ''
|
||||
for key, value in new.items():
|
||||
if redo_sql != '':
|
||||
redo_sql += '\n'
|
||||
redo_sql += f"update times set value = '{value}' where key = '{key}';"
|
||||
redo_cs |= { key: value }
|
||||
|
||||
undo_cs = g_update_prefix | { 'type' : 'time' }
|
||||
|
||||
undo_sql = ''
|
||||
for key, value in old.items():
|
||||
if undo_sql != '':
|
||||
undo_sql += '\n'
|
||||
undo_sql += f"update times set value = '{value}' where key = '{key}';"
|
||||
undo_cs |= { key: value }
|
||||
|
||||
return execute_command(name, redo_sql, undo_sql, redo_cs, undo_cs)
|
||||
0
api/s22_options.py
Normal file
0
api/s22_options.py
Normal file
@@ -1500,6 +1500,102 @@ class TestApi:
|
||||
self.leave(p)
|
||||
|
||||
|
||||
def test_time(self):
|
||||
p = 'test_time'
|
||||
self.enter(p)
|
||||
|
||||
t = get_time(p)
|
||||
assert t['DURATION'] == '0:00'
|
||||
assert t['HYDRAULIC TIMESTEP'] == '1:00'
|
||||
assert t['QUALITY TIMESTEP'] == '0:05'
|
||||
assert t['RULE TIMESTEP'] == '0:05'
|
||||
assert t['PATTERN TIMESTEP'] == '1:00'
|
||||
assert t['PATTERN START'] == '0:00'
|
||||
assert t['REPORT TIMESTEP'] == '1:00'
|
||||
assert t['REPORT START'] == '0:00'
|
||||
assert t['START CLOCKTIME'] == '12:00 AM'
|
||||
assert t['STATISTIC'] == TIME_STATISTIC_NONE
|
||||
|
||||
t['STATISTIC'] = TIME_STATISTIC_AVERAGED
|
||||
set_time(p, ChangeSet(t))
|
||||
|
||||
t = get_time(p)
|
||||
assert t['DURATION'] == '0:00'
|
||||
assert t['HYDRAULIC TIMESTEP'] == '1:00'
|
||||
assert t['QUALITY TIMESTEP'] == '0:05'
|
||||
assert t['RULE TIMESTEP'] == '0:05'
|
||||
assert t['PATTERN TIMESTEP'] == '1:00'
|
||||
assert t['PATTERN START'] == '0:00'
|
||||
assert t['REPORT TIMESTEP'] == '1:00'
|
||||
assert t['REPORT START'] == '0:00'
|
||||
assert t['START CLOCKTIME'] == '12:00 AM'
|
||||
assert t['STATISTIC'] == TIME_STATISTIC_AVERAGED
|
||||
|
||||
self.leave(p)
|
||||
|
||||
|
||||
def test_time_op(self):
|
||||
p = 'test_time_op'
|
||||
self.enter(p)
|
||||
|
||||
t = get_time(p)
|
||||
assert t['DURATION'] == '0:00'
|
||||
assert t['HYDRAULIC TIMESTEP'] == '1:00'
|
||||
assert t['QUALITY TIMESTEP'] == '0:05'
|
||||
assert t['RULE TIMESTEP'] == '0:05'
|
||||
assert t['PATTERN TIMESTEP'] == '1:00'
|
||||
assert t['PATTERN START'] == '0:00'
|
||||
assert t['REPORT TIMESTEP'] == '1:00'
|
||||
assert t['REPORT START'] == '0:00'
|
||||
assert t['START CLOCKTIME'] == '12:00 AM'
|
||||
assert t['STATISTIC'] == TIME_STATISTIC_NONE
|
||||
|
||||
t['STATISTIC'] = TIME_STATISTIC_AVERAGED
|
||||
cs = set_time(p, ChangeSet(t)).operations[0]
|
||||
assert cs['operation'] == API_UPDATE
|
||||
assert cs['type'] == 'time'
|
||||
assert cs['DURATION'] == '0:00'
|
||||
assert cs['HYDRAULIC TIMESTEP'] == '1:00'
|
||||
assert cs['QUALITY TIMESTEP'] == '0:05'
|
||||
assert cs['RULE TIMESTEP'] == '0:05'
|
||||
assert cs['PATTERN TIMESTEP'] == '1:00'
|
||||
assert cs['PATTERN START'] == '0:00'
|
||||
assert cs['REPORT TIMESTEP'] == '1:00'
|
||||
assert cs['REPORT START'] == '0:00'
|
||||
assert cs['START CLOCKTIME'] == '12:00 AM'
|
||||
assert cs['STATISTIC'] == TIME_STATISTIC_AVERAGED
|
||||
|
||||
cs = execute_undo(p).operations[0]
|
||||
assert cs['operation'] == API_UPDATE
|
||||
assert cs['type'] == 'time'
|
||||
assert cs['DURATION'] == '0:00'
|
||||
assert cs['HYDRAULIC TIMESTEP'] == '1:00'
|
||||
assert cs['QUALITY TIMESTEP'] == '0:05'
|
||||
assert cs['RULE TIMESTEP'] == '0:05'
|
||||
assert cs['PATTERN TIMESTEP'] == '1:00'
|
||||
assert cs['PATTERN START'] == '0:00'
|
||||
assert cs['REPORT TIMESTEP'] == '1:00'
|
||||
assert cs['REPORT START'] == '0:00'
|
||||
assert cs['START CLOCKTIME'] == '12:00 AM'
|
||||
assert cs['STATISTIC'] == TIME_STATISTIC_NONE
|
||||
|
||||
cs = execute_redo(p).operations[0]
|
||||
assert cs['operation'] == API_UPDATE
|
||||
assert cs['type'] == 'time'
|
||||
assert cs['DURATION'] == '0:00'
|
||||
assert cs['HYDRAULIC TIMESTEP'] == '1:00'
|
||||
assert cs['QUALITY TIMESTEP'] == '0:05'
|
||||
assert cs['RULE TIMESTEP'] == '0:05'
|
||||
assert cs['PATTERN TIMESTEP'] == '1:00'
|
||||
assert cs['PATTERN START'] == '0:00'
|
||||
assert cs['REPORT TIMESTEP'] == '1:00'
|
||||
assert cs['REPORT START'] == '0:00'
|
||||
assert cs['START CLOCKTIME'] == '12:00 AM'
|
||||
assert cs['STATISTIC'] == TIME_STATISTIC_AVERAGED
|
||||
|
||||
self.leave(p)
|
||||
|
||||
|
||||
def test_snapshot(self):
|
||||
p = "test_snapshot"
|
||||
self.enter(p)
|
||||
|
||||
24
tjnetwork.py
24
tjnetwork.py
@@ -44,6 +44,12 @@ LINK_STATUS_OPEN = api.LINK_STATUS_OPEN
|
||||
LINK_STATUS_CLOSED = api.LINK_STATUS_CLOSED
|
||||
LINK_STATUS_ACTIVE = api.LINK_STATUS_ACTIVE
|
||||
|
||||
TIME_STATISTIC_NONE = api.TIME_STATISTIC_NONE
|
||||
TIME_STATISTIC_AVERAGED = api.TIME_STATISTIC_AVERAGED
|
||||
TIME_STATISTIC_MINIMUM = api.TIME_STATISTIC_MINIMUM
|
||||
TIME_STATISTIC_MAXIMUM = api.TIME_STATISTIC_MAXIMUM
|
||||
TIME_STATISTIC_RANGE = api.TIME_STATISTIC_RANGE
|
||||
|
||||
|
||||
############################################################
|
||||
# project
|
||||
@@ -360,13 +366,27 @@ def set_curve(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
def get_emitter_schema(name: str) -> dict[str, dict[str, Any]]:
|
||||
return api.get_emitter_schema(name)
|
||||
|
||||
def get_emitter(name: str, id: str) -> dict[str, Any]:
|
||||
return api.get_emitter(name, id)
|
||||
def get_emitter(name: str, junction: str) -> dict[str, Any]:
|
||||
return api.get_emitter(name, junction)
|
||||
|
||||
def set_emitter(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return api.set_emitter(name, cs)
|
||||
|
||||
|
||||
############################################################
|
||||
# time 21.[EMITTERS]
|
||||
############################################################
|
||||
|
||||
def get_time_schema(name: str) -> dict[str, dict[str, Any]]:
|
||||
return api.get_time_schema(name)
|
||||
|
||||
def get_time(name: str) -> dict[str, Any]:
|
||||
return api.get_time(name)
|
||||
|
||||
def set_time(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return api.set_time(name, cs)
|
||||
|
||||
|
||||
############################################################
|
||||
# coord 24.[COORDINATES]
|
||||
############################################################
|
||||
|
||||
Reference in New Issue
Block a user