Add energy api and test
This commit is contained in:
@@ -54,6 +54,9 @@ from .s13_controls import get_control_schema, get_control, set_control
|
|||||||
|
|
||||||
from .s14_rules import get_rule_schema, get_rule, set_rule
|
from .s14_rules import get_rule_schema, get_rule, set_rule
|
||||||
|
|
||||||
|
from .s15_energy import get_global_energy_schema, get_global_energy, set_global_energy
|
||||||
|
from .s15_energy import get_pump_energy_schema, get_pump_energy, set_pump_energy
|
||||||
|
|
||||||
from .s16_emitters import get_emitter_schema, get_emitter, set_emitter
|
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 TIME_STATISTIC_NONE, TIME_STATISTIC_AVERAGED, TIME_STATISTIC_MINIMUM, TIME_STATISTIC_MAXIMUM, TIME_STATISTIC_RANGE
|
||||||
|
|||||||
134
api/s15_energy.py
Normal file
134
api/s15_energy.py
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
from .operation import *
|
||||||
|
|
||||||
|
|
||||||
|
def get_global_energy_schema(name: str) -> dict[str, dict[str, Any]]:
|
||||||
|
return { 'price' : {'type': 'float' , 'optional': True , 'readonly': False},
|
||||||
|
'pattern' : {'type': 'str' , 'optional': True , 'readonly': False},
|
||||||
|
'effic' : {'type': 'float' , 'optional': True , 'readonly': False},
|
||||||
|
'demand_charge' : {'type': 'float' , 'optional': True , 'readonly': False} }
|
||||||
|
|
||||||
|
|
||||||
|
def get_global_energy(name: str) -> dict[str, Any]:
|
||||||
|
ge = read(name, f"select * from energy_global")
|
||||||
|
d = {}
|
||||||
|
d['price'] = float(ge['price'])
|
||||||
|
d['pattern'] = str(ge['pattern']) if ge['pattern'] != None else None
|
||||||
|
d['effic'] = float(ge['effic'])
|
||||||
|
d['demand_charge'] = float(ge['demand_charge'])
|
||||||
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
class GlobalEnergy(object):
|
||||||
|
def __init__(self, input: dict[str, Any]) -> None:
|
||||||
|
self.type = 'global_energy'
|
||||||
|
self.price = float(input['price']) if 'price' in input and input['price'] != None else 0.0
|
||||||
|
self.pattern = str(input['pattern']) if 'pattern' in input and input['pattern'] != None else None
|
||||||
|
self.effic = float(input['effic']) if 'effic' in input and input['effic'] != None else 75
|
||||||
|
self.demand_charge = float(input['demand_charge']) if 'demand_charge' in input and input['demand_charge'] != None else 0.0
|
||||||
|
|
||||||
|
self.f_type = f"'{self.type}'"
|
||||||
|
self.f_price = self.price
|
||||||
|
self.f_pattern = f"'{self.pattern}'" if self.pattern != None else 'null'
|
||||||
|
self.f_effic = self.effic
|
||||||
|
self.f_demand_charge = self.demand_charge
|
||||||
|
|
||||||
|
def as_dict(self) -> dict[str, Any]:
|
||||||
|
return { 'type': self.type, 'price': self.price, 'pattern': self.pattern, 'effic': self.effic, 'demand_charge': self.demand_charge }
|
||||||
|
|
||||||
|
|
||||||
|
def set_global_energy_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
|
||||||
|
old = GlobalEnergy(get_global_energy(name))
|
||||||
|
raw_new = get_global_energy(name)
|
||||||
|
|
||||||
|
new_dict = cs.operations[0]
|
||||||
|
schema = get_global_energy_schema(name)
|
||||||
|
for key, value in schema.items():
|
||||||
|
if key in new_dict and not value['readonly']:
|
||||||
|
raw_new[key] = new_dict[key]
|
||||||
|
new = GlobalEnergy(raw_new)
|
||||||
|
|
||||||
|
redo_sql = f"update energy_global set price = {new.f_price}, pattern = {new.f_pattern}, effic = {new.f_effic}, demand_charge = {new.f_demand_charge} where _no = 0;"
|
||||||
|
undo_sql = f"update energy_global set price = {old.f_price}, pattern = {old.f_pattern}, effic = {old.f_effic}, demand_charge = {old.f_demand_charge} where _no = 0;"
|
||||||
|
|
||||||
|
redo_cs = g_update_prefix | new.as_dict()
|
||||||
|
undo_cs = g_update_prefix | old.as_dict()
|
||||||
|
|
||||||
|
return SqlChangeSet(redo_sql, undo_sql, redo_cs, undo_cs)
|
||||||
|
|
||||||
|
|
||||||
|
def set_global_energy(name: str, cs: ChangeSet) -> ChangeSet:
|
||||||
|
return execute_command(name, set_global_energy_cache(name, cs))
|
||||||
|
|
||||||
|
|
||||||
|
def get_pump_energy_schema(name: str) -> dict[str, dict[str, Any]]:
|
||||||
|
return { 'id' : {'type': 'str' , 'optional': False , 'readonly': True },
|
||||||
|
'price' : {'type': 'float' , 'optional': True , 'readonly': False},
|
||||||
|
'pattern' : {'type': 'str' , 'optional': True , 'readonly': False},
|
||||||
|
'effic' : {'type': 'str' , 'optional': True , 'readonly': False} }
|
||||||
|
|
||||||
|
|
||||||
|
def get_pump_energy(name: str, id: str) -> dict[str, Any]:
|
||||||
|
d = {}
|
||||||
|
d['id'] = id
|
||||||
|
pe = try_read(name, f"select * from energy_pump_price where id = '{id}'")
|
||||||
|
d['price'] = float(pe['price']) if pe != None else None
|
||||||
|
pe = try_read(name, f"select * from energy_pump_pattern where id = '{id}'")
|
||||||
|
d['pattern'] = str(pe['pattern']) if pe != None else None
|
||||||
|
pe = try_read(name, f"select * from energy_pump_effic where id = '{id}'")
|
||||||
|
d['effic'] = str(pe['effic']) if pe != None else None
|
||||||
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
class PumpEnergy(object):
|
||||||
|
def __init__(self, input: dict[str, Any]) -> None:
|
||||||
|
self.type = 'pump_energy'
|
||||||
|
self.id = str(input['id'])
|
||||||
|
self.price = float(input['price']) if 'price' in input and input['price'] != None else None
|
||||||
|
self.pattern = str(input['pattern']) if 'pattern' in input and input['pattern'] != None else None
|
||||||
|
self.effic = str(input['effic']) if 'effic' in input and input['effic'] != None else None
|
||||||
|
|
||||||
|
self.f_id = f"'{self.id}'"
|
||||||
|
self.f_type = f"'{self.type}'"
|
||||||
|
self.f_price = self.price if self.price != None else 'null'
|
||||||
|
self.f_pattern = f"'{self.pattern}'" if self.pattern != None else 'null'
|
||||||
|
self.f_effic = f"'{self.effic}'" if self.effic != None else 'null'
|
||||||
|
|
||||||
|
def as_dict(self) -> dict[str, Any]:
|
||||||
|
return { 'type': self.type, 'id': self.id, 'price': self.price, 'pattern': self.pattern, 'effic': self.effic }
|
||||||
|
|
||||||
|
|
||||||
|
def set_pump_energy_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
|
||||||
|
old = PumpEnergy(get_pump_energy(name, cs.operations[0]['id']))
|
||||||
|
raw_new = get_pump_energy(name, cs.operations[0]['id'])
|
||||||
|
|
||||||
|
new_dict = cs.operations[0]
|
||||||
|
schema = get_pump_energy_schema(name)
|
||||||
|
for key, value in schema.items():
|
||||||
|
if key in new_dict and not value['readonly']:
|
||||||
|
raw_new[key] = new_dict[key]
|
||||||
|
new = PumpEnergy(raw_new)
|
||||||
|
|
||||||
|
redo_sql = f"delete from energy_pump_price where id = {new.f_id};\ndelete from energy_pump_pattern where id = {new.f_id};\ndelete from energy_pump_effic where id = {new.f_id};"
|
||||||
|
if new.price != None:
|
||||||
|
redo_sql += f"\ninsert into energy_pump_price (id, price) values ({new.f_id}, {new.f_price});"
|
||||||
|
if new.pattern != None:
|
||||||
|
redo_sql += f"\ninsert into energy_pump_pattern (id, pattern) values ({new.f_id}, {new.f_pattern});"
|
||||||
|
if new.effic != None:
|
||||||
|
redo_sql += f"\ninsert into energy_pump_effic (id, effic) values ({new.f_id}, {new.f_effic});"
|
||||||
|
|
||||||
|
undo_sql = f"delete from energy_pump_price where id = {old.f_id};\ndelete from energy_pump_pattern where id = {old.f_id};\ndelete from energy_pump_effic where id = {old.f_id};"
|
||||||
|
if old.price != None:
|
||||||
|
undo_sql += f"\ninsert into energy_pump_price (id, price) values ({old.f_id}, {old.f_price});"
|
||||||
|
if old.pattern != None:
|
||||||
|
undo_sql += f"\ninsert into energy_pump_pattern (id, pattern) values ({old.f_id}, {old.f_pattern});"
|
||||||
|
if old.effic != None:
|
||||||
|
undo_sql += f"\ninsert into energy_pump_effic (id, effic) values ({old.f_id}, {old.f_effic});"
|
||||||
|
|
||||||
|
redo_cs = g_update_prefix | new.as_dict()
|
||||||
|
undo_cs = g_update_prefix | old.as_dict()
|
||||||
|
|
||||||
|
return SqlChangeSet(redo_sql, undo_sql, redo_cs, undo_cs)
|
||||||
|
|
||||||
|
|
||||||
|
def set_pump_energy(name: str, cs: ChangeSet) -> ChangeSet:
|
||||||
|
return execute_command(name, set_pump_energy_cache(name, cs))
|
||||||
@@ -1,33 +1,31 @@
|
|||||||
-- [ENERGY]
|
-- [ENERGY]
|
||||||
|
|
||||||
create type energy_param as enum ('PRICE', 'PATTERN', 'EFFIC');
|
|
||||||
|
|
||||||
-- GLOBAL PRICE / PATTERN / EFFIC value
|
|
||||||
create table energy_global
|
create table energy_global
|
||||||
(
|
(
|
||||||
param energy_param not null
|
_no integer primary key
|
||||||
, value numeric not null
|
, price numeric not null
|
||||||
|
, pattern varchar(32) references _pattern(id)
|
||||||
|
, effic numeric not null
|
||||||
|
, demand_charge numeric not null
|
||||||
);
|
);
|
||||||
|
|
||||||
-- PUMP pumpID PRICE / PATTERN / EFFIC value
|
insert into energy_global (_no, price, pattern, effic, demand_charge)
|
||||||
create table energy_pump
|
values (0, 0.0, null, 75, 0.0);
|
||||||
|
|
||||||
|
create table energy_pump_price
|
||||||
(
|
(
|
||||||
id varchar(32) references pumps(id) not null
|
id varchar(32) primary key references pumps(id) not null
|
||||||
, param energy_param not null
|
, price numeric not null
|
||||||
, value numeric not null
|
|
||||||
);
|
);
|
||||||
|
|
||||||
-- DEMAND CHARGE value
|
create table energy_pump_pattern
|
||||||
create table energy_demand_charge
|
|
||||||
(
|
(
|
||||||
value numeric not null
|
id varchar(32) primary key references pumps(id) not null
|
||||||
|
, pattern varchar(32) references _pattern(id) not null
|
||||||
);
|
);
|
||||||
|
|
||||||
insert into energy_global (param, value) values
|
create table energy_pump_effic
|
||||||
('PRICE', 0.0)
|
(
|
||||||
, ('EFFIC', 75)
|
id varchar(32) primary key references pumps(id) not null
|
||||||
;
|
, effic varchar(32) references _curve(id) not null
|
||||||
|
);
|
||||||
insert into energy_demand_charge values
|
|
||||||
(0.0)
|
|
||||||
;
|
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
-- [ENERGY]
|
-- [ENERGY]
|
||||||
|
|
||||||
drop table if exists energy_demand_charge;
|
drop table if exists energy_pump_effic;
|
||||||
|
drop table if exists energy_pump_pattern;
|
||||||
drop table if exists energy_pump;
|
drop table if exists energy_pump_price;
|
||||||
|
|
||||||
drop table if exists energy_global;
|
drop table if exists energy_global;
|
||||||
|
|
||||||
drop type if exists energy_param;
|
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ class TestApi:
|
|||||||
delete_project(p)
|
delete_project(p)
|
||||||
|
|
||||||
|
|
||||||
|
# project
|
||||||
|
|
||||||
|
|
||||||
def test_project(self):
|
def test_project(self):
|
||||||
p = 'test_project'
|
p = 'test_project'
|
||||||
|
|
||||||
@@ -62,6 +65,121 @@ class TestApi:
|
|||||||
assert get_project_open_count(p) == 0
|
assert get_project_open_count(p) == 0
|
||||||
|
|
||||||
|
|
||||||
|
# operation
|
||||||
|
|
||||||
|
|
||||||
|
def test_snapshot(self):
|
||||||
|
p = "test_snapshot"
|
||||||
|
self.enter(p)
|
||||||
|
|
||||||
|
add_junction(p, ChangeSet({'id': 'j1', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
|
||||||
|
add_junction(p, ChangeSet({'id': 'j2', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
|
||||||
|
add_junction(p, ChangeSet({'id': 'j3', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
|
||||||
|
add_junction(p, ChangeSet({'id': 'j4', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
|
||||||
|
|
||||||
|
client_op = get_current_operation(p)
|
||||||
|
assert client_op == 4
|
||||||
|
assert take_snapshot(p, 'x') == 4
|
||||||
|
|
||||||
|
execute_undo(p)
|
||||||
|
execute_undo(p)
|
||||||
|
add_junction(p, ChangeSet({'id': 'j5', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
|
||||||
|
add_junction(p, ChangeSet({'id': 'j6', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
|
||||||
|
|
||||||
|
assert take_snapshot(p, 'xx') == 6
|
||||||
|
|
||||||
|
cs = sync_with_server(p, client_op).operations
|
||||||
|
cs[0]['operation'] = API_DELETE
|
||||||
|
cs[0]['id'] = 'j4'
|
||||||
|
cs[1]['operation'] = API_DELETE
|
||||||
|
cs[1]['id'] = 'j3'
|
||||||
|
cs[2]['operation'] = API_ADD
|
||||||
|
cs[2]['id'] = 'j5'
|
||||||
|
cs[3]['operation'] = API_ADD
|
||||||
|
cs[3]['id'] = 'j6'
|
||||||
|
|
||||||
|
cs = pick_snapshot(p, 'x').operations
|
||||||
|
cs[0]['operation'] = 'delete'
|
||||||
|
cs[0]['id'] = 'j6'
|
||||||
|
cs[1]['operation'] = 'delete'
|
||||||
|
cs[1]['id'] = 'j5'
|
||||||
|
cs[2]['operation'] = 'add'
|
||||||
|
cs[2]['id'] = 'j3'
|
||||||
|
cs[3]['operation'] = 'add'
|
||||||
|
cs[3]['id'] = 'j4'
|
||||||
|
|
||||||
|
assert get_nodes(p) == ['j1', 'j2', 'j3', 'j4']
|
||||||
|
|
||||||
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
|
def test_batch_commands(self):
|
||||||
|
p = 'test_batch_commands'
|
||||||
|
self.enter(p)
|
||||||
|
|
||||||
|
cs = ChangeSet()
|
||||||
|
cs.add({'type': JUNCTION, 'id': 'j1', 'x': 0.0, 'y': 10.0, 'elevation': 20.0})
|
||||||
|
cs.add({'type': JUNCTION, 'id': 'j2', 'x': 0.0, 'y': 10.0, 'elevation': 20.0})
|
||||||
|
cs.add({'type': JUNCTION, 'id': 'j2', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}) # fail
|
||||||
|
|
||||||
|
cs = execute_batch_commands(p, cs)
|
||||||
|
assert len(cs.operations) == 2
|
||||||
|
|
||||||
|
cs = ChangeSet()
|
||||||
|
cs.delete({'type': JUNCTION, 'id': 'j1'})
|
||||||
|
cs.delete({'type': JUNCTION, 'id': 'j2'})
|
||||||
|
|
||||||
|
cs = execute_batch_commands(p, cs)
|
||||||
|
assert len(cs.operations) == 2
|
||||||
|
|
||||||
|
cs = execute_undo(p)
|
||||||
|
assert len(cs.operations) == 1
|
||||||
|
|
||||||
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
|
def test_batch_command(self):
|
||||||
|
p = 'test_batch_command'
|
||||||
|
self.enter(p)
|
||||||
|
|
||||||
|
cs = ChangeSet()
|
||||||
|
cs.add({'type': JUNCTION, 'id': 'j1', 'x': 0.0, 'y': 10.0, 'elevation': 20.0})
|
||||||
|
cs.add({'type': JUNCTION, 'id': 'j2', 'x': 0.0, 'y': 10.0, 'elevation': 20.0})
|
||||||
|
cs.add({'type': JUNCTION, 'id': 'j2', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}) # fail
|
||||||
|
|
||||||
|
cs = execute_batch_command(p, cs)
|
||||||
|
assert len(cs.operations) == 0
|
||||||
|
|
||||||
|
assert get_current_operation(p) == 0
|
||||||
|
|
||||||
|
cs = ChangeSet()
|
||||||
|
cs.add({'type': JUNCTION, 'id': 'j1', 'x': 0.0, 'y': 10.0, 'elevation': 20.0})
|
||||||
|
cs.add({'type': JUNCTION, 'id': 'j2', 'x': 0.0, 'y': 10.0, 'elevation': 20.0})
|
||||||
|
|
||||||
|
cs = execute_batch_command(p, cs)
|
||||||
|
|
||||||
|
assert get_current_operation(p) == 1
|
||||||
|
|
||||||
|
cs = ChangeSet()
|
||||||
|
cs.delete({'type': JUNCTION, 'id': 'j1'})
|
||||||
|
cs.delete({'type': JUNCTION, 'id': 'j2'})
|
||||||
|
|
||||||
|
cs = execute_batch_command(p, cs)
|
||||||
|
|
||||||
|
assert get_current_operation(p) == 2
|
||||||
|
|
||||||
|
cs = execute_undo(p)
|
||||||
|
assert get_current_operation(p) == 1
|
||||||
|
|
||||||
|
cs = execute_undo(p)
|
||||||
|
assert get_current_operation(p) == 0
|
||||||
|
|
||||||
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
|
# 1 title
|
||||||
|
|
||||||
|
|
||||||
def test_title(self):
|
def test_title(self):
|
||||||
p = 'test_title'
|
p = 'test_title'
|
||||||
self.enter(p)
|
self.enter(p)
|
||||||
@@ -116,6 +234,9 @@ class TestApi:
|
|||||||
self.leave(p)
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
|
# 2 junction
|
||||||
|
|
||||||
|
|
||||||
def test_junction(self):
|
def test_junction(self):
|
||||||
p = 'test_junction'
|
p = 'test_junction'
|
||||||
self.enter(p)
|
self.enter(p)
|
||||||
@@ -278,6 +399,9 @@ class TestApi:
|
|||||||
self.leave(p)
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
|
# 3 reservoir
|
||||||
|
|
||||||
|
|
||||||
def test_reservoir(self):
|
def test_reservoir(self):
|
||||||
p = 'test_reservoir'
|
p = 'test_reservoir'
|
||||||
self.enter(p)
|
self.enter(p)
|
||||||
@@ -429,6 +553,9 @@ class TestApi:
|
|||||||
self.leave(p)
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
|
# 4 tank
|
||||||
|
|
||||||
|
|
||||||
def test_tank(self):
|
def test_tank(self):
|
||||||
p = 'test_tank'
|
p = 'test_tank'
|
||||||
self.enter(p)
|
self.enter(p)
|
||||||
@@ -640,6 +767,9 @@ class TestApi:
|
|||||||
self.leave(p)
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
|
# 5 pipe
|
||||||
|
|
||||||
|
|
||||||
def test_pipe(self):
|
def test_pipe(self):
|
||||||
p = 'test_pipe'
|
p = 'test_pipe'
|
||||||
self.enter(p)
|
self.enter(p)
|
||||||
@@ -833,6 +963,9 @@ class TestApi:
|
|||||||
self.leave(p)
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
|
# 6 pump
|
||||||
|
|
||||||
|
|
||||||
def test_pump(self):
|
def test_pump(self):
|
||||||
p = 'test_pump'
|
p = 'test_pump'
|
||||||
self.enter(p)
|
self.enter(p)
|
||||||
@@ -992,6 +1125,9 @@ class TestApi:
|
|||||||
self.leave(p)
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
|
# 7 valve
|
||||||
|
|
||||||
|
|
||||||
def test_valve(self):
|
def test_valve(self):
|
||||||
p = 'test_valve'
|
p = 'test_valve'
|
||||||
self.enter(p)
|
self.enter(p)
|
||||||
@@ -1174,6 +1310,9 @@ class TestApi:
|
|||||||
self.leave(p)
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
|
# 8 tag
|
||||||
|
|
||||||
|
|
||||||
def test_tag(self):
|
def test_tag(self):
|
||||||
p = 'test_tag'
|
p = 'test_tag'
|
||||||
self.enter(p)
|
self.enter(p)
|
||||||
@@ -1264,38 +1403,7 @@ class TestApi:
|
|||||||
self.leave(p)
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
def test_rule(self):
|
# 9 demand
|
||||||
p = 'test_rule'
|
|
||||||
self.enter(p)
|
|
||||||
|
|
||||||
assert get_rule(p)['rule'] == ''
|
|
||||||
|
|
||||||
set_rule(p, ChangeSet({'rule': 'x'}))
|
|
||||||
assert get_rule(p)['rule'] == 'x'
|
|
||||||
|
|
||||||
self.leave(p)
|
|
||||||
|
|
||||||
|
|
||||||
def test_rule_op(self):
|
|
||||||
p = 'test_rule_op'
|
|
||||||
self.enter(p)
|
|
||||||
|
|
||||||
cs = set_rule(p, ChangeSet({'rule': 'x'})).operations[0]
|
|
||||||
assert cs['operation'] == API_UPDATE
|
|
||||||
assert cs['type'] == 'rule'
|
|
||||||
assert cs['rule'] == 'x'
|
|
||||||
|
|
||||||
cs = execute_undo(p).operations[0]
|
|
||||||
assert cs['operation'] == API_UPDATE
|
|
||||||
assert cs['type'] == 'rule'
|
|
||||||
assert cs['rule'] == ''
|
|
||||||
|
|
||||||
cs = execute_redo(p).operations[0]
|
|
||||||
assert cs['operation'] == API_UPDATE
|
|
||||||
assert cs['type'] == 'rule'
|
|
||||||
assert cs['rule'] == 'x'
|
|
||||||
|
|
||||||
self.leave(p)
|
|
||||||
|
|
||||||
|
|
||||||
def test_demand(self):
|
def test_demand(self):
|
||||||
@@ -1397,6 +1505,9 @@ class TestApi:
|
|||||||
self.leave(p)
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
|
# 10 status
|
||||||
|
|
||||||
|
|
||||||
def test_status(self):
|
def test_status(self):
|
||||||
p = 'test_status'
|
p = 'test_status'
|
||||||
self.enter(p)
|
self.enter(p)
|
||||||
@@ -1475,6 +1586,9 @@ class TestApi:
|
|||||||
self.leave(p)
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
|
# 11 pattern
|
||||||
|
|
||||||
|
|
||||||
def test_pattern(self):
|
def test_pattern(self):
|
||||||
p = 'test_pattern'
|
p = 'test_pattern'
|
||||||
self.enter(p)
|
self.enter(p)
|
||||||
@@ -1526,6 +1640,9 @@ class TestApi:
|
|||||||
self.leave(p)
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
|
# 12 curve
|
||||||
|
|
||||||
|
|
||||||
def test_curve(self):
|
def test_curve(self):
|
||||||
p = 'test_curve'
|
p = 'test_curve'
|
||||||
self.enter(p)
|
self.enter(p)
|
||||||
@@ -1592,6 +1709,461 @@ class TestApi:
|
|||||||
self.leave(p)
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
|
# 13 control
|
||||||
|
|
||||||
|
|
||||||
|
def test_control(self):
|
||||||
|
p = 'test_control'
|
||||||
|
self.enter(p)
|
||||||
|
|
||||||
|
assert get_control(p)['control'] == ''
|
||||||
|
|
||||||
|
set_control(p, ChangeSet({'control': 'x'}))
|
||||||
|
assert get_control(p)['control'] == 'x'
|
||||||
|
|
||||||
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
|
def test_control_op(self):
|
||||||
|
p = 'test_control_op'
|
||||||
|
self.enter(p)
|
||||||
|
|
||||||
|
cs = set_control(p, ChangeSet({'control': 'x'})).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'control'
|
||||||
|
assert cs['control'] == 'x'
|
||||||
|
|
||||||
|
cs = execute_undo(p).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'control'
|
||||||
|
assert cs['control'] == ''
|
||||||
|
|
||||||
|
cs = execute_redo(p).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'control'
|
||||||
|
assert cs['control'] == 'x'
|
||||||
|
|
||||||
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
|
# 14 rule
|
||||||
|
|
||||||
|
|
||||||
|
def test_rule(self):
|
||||||
|
p = 'test_rule'
|
||||||
|
self.enter(p)
|
||||||
|
|
||||||
|
assert get_rule(p)['rule'] == ''
|
||||||
|
|
||||||
|
set_rule(p, ChangeSet({'rule': 'x'}))
|
||||||
|
assert get_rule(p)['rule'] == 'x'
|
||||||
|
|
||||||
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
|
def test_rule_op(self):
|
||||||
|
p = 'test_rule_op'
|
||||||
|
self.enter(p)
|
||||||
|
|
||||||
|
cs = set_rule(p, ChangeSet({'rule': 'x'})).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'rule'
|
||||||
|
assert cs['rule'] == 'x'
|
||||||
|
|
||||||
|
cs = execute_undo(p).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'rule'
|
||||||
|
assert cs['rule'] == ''
|
||||||
|
|
||||||
|
cs = execute_redo(p).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'rule'
|
||||||
|
assert cs['rule'] == 'x'
|
||||||
|
|
||||||
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
|
# 15 energy
|
||||||
|
|
||||||
|
|
||||||
|
def test_global_energy(self):
|
||||||
|
p = 'test_global_energy'
|
||||||
|
self.enter(p)
|
||||||
|
|
||||||
|
ge = get_global_energy(p)
|
||||||
|
assert ge['price'] == 0.0
|
||||||
|
assert ge['pattern'] == None
|
||||||
|
assert ge['effic'] == float(75)
|
||||||
|
assert ge['demand_charge'] == 0.0
|
||||||
|
|
||||||
|
set_global_energy(p, ChangeSet({ 'price' : 10.0 }))
|
||||||
|
ge = get_global_energy(p)
|
||||||
|
assert ge['price'] == 10.0
|
||||||
|
assert ge['pattern'] == None
|
||||||
|
assert ge['effic'] == float(75)
|
||||||
|
assert ge['demand_charge'] == 0.0
|
||||||
|
|
||||||
|
add_pattern(p, ChangeSet({'id' : 'p0', 'factors': [1.0, 2.0, 3.0]}))
|
||||||
|
set_global_energy(p, ChangeSet({ 'pattern' : 'p0' }))
|
||||||
|
ge = get_global_energy(p)
|
||||||
|
assert ge['price'] == 10.0
|
||||||
|
assert ge['pattern'] == 'p0'
|
||||||
|
assert ge['effic'] == float(75)
|
||||||
|
assert ge['demand_charge'] == 0.0
|
||||||
|
|
||||||
|
set_global_energy(p, ChangeSet({ 'effic' : 0.0 }))
|
||||||
|
ge = get_global_energy(p)
|
||||||
|
assert ge['price'] == 10.0
|
||||||
|
assert ge['pattern'] == 'p0'
|
||||||
|
assert ge['effic'] == 0.0
|
||||||
|
assert ge['demand_charge'] == 0.0
|
||||||
|
|
||||||
|
set_global_energy(p, ChangeSet({ 'demand_charge' : 10.0 }))
|
||||||
|
ge = get_global_energy(p)
|
||||||
|
assert ge['price'] == 10.0
|
||||||
|
assert ge['pattern'] == 'p0'
|
||||||
|
assert ge['effic'] == 0.0
|
||||||
|
assert ge['demand_charge'] == 10.0
|
||||||
|
|
||||||
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
|
def test_global_energy_op(self):
|
||||||
|
p = 'test_global_energy_op'
|
||||||
|
self.enter(p)
|
||||||
|
|
||||||
|
add_pattern(p, ChangeSet({'id' : 'p0', 'factors': [1.0, 2.0, 3.0]}))
|
||||||
|
|
||||||
|
cs = set_global_energy(p, ChangeSet({ 'price' : 10.0 })).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'global_energy'
|
||||||
|
assert cs['price'] == 10.0
|
||||||
|
assert cs['pattern'] == None
|
||||||
|
assert cs['effic'] == float(75)
|
||||||
|
assert cs['demand_charge'] == 0.0
|
||||||
|
|
||||||
|
cs = execute_undo(p).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'global_energy'
|
||||||
|
assert cs['price'] == 0.0
|
||||||
|
assert cs['pattern'] == None
|
||||||
|
assert cs['effic'] == float(75)
|
||||||
|
assert cs['demand_charge'] == 0.0
|
||||||
|
|
||||||
|
cs = execute_redo(p).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'global_energy'
|
||||||
|
assert cs['price'] == 10.0
|
||||||
|
assert cs['pattern'] == None
|
||||||
|
assert cs['effic'] == float(75)
|
||||||
|
assert cs['demand_charge'] == 0.0
|
||||||
|
|
||||||
|
cs = set_global_energy(p, ChangeSet({ 'pattern' : 'p0' })).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'global_energy'
|
||||||
|
assert cs['price'] == 10.0
|
||||||
|
assert cs['pattern'] == 'p0'
|
||||||
|
assert cs['effic'] == float(75)
|
||||||
|
assert cs['demand_charge'] == 0.0
|
||||||
|
|
||||||
|
cs = execute_undo(p).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'global_energy'
|
||||||
|
assert cs['price'] == 10.0
|
||||||
|
assert cs['pattern'] == None
|
||||||
|
assert cs['effic'] == float(75)
|
||||||
|
assert cs['demand_charge'] == 0.0
|
||||||
|
|
||||||
|
cs = execute_redo(p).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'global_energy'
|
||||||
|
assert cs['price'] == 10.0
|
||||||
|
assert cs['pattern'] == 'p0'
|
||||||
|
assert cs['effic'] == float(75)
|
||||||
|
assert cs['demand_charge'] == 0.0
|
||||||
|
|
||||||
|
cs = set_global_energy(p, ChangeSet({ 'effic' : 0.0 })).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'global_energy'
|
||||||
|
assert cs['price'] == 10.0
|
||||||
|
assert cs['pattern'] == 'p0'
|
||||||
|
assert cs['effic'] == 0.0
|
||||||
|
assert cs['demand_charge'] == 0.0
|
||||||
|
|
||||||
|
cs = execute_undo(p).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'global_energy'
|
||||||
|
assert cs['price'] == 10.0
|
||||||
|
assert cs['pattern'] == 'p0'
|
||||||
|
assert cs['effic'] == float(75)
|
||||||
|
assert cs['demand_charge'] == 0.0
|
||||||
|
|
||||||
|
cs = execute_redo(p).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'global_energy'
|
||||||
|
assert cs['price'] == 10.0
|
||||||
|
assert cs['pattern'] == 'p0'
|
||||||
|
assert cs['effic'] == 0.0
|
||||||
|
assert cs['demand_charge'] == 0.0
|
||||||
|
|
||||||
|
cs = set_global_energy(p, ChangeSet({ 'demand_charge' : 10.0 })).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'global_energy'
|
||||||
|
assert cs['price'] == 10.0
|
||||||
|
assert cs['pattern'] == 'p0'
|
||||||
|
assert cs['effic'] == 0.0
|
||||||
|
assert cs['demand_charge'] == 10.0
|
||||||
|
|
||||||
|
cs = execute_undo(p).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'global_energy'
|
||||||
|
assert cs['price'] == 10.0
|
||||||
|
assert cs['pattern'] == 'p0'
|
||||||
|
assert cs['effic'] == 0.0
|
||||||
|
assert cs['demand_charge'] == 0.0
|
||||||
|
|
||||||
|
cs = execute_redo(p).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'global_energy'
|
||||||
|
assert cs['price'] == 10.0
|
||||||
|
assert cs['pattern'] == 'p0'
|
||||||
|
assert cs['effic'] == 0.0
|
||||||
|
assert cs['demand_charge'] == 10.0
|
||||||
|
|
||||||
|
cs = set_global_energy(p, ChangeSet({ 'price' : 0.0, 'pattern' : None, 'effic' : float(75), 'demand_charge' : 0.0 })).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'global_energy'
|
||||||
|
assert cs['price'] == 0.0
|
||||||
|
assert cs['pattern'] == None
|
||||||
|
assert cs['effic'] == float(75)
|
||||||
|
assert cs['demand_charge'] == 0.0
|
||||||
|
|
||||||
|
cs = execute_undo(p).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'global_energy'
|
||||||
|
assert cs['price'] == 10.0
|
||||||
|
assert cs['pattern'] == 'p0'
|
||||||
|
assert cs['effic'] == 0.0
|
||||||
|
assert cs['demand_charge'] == 10.0
|
||||||
|
|
||||||
|
cs = execute_redo(p).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'global_energy'
|
||||||
|
assert cs['price'] == 0.0
|
||||||
|
assert cs['pattern'] == None
|
||||||
|
assert cs['effic'] == float(75)
|
||||||
|
assert cs['demand_charge'] == 0.0
|
||||||
|
|
||||||
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
|
def test_pump_energy(self):
|
||||||
|
p = 'test_pump_energy'
|
||||||
|
self.enter(p)
|
||||||
|
|
||||||
|
ge = get_pump_energy(p, 'p0')
|
||||||
|
assert ge['id'] == 'p0'
|
||||||
|
assert ge['price'] == None
|
||||||
|
assert ge['pattern'] == None
|
||||||
|
assert ge['effic'] == None
|
||||||
|
|
||||||
|
add_junction(p, ChangeSet({'id': 'j1', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
|
||||||
|
add_junction(p, ChangeSet({'id': 'j2', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
|
||||||
|
add_pump(p, ChangeSet({'id': 'p0', 'node1': 'j1', 'node2': 'j2', 'power': 0.0}))
|
||||||
|
|
||||||
|
set_pump_energy(p, ChangeSet({'id' : 'p0'}))
|
||||||
|
ge = get_pump_energy(p, 'p0')
|
||||||
|
assert ge['id'] == 'p0'
|
||||||
|
assert ge['price'] == None
|
||||||
|
assert ge['pattern'] == None
|
||||||
|
assert ge['effic'] == None
|
||||||
|
|
||||||
|
set_pump_energy(p, ChangeSet({'id' : 'p0', 'price': 0.0}))
|
||||||
|
ge = get_pump_energy(p, 'p0')
|
||||||
|
assert ge['id'] == 'p0'
|
||||||
|
assert ge['price'] == 0.0
|
||||||
|
assert ge['pattern'] == None
|
||||||
|
assert ge['effic'] == None
|
||||||
|
|
||||||
|
add_pattern(p, ChangeSet({'id' : 'pa0', 'factors': [1.0, 2.0, 3.0]}))
|
||||||
|
set_pump_energy(p, ChangeSet({'id' : 'p0', 'pattern': 'pa0'}))
|
||||||
|
ge = get_pump_energy(p, 'p0')
|
||||||
|
assert ge['id'] == 'p0'
|
||||||
|
assert ge['price'] == 0.0
|
||||||
|
assert ge['pattern'] == 'pa0'
|
||||||
|
assert ge['effic'] == None
|
||||||
|
|
||||||
|
set_curve(p, ChangeSet({'id' : 'c0', 'coords': [{'x': 1.0, 'y': 2.0}, {'x': 2.0, 'y': 1.0}]}))
|
||||||
|
set_pump_energy(p, ChangeSet({'id' : 'p0', 'effic': 'c0'}))
|
||||||
|
ge = get_pump_energy(p, 'p0')
|
||||||
|
assert ge['id'] == 'p0'
|
||||||
|
assert ge['price'] == 0.0
|
||||||
|
assert ge['pattern'] == 'pa0'
|
||||||
|
assert ge['effic'] == 'c0'
|
||||||
|
|
||||||
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
|
def test_pump_energy_op(self):
|
||||||
|
p = 'test_pump_energy_op'
|
||||||
|
self.enter(p)
|
||||||
|
|
||||||
|
add_junction(p, ChangeSet({'id': 'j1', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
|
||||||
|
add_junction(p, ChangeSet({'id': 'j2', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
|
||||||
|
add_pump(p, ChangeSet({'id': 'p0', 'node1': 'j1', 'node2': 'j2', 'power': 0.0}))
|
||||||
|
add_pattern(p, ChangeSet({'id' : 'pa0', 'factors': [1.0, 2.0, 3.0]}))
|
||||||
|
set_curve(p, ChangeSet({'id' : 'c0', 'coords': [{'x': 1.0, 'y': 2.0}, {'x': 2.0, 'y': 1.0}]}))
|
||||||
|
|
||||||
|
cs = set_pump_energy(p, ChangeSet({'id' : 'p0'})).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'pump_energy'
|
||||||
|
assert cs['id'] == 'p0'
|
||||||
|
assert cs['price'] == None
|
||||||
|
assert cs['pattern'] == None
|
||||||
|
assert cs['effic'] == None
|
||||||
|
|
||||||
|
cs = execute_undo(p).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'pump_energy'
|
||||||
|
assert cs['id'] == 'p0'
|
||||||
|
assert cs['price'] == None
|
||||||
|
assert cs['pattern'] == None
|
||||||
|
assert cs['effic'] == None
|
||||||
|
|
||||||
|
cs = execute_redo(p).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'pump_energy'
|
||||||
|
assert cs['id'] == 'p0'
|
||||||
|
assert cs['price'] == None
|
||||||
|
assert cs['pattern'] == None
|
||||||
|
assert cs['effic'] == None
|
||||||
|
|
||||||
|
cs = set_pump_energy(p, ChangeSet({'id' : 'p0', 'price': 0.0})).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'pump_energy'
|
||||||
|
assert cs['id'] == 'p0'
|
||||||
|
assert cs['price'] == 0.0
|
||||||
|
assert cs['pattern'] == None
|
||||||
|
assert cs['effic'] == None
|
||||||
|
|
||||||
|
cs = execute_undo(p).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'pump_energy'
|
||||||
|
assert cs['id'] == 'p0'
|
||||||
|
assert cs['price'] == None
|
||||||
|
assert cs['pattern'] == None
|
||||||
|
assert cs['effic'] == None
|
||||||
|
|
||||||
|
cs = execute_redo(p).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'pump_energy'
|
||||||
|
assert cs['id'] == 'p0'
|
||||||
|
assert cs['price'] == 0.0
|
||||||
|
assert cs['pattern'] == None
|
||||||
|
assert cs['effic'] == None
|
||||||
|
|
||||||
|
cs = set_pump_energy(p, ChangeSet({'id' : 'p0', 'pattern': 'pa0'})).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'pump_energy'
|
||||||
|
assert cs['id'] == 'p0'
|
||||||
|
assert cs['price'] == 0.0
|
||||||
|
assert cs['pattern'] == 'pa0'
|
||||||
|
assert cs['effic'] == None
|
||||||
|
|
||||||
|
cs = execute_undo(p).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'pump_energy'
|
||||||
|
assert cs['id'] == 'p0'
|
||||||
|
assert cs['price'] == 0.0
|
||||||
|
assert cs['pattern'] == None
|
||||||
|
assert cs['effic'] == None
|
||||||
|
|
||||||
|
cs = execute_redo(p).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'pump_energy'
|
||||||
|
assert cs['id'] == 'p0'
|
||||||
|
assert cs['price'] == 0.0
|
||||||
|
assert cs['pattern'] == 'pa0'
|
||||||
|
assert cs['effic'] == None
|
||||||
|
|
||||||
|
cs = set_pump_energy(p, ChangeSet({'id' : 'p0', 'effic': 'c0'})).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'pump_energy'
|
||||||
|
assert cs['id'] == 'p0'
|
||||||
|
assert cs['price'] == 0.0
|
||||||
|
assert cs['pattern'] == 'pa0'
|
||||||
|
assert cs['effic'] == 'c0'
|
||||||
|
|
||||||
|
cs = execute_undo(p).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'pump_energy'
|
||||||
|
assert cs['id'] == 'p0'
|
||||||
|
assert cs['price'] == 0.0
|
||||||
|
assert cs['pattern'] == 'pa0'
|
||||||
|
assert cs['effic'] == None
|
||||||
|
|
||||||
|
cs = execute_redo(p).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'pump_energy'
|
||||||
|
assert cs['id'] == 'p0'
|
||||||
|
assert cs['price'] == 0.0
|
||||||
|
assert cs['pattern'] == 'pa0'
|
||||||
|
assert cs['effic'] == 'c0'
|
||||||
|
|
||||||
|
cs = set_pump_energy(p, ChangeSet({'id' : 'p0', 'price': None, 'pattern': None, 'effic': None})).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'pump_energy'
|
||||||
|
assert cs['id'] == 'p0'
|
||||||
|
assert cs['price'] == None
|
||||||
|
assert cs['pattern'] == None
|
||||||
|
assert cs['effic'] == None
|
||||||
|
|
||||||
|
cs = execute_undo(p).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'pump_energy'
|
||||||
|
assert cs['id'] == 'p0'
|
||||||
|
assert cs['price'] == 0.0
|
||||||
|
assert cs['pattern'] == 'pa0'
|
||||||
|
assert cs['effic'] == 'c0'
|
||||||
|
|
||||||
|
cs = execute_redo(p).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'pump_energy'
|
||||||
|
assert cs['id'] == 'p0'
|
||||||
|
assert cs['price'] == None
|
||||||
|
assert cs['pattern'] == None
|
||||||
|
assert cs['effic'] == None
|
||||||
|
|
||||||
|
cs = set_pump_energy(p, ChangeSet({'id' : 'p0', 'price': 0.0, 'pattern': 'pa0', 'effic': 'c0'})).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'pump_energy'
|
||||||
|
assert cs['id'] == 'p0'
|
||||||
|
assert cs['price'] == 0.0
|
||||||
|
assert cs['pattern'] == 'pa0'
|
||||||
|
assert cs['effic'] == 'c0'
|
||||||
|
|
||||||
|
cs = execute_undo(p).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'pump_energy'
|
||||||
|
assert cs['id'] == 'p0'
|
||||||
|
assert cs['price'] == None
|
||||||
|
assert cs['pattern'] == None
|
||||||
|
assert cs['effic'] == None
|
||||||
|
|
||||||
|
cs = execute_redo(p).operations[0]
|
||||||
|
assert cs['operation'] == API_UPDATE
|
||||||
|
assert cs['type'] == 'pump_energy'
|
||||||
|
assert cs['id'] == 'p0'
|
||||||
|
assert cs['price'] == 0.0
|
||||||
|
assert cs['pattern'] == 'pa0'
|
||||||
|
assert cs['effic'] == 'c0'
|
||||||
|
|
||||||
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
|
# 16 emitter
|
||||||
|
|
||||||
|
|
||||||
def test_emitter(self):
|
def test_emitter(self):
|
||||||
p = 'test_emitter'
|
p = 'test_emitter'
|
||||||
self.enter(p)
|
self.enter(p)
|
||||||
@@ -1646,6 +2218,9 @@ class TestApi:
|
|||||||
self.leave(p)
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
|
# 21 time
|
||||||
|
|
||||||
|
|
||||||
def test_time(self):
|
def test_time(self):
|
||||||
p = 'test_time'
|
p = 'test_time'
|
||||||
self.enter(p)
|
self.enter(p)
|
||||||
@@ -1742,6 +2317,9 @@ class TestApi:
|
|||||||
self.leave(p)
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
|
# 22 option
|
||||||
|
|
||||||
|
|
||||||
def test_option(self):
|
def test_option(self):
|
||||||
p = 'test_option'
|
p = 'test_option'
|
||||||
self.enter(p)
|
self.enter(p)
|
||||||
@@ -1910,114 +2488,5 @@ class TestApi:
|
|||||||
self.leave(p)
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
def test_snapshot(self):
|
|
||||||
p = "test_snapshot"
|
|
||||||
self.enter(p)
|
|
||||||
|
|
||||||
add_junction(p, ChangeSet({'id': 'j1', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
|
|
||||||
add_junction(p, ChangeSet({'id': 'j2', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
|
|
||||||
add_junction(p, ChangeSet({'id': 'j3', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
|
|
||||||
add_junction(p, ChangeSet({'id': 'j4', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
|
|
||||||
|
|
||||||
client_op = get_current_operation(p)
|
|
||||||
assert client_op == 4
|
|
||||||
assert take_snapshot(p, 'x') == 4
|
|
||||||
|
|
||||||
execute_undo(p)
|
|
||||||
execute_undo(p)
|
|
||||||
add_junction(p, ChangeSet({'id': 'j5', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
|
|
||||||
add_junction(p, ChangeSet({'id': 'j6', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
|
|
||||||
|
|
||||||
assert take_snapshot(p, 'xx') == 6
|
|
||||||
|
|
||||||
cs = sync_with_server(p, client_op).operations
|
|
||||||
cs[0]['operation'] = API_DELETE
|
|
||||||
cs[0]['id'] = 'j4'
|
|
||||||
cs[1]['operation'] = API_DELETE
|
|
||||||
cs[1]['id'] = 'j3'
|
|
||||||
cs[2]['operation'] = API_ADD
|
|
||||||
cs[2]['id'] = 'j5'
|
|
||||||
cs[3]['operation'] = API_ADD
|
|
||||||
cs[3]['id'] = 'j6'
|
|
||||||
|
|
||||||
cs = pick_snapshot(p, 'x').operations
|
|
||||||
cs[0]['operation'] = 'delete'
|
|
||||||
cs[0]['id'] = 'j6'
|
|
||||||
cs[1]['operation'] = 'delete'
|
|
||||||
cs[1]['id'] = 'j5'
|
|
||||||
cs[2]['operation'] = 'add'
|
|
||||||
cs[2]['id'] = 'j3'
|
|
||||||
cs[3]['operation'] = 'add'
|
|
||||||
cs[3]['id'] = 'j4'
|
|
||||||
|
|
||||||
assert get_nodes(p) == ['j1', 'j2', 'j3', 'j4']
|
|
||||||
|
|
||||||
self.leave(p)
|
|
||||||
|
|
||||||
|
|
||||||
def test_batch_commands(self):
|
|
||||||
p = 'test_batch_commands'
|
|
||||||
self.enter(p)
|
|
||||||
|
|
||||||
cs = ChangeSet()
|
|
||||||
cs.add({'type': JUNCTION, 'id': 'j1', 'x': 0.0, 'y': 10.0, 'elevation': 20.0})
|
|
||||||
cs.add({'type': JUNCTION, 'id': 'j2', 'x': 0.0, 'y': 10.0, 'elevation': 20.0})
|
|
||||||
cs.add({'type': JUNCTION, 'id': 'j2', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}) # fail
|
|
||||||
|
|
||||||
cs = execute_batch_commands(p, cs)
|
|
||||||
assert len(cs.operations) == 2
|
|
||||||
|
|
||||||
cs = ChangeSet()
|
|
||||||
cs.delete({'type': JUNCTION, 'id': 'j1'})
|
|
||||||
cs.delete({'type': JUNCTION, 'id': 'j2'})
|
|
||||||
|
|
||||||
cs = execute_batch_commands(p, cs)
|
|
||||||
assert len(cs.operations) == 2
|
|
||||||
|
|
||||||
cs = execute_undo(p)
|
|
||||||
assert len(cs.operations) == 1
|
|
||||||
|
|
||||||
self.leave(p)
|
|
||||||
|
|
||||||
|
|
||||||
def test_batch_command(self):
|
|
||||||
p = 'test_batch_command'
|
|
||||||
self.enter(p)
|
|
||||||
|
|
||||||
cs = ChangeSet()
|
|
||||||
cs.add({'type': JUNCTION, 'id': 'j1', 'x': 0.0, 'y': 10.0, 'elevation': 20.0})
|
|
||||||
cs.add({'type': JUNCTION, 'id': 'j2', 'x': 0.0, 'y': 10.0, 'elevation': 20.0})
|
|
||||||
cs.add({'type': JUNCTION, 'id': 'j2', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}) # fail
|
|
||||||
|
|
||||||
cs = execute_batch_command(p, cs)
|
|
||||||
assert len(cs.operations) == 0
|
|
||||||
|
|
||||||
assert get_current_operation(p) == 0
|
|
||||||
|
|
||||||
cs = ChangeSet()
|
|
||||||
cs.add({'type': JUNCTION, 'id': 'j1', 'x': 0.0, 'y': 10.0, 'elevation': 20.0})
|
|
||||||
cs.add({'type': JUNCTION, 'id': 'j2', 'x': 0.0, 'y': 10.0, 'elevation': 20.0})
|
|
||||||
|
|
||||||
cs = execute_batch_command(p, cs)
|
|
||||||
|
|
||||||
assert get_current_operation(p) == 1
|
|
||||||
|
|
||||||
cs = ChangeSet()
|
|
||||||
cs.delete({'type': JUNCTION, 'id': 'j1'})
|
|
||||||
cs.delete({'type': JUNCTION, 'id': 'j2'})
|
|
||||||
|
|
||||||
cs = execute_batch_command(p, cs)
|
|
||||||
|
|
||||||
assert get_current_operation(p) == 2
|
|
||||||
|
|
||||||
cs = execute_undo(p)
|
|
||||||
assert get_current_operation(p) == 1
|
|
||||||
|
|
||||||
cs = execute_undo(p)
|
|
||||||
assert get_current_operation(p) == 0
|
|
||||||
|
|
||||||
self.leave(p)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
pytest.main()
|
pytest.main()
|
||||||
|
|||||||
22
tjnetwork.py
22
tjnetwork.py
@@ -459,6 +459,28 @@ def set_rule(name: str, cs: ChangeSet) -> ChangeSet:
|
|||||||
return api.set_rule(name, cs)
|
return api.set_rule(name, cs)
|
||||||
|
|
||||||
|
|
||||||
|
############################################################
|
||||||
|
# energy 16.[ENERGY]
|
||||||
|
############################################################
|
||||||
|
|
||||||
|
def get_global_energy_schema(name: str) -> dict[str, dict[str, Any]]:
|
||||||
|
return api.get_global_energy_schema(name)
|
||||||
|
|
||||||
|
def get_global_energy(name: str) -> dict[str, Any]:
|
||||||
|
return api.get_global_energy(name)
|
||||||
|
|
||||||
|
def set_global_energy(name: str, cs: ChangeSet) -> ChangeSet:
|
||||||
|
return api.set_global_energy(name, cs)
|
||||||
|
|
||||||
|
def get_pump_energy_schema(name: str) -> dict[str, dict[str, Any]]:
|
||||||
|
return api.get_pump_energy_schema(name)
|
||||||
|
|
||||||
|
def get_pump_energy(name: str, id: str) -> dict[str, Any]:
|
||||||
|
return api.get_pump_energy(name, id)
|
||||||
|
|
||||||
|
def set_pump_energy(name: str, cs: ChangeSet) -> ChangeSet:
|
||||||
|
return api.set_pump_energy(name, cs)
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
# emitter 16.[EMITTERS]
|
# emitter 16.[EMITTERS]
|
||||||
############################################################
|
############################################################
|
||||||
|
|||||||
Reference in New Issue
Block a user