Add scada model type to scada element
This commit is contained in:
@@ -127,6 +127,7 @@ from .del_cmd import clean_scada_device
|
||||
from .s30_scada_device_data import get_scada_device_data_schema, get_scada_device_data, set_scada_device_data, add_scada_device_data, delete_scada_device_data
|
||||
from .del_cmd import clean_scada_device_data
|
||||
|
||||
from .s31_scada_element import SCADA_MODEL_TYPE_JUNCTION, SCADA_MODEL_TYPE_RESERVOIR, SCADA_MODEL_TYPE_TANK, SCADA_MODEL_TYPE_PIPE, SCADA_MODEL_TYPE_PUMP, SCADA_MODEL_TYPE_VALVE
|
||||
from .s31_scada_element import SCADA_ELEMENT_STATUS_OFFLINE, SCADA_ELEMENT_STATUS_ONLINE
|
||||
from .s31_scada_element import get_scada_element_schema, get_scada_elements, get_scada_element, set_scada_element, add_scada_element, delete_scada_element
|
||||
from .del_cmd import clean_scada_element
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from .database import *
|
||||
from .s0_base import is_node, is_link
|
||||
from .s0_base import *
|
||||
|
||||
|
||||
SCADA_TYPE_PRESSURE = 'PRESSURE'
|
||||
@@ -9,17 +9,49 @@ SCADA_TYPE_LEVEL = 'LEVEL'
|
||||
SCADA_TYPE_FLOW = 'FLOW'
|
||||
|
||||
|
||||
SCADA_MODEL_TYPE_JUNCTION = 'JUNCTION'
|
||||
SCADA_MODEL_TYPE_RESERVOIR = 'RESERVOIR'
|
||||
SCADA_MODEL_TYPE_TANK = 'TANK'
|
||||
SCADA_MODEL_TYPE_PIPE = 'PIPE'
|
||||
SCADA_MODEL_TYPE_PUMP = 'PUMP'
|
||||
SCADA_MODEL_TYPE_VALVE = 'VALVE'
|
||||
|
||||
|
||||
SCADA_ELEMENT_STATUS_OFFLINE = 'OFF'
|
||||
SCADA_ELEMENT_STATUS_ONLINE = 'ON'
|
||||
|
||||
|
||||
def _check_model_id(name: str, cs: ChangeSet) -> bool:
|
||||
if 'model_id' not in cs.operations[0]:
|
||||
_scada_model_types = [SCADA_MODEL_TYPE_JUNCTION, SCADA_MODEL_TYPE_RESERVOIR, SCADA_MODEL_TYPE_TANK, SCADA_MODEL_TYPE_PIPE, SCADA_MODEL_TYPE_PUMP, SCADA_MODEL_TYPE_VALVE]
|
||||
|
||||
|
||||
def _check_model(name: str, cs: ChangeSet) -> bool:
|
||||
has_model_id = 'model_id' in cs.operations[0]
|
||||
has_model_type = 'model_type' in cs.operations[0]
|
||||
|
||||
if has_model_id and has_model_type:
|
||||
pass
|
||||
elif has_model_id and not has_model_type:
|
||||
return False
|
||||
elif not has_model_id and has_model_type:
|
||||
return False
|
||||
elif not has_model_id and not has_model_type:
|
||||
return True
|
||||
if cs.operations[0]['model_id'] == None:
|
||||
return True
|
||||
model_id = cs.operations[0]['model_id']
|
||||
return is_node(name, model_id) or is_link(name, model_id)
|
||||
|
||||
_model_id = cs.operations[0]['model_id']
|
||||
_model_type = cs.operations[0]['model_type']
|
||||
if _model_type == SCADA_MODEL_TYPE_JUNCTION:
|
||||
return is_junction(name, _model_id)
|
||||
elif _model_type == SCADA_MODEL_TYPE_RESERVOIR:
|
||||
return is_reservoir(name, _model_id)
|
||||
elif _model_type == SCADA_MODEL_TYPE_TANK:
|
||||
return is_tank(name, _model_id)
|
||||
elif _model_type == SCADA_MODEL_TYPE_PIPE:
|
||||
return is_pipe(name, _model_id)
|
||||
elif _model_type == SCADA_MODEL_TYPE_PUMP:
|
||||
return is_pump(name, _model_id)
|
||||
elif _model_type == SCADA_MODEL_TYPE_VALVE:
|
||||
return is_valve(name, _model_id)
|
||||
return False
|
||||
|
||||
|
||||
def get_scada_element_schema(name: str) -> dict[str, dict[str, Any]]:
|
||||
@@ -28,6 +60,7 @@ def get_scada_element_schema(name: str) -> dict[str, dict[str, Any]]:
|
||||
'y' : {'type': 'float' , 'optional': False , 'readonly': False},
|
||||
'device_id' : {'type': 'str' , 'optional': True , 'readonly': False},
|
||||
'model_id' : {'type': 'str' , 'optional': True , 'readonly': False},
|
||||
'model_type' : {'type': 'str' , 'optional': True , 'readonly': False},
|
||||
'status' : {'type': 'str' , 'optional': True , 'readonly': False} }
|
||||
|
||||
|
||||
@@ -49,6 +82,7 @@ def get_scada_element(name: str, id: str) -> dict[str, Any]:
|
||||
d['y'] = float(sm['y'])
|
||||
d['device_id'] = str(sm['device_id']) if sm['device_id'] != None else None
|
||||
d['model_id'] = str(sm['model_id']) if sm['model_id'] != None else None
|
||||
d['model_type'] = str(sm['model_type']) if sm['model_type'] != None else None
|
||||
d['status'] = str(sm['status'])
|
||||
return d
|
||||
|
||||
@@ -61,6 +95,7 @@ class ScadaModel(object):
|
||||
self.y = float(input['y'])
|
||||
self.device_id = str(input['device_id']) if 'device_id' in input and input['device_id'] != None else None
|
||||
self.model_id = str(input['model_id']) if 'model_id' in input and input['model_id'] != None else None
|
||||
self.model_type = str(input['model_type']) if 'model_type' in input and input['model_type'] != None else None
|
||||
self.status = str(input['status']) if 'status' in input and input['status'] != None else SCADA_ELEMENT_STATUS_OFFLINE
|
||||
|
||||
self.f_type = f"'{self.type}'"
|
||||
@@ -69,10 +104,11 @@ class ScadaModel(object):
|
||||
self.f_y = self.y
|
||||
self.f_device_id = f"'{self.device_id}'" if self.device_id != None else 'null'
|
||||
self.f_model_id = f"'{self.model_id}'" if self.model_id != None else 'null'
|
||||
self.f_model_type = f"'{self.model_type}'" if self.model_type != None else 'null'
|
||||
self.f_status = f"'{self.status}'"
|
||||
|
||||
def as_dict(self) -> dict[str, Any]:
|
||||
return { 'type': self.type, 'id': self.id, 'x': self.x, 'y': self.y, 'device_id': self.device_id, 'model_id': self.model_id, 'status': self.status }
|
||||
return { 'type': self.type, 'id': self.id, 'x': self.x, 'y': self.y, 'device_id': self.device_id, 'model_id': self.model_id, 'model_type': self.model_type, 'status': self.status }
|
||||
|
||||
def as_id_dict(self) -> dict[str, Any]:
|
||||
return { 'type': self.type, 'id': self.id }
|
||||
@@ -89,8 +125,8 @@ def set_scada_element_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
raw_new[key] = new_dict[key]
|
||||
new = ScadaModel(raw_new)
|
||||
|
||||
redo_sql = f"update scada_element set x = {new.f_x}, y = {new.f_y}, device_id = {new.f_device_id}, model_id = {new.f_model_id}, status = {new.f_status} where id = {new.f_id};"
|
||||
undo_sql = f"update scada_element set x = {old.f_x}, y = {old.f_y}, device_id = {old.f_device_id}, model_id = {old.f_model_id}, status = {old.f_status} where id = {old.f_id};"
|
||||
redo_sql = f"update scada_element set x = {new.f_x}, y = {new.f_y}, device_id = {new.f_device_id}, model_id = {new.f_model_id}, model_type = {new.f_model_type}, status = {new.f_status} where id = {new.f_id};"
|
||||
undo_sql = f"update scada_element set x = {old.f_x}, y = {old.f_y}, device_id = {old.f_device_id}, model_id = {old.f_model_id}, model_type = {old.f_model_type}, status = {old.f_status} where id = {old.f_id};"
|
||||
|
||||
redo_cs = g_update_prefix | new.as_dict()
|
||||
undo_cs = g_update_prefix | old.as_dict()
|
||||
@@ -101,7 +137,7 @@ def set_scada_element_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
def set_scada_element(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
if get_scada_element(name, cs.operations[0]['id']) == {}:
|
||||
return ChangeSet()
|
||||
if _check_model_id(name, cs) == False:
|
||||
if _check_model(name, cs) == False:
|
||||
return ChangeSet()
|
||||
return execute_command(name, set_scada_element_cmd(name, cs))
|
||||
|
||||
@@ -109,7 +145,7 @@ def set_scada_element(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
def add_scada_element_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
new = ScadaModel(cs.operations[0])
|
||||
|
||||
redo_sql = f"insert into scada_element (id, x, y, device_id, model_id, status) values ({new.f_id}, {new.f_x}, {new.f_y}, {new.f_device_id}, {new.f_model_id}, {new.f_status});"
|
||||
redo_sql = f"insert into scada_element (id, x, y, device_id, model_id, model_type, status) values ({new.f_id}, {new.f_x}, {new.f_y}, {new.f_device_id}, {new.f_model_id}, {new.f_model_type}, {new.f_status});"
|
||||
undo_sql = f"delete from scada_element where id = {new.f_id};"
|
||||
|
||||
redo_cs = g_add_prefix | new.as_dict()
|
||||
@@ -121,7 +157,7 @@ def add_scada_element_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
def add_scada_element(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
if get_scada_element(name, cs.operations[0]['id']) != {}:
|
||||
return ChangeSet()
|
||||
if _check_model_id(name, cs) == False:
|
||||
if _check_model(name, cs) == False:
|
||||
return ChangeSet()
|
||||
return execute_command(name, add_scada_element_cmd(name, cs))
|
||||
|
||||
@@ -130,7 +166,7 @@ def delete_scada_element_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
old = ScadaModel(get_scada_element(name, cs.operations[0]['id']))
|
||||
|
||||
redo_sql = f"delete from scada_element where id = {old.f_id};"
|
||||
undo_sql = f"insert into scada_element (id, x, y, device_id, model_id, status) values ({old.f_id}, {old.f_x}, {old.f_y}, {old.f_device_id}, {old.f_model_id}, {old.f_status});"
|
||||
undo_sql = f"insert into scada_element (id, x, y, device_id, model_id, model_type, status) values ({old.f_id}, {old.f_x}, {old.f_y}, {old.f_device_id}, {old.f_model_id}, {old.f_model_type}, {old.f_status});"
|
||||
|
||||
redo_cs = g_delete_prefix | old.as_id_dict()
|
||||
undo_cs = g_add_prefix | old.as_dict()
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
create type scada_model_type as enum ('JUNCTION', 'RESERVOIR', 'TANK', 'PIPE', 'PUMP', 'VALVE');
|
||||
|
||||
create type scada_element_status as enum ('OFF', 'ON');
|
||||
|
||||
create table scada_element
|
||||
@@ -7,5 +9,6 @@ create table scada_element
|
||||
, y numeric not null
|
||||
, device_id text references scada_device(id)
|
||||
, model_id varchar(32) -- add constraint in API
|
||||
, model_type scada_model_type
|
||||
, status scada_element_status not null default 'OFF'
|
||||
);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
drop table if exists scada_element;
|
||||
|
||||
drop type if exists scada_element_status;
|
||||
|
||||
drop type if exists scada_model_type;
|
||||
|
||||
@@ -5174,28 +5174,50 @@ class TestApi:
|
||||
|
||||
assert get_scada_elements(p) == []
|
||||
|
||||
add_scada_element(p, ChangeSet({'id': 'sm0', 'x': 0.0, 'y': 1.0, 'device_id': 'sd0', 'model_id': 'j0', 'model_type': SCADA_MODEL_TYPE_JUNCTION, 'status': SCADA_ELEMENT_STATUS_OFFLINE}))
|
||||
sm = get_scada_element(p, 'sm0')
|
||||
assert sm == {}
|
||||
add_scada_element(p, ChangeSet({'id': 'sm0', 'x': 0.0, 'y': 1.0, 'device_id': 'sd0', 'model_id': 'j0', 'status': SCADA_ELEMENT_STATUS_OFFLINE}))
|
||||
sm = get_scada_element(p, 'sm0')
|
||||
assert sm == {}
|
||||
add_scada_element(p, ChangeSet({'id': 'sm0', 'x': 0.0, 'y': 1.0, 'device_id': 'sd0', 'model_id': 'j1', 'status': SCADA_ELEMENT_STATUS_OFFLINE}))
|
||||
add_scada_element(p, ChangeSet({'id': 'sm0', 'x': 0.0, 'y': 1.0, 'device_id': 'sd0', 'model_type': SCADA_MODEL_TYPE_JUNCTION, 'status': SCADA_ELEMENT_STATUS_OFFLINE}))
|
||||
sm = get_scada_element(p, 'sm0')
|
||||
assert sm == {}
|
||||
add_scada_element(p, ChangeSet({'id': 'sm0', 'x': 0.0, 'y': 1.0, 'device_id': 'sd0', 'model_type': SCADA_MODEL_TYPE_PIPE, 'status': SCADA_ELEMENT_STATUS_OFFLINE}))
|
||||
sm = get_scada_element(p, 'sm0')
|
||||
assert sm == {}
|
||||
|
||||
add_scada_element(p, ChangeSet({'id': 'sm0', 'x': 0.0, 'y': 1.0, 'device_id': 'sd0', 'model_id': 'j1', 'model_type': SCADA_MODEL_TYPE_JUNCTION, 'status': SCADA_ELEMENT_STATUS_OFFLINE}))
|
||||
sm = get_scada_element(p, 'sm0')
|
||||
assert sm['id'] == 'sm0'
|
||||
assert sm['x'] == 0.0
|
||||
assert sm['y'] == 1.0
|
||||
assert sm['device_id'] == 'sd0'
|
||||
assert sm['model_id'] == 'j1'
|
||||
assert sm['model_type'] == SCADA_MODEL_TYPE_JUNCTION
|
||||
assert sm['status'] == SCADA_ELEMENT_STATUS_OFFLINE
|
||||
|
||||
add_scada_element(p, ChangeSet({'id': 'sm1', 'x': 1.0, 'y': 2.0, 'device_id': 'sd1', 'model_id': 'p0', 'model_type': SCADA_MODEL_TYPE_PIPE, 'status': SCADA_ELEMENT_STATUS_ONLINE}))
|
||||
sm = get_scada_element(p, 'sm1')
|
||||
assert sm == {}
|
||||
add_scada_element(p, ChangeSet({'id': 'sm1', 'x': 1.0, 'y': 2.0, 'device_id': 'sd1', 'model_id': 'p0', 'status': SCADA_ELEMENT_STATUS_ONLINE}))
|
||||
sm = get_scada_element(p, 'sm1')
|
||||
assert sm == {}
|
||||
add_scada_element(p, ChangeSet({'id': 'sm1', 'x': 1.0, 'y': 2.0, 'device_id': 'sd1', 'model_id': 'p1', 'status': SCADA_ELEMENT_STATUS_ONLINE}))
|
||||
add_scada_element(p, ChangeSet({'id': 'sm1', 'x': 1.0, 'y': 2.0, 'device_id': 'sd1', 'model_type': SCADA_MODEL_TYPE_PIPE, 'status': SCADA_ELEMENT_STATUS_ONLINE}))
|
||||
sm = get_scada_element(p, 'sm1')
|
||||
assert sm == {}
|
||||
add_scada_element(p, ChangeSet({'id': 'sm1', 'x': 1.0, 'y': 2.0, 'device_id': 'sd1', 'model_id': 'p0', 'model_type': SCADA_MODEL_TYPE_JUNCTION, 'status': SCADA_ELEMENT_STATUS_ONLINE}))
|
||||
sm = get_scada_element(p, 'sm1')
|
||||
assert sm == {}
|
||||
|
||||
add_scada_element(p, ChangeSet({'id': 'sm1', 'x': 1.0, 'y': 2.0, 'device_id': 'sd1', 'model_id': 'p1', 'model_type': SCADA_MODEL_TYPE_PIPE, 'status': SCADA_ELEMENT_STATUS_ONLINE}))
|
||||
sm = get_scada_element(p, 'sm1')
|
||||
assert sm['id'] == 'sm1'
|
||||
assert sm['x'] == 1.0
|
||||
assert sm['y'] == 2.0
|
||||
assert sm['device_id'] == 'sd1'
|
||||
assert sm['model_id'] == 'p1'
|
||||
assert sm['model_type'] == SCADA_MODEL_TYPE_PIPE
|
||||
assert sm['status'] == SCADA_ELEMENT_STATUS_ONLINE
|
||||
|
||||
elements = get_scada_elements(p)
|
||||
@@ -5203,22 +5225,44 @@ class TestApi:
|
||||
assert elements[0] == 'sm0'
|
||||
assert elements[1] == 'sm1'
|
||||
|
||||
set_scada_element(p, ChangeSet({'id': 'sm0', 'x': 1.0, 'y': 2.0, 'device_id': 'sd1', 'model_id': 'p1', 'status': SCADA_ELEMENT_STATUS_ONLINE}))
|
||||
set_scada_element(p, ChangeSet({'id': 'sm0', 'x': 1.0, 'y': 2.0, 'device_id': 'sd1', 'model_id': 'p1', 'model_type': SCADA_MODEL_TYPE_PIPE, 'status': SCADA_ELEMENT_STATUS_ONLINE}))
|
||||
sm = get_scada_element(p, 'sm0')
|
||||
assert sm['id'] == 'sm0'
|
||||
assert sm['x'] == 1.0
|
||||
assert sm['y'] == 2.0
|
||||
assert sm['device_id'] == 'sd1'
|
||||
assert sm['model_id'] == 'p1'
|
||||
assert sm['model_type'] == SCADA_MODEL_TYPE_PIPE
|
||||
assert sm['status'] == SCADA_ELEMENT_STATUS_ONLINE
|
||||
|
||||
set_scada_element(p, ChangeSet({'id': 'sm1', 'x': 0.0, 'y': 1.0, 'device_id': 'sd0', 'model_id': 'j1', 'status': SCADA_ELEMENT_STATUS_OFFLINE}))
|
||||
set_scada_element(p, ChangeSet({'id': 'sm0', 'x': 1.0, 'y': 2.0, 'device_id': 'sd1', 'model_id': 'p1', 'model_type': SCADA_MODEL_TYPE_JUNCTION, 'status': SCADA_ELEMENT_STATUS_ONLINE}))
|
||||
sm = get_scada_element(p, 'sm0')
|
||||
assert sm['id'] == 'sm0'
|
||||
assert sm['x'] == 1.0
|
||||
assert sm['y'] == 2.0
|
||||
assert sm['device_id'] == 'sd1'
|
||||
assert sm['model_id'] == 'p1'
|
||||
assert sm['model_type'] == SCADA_MODEL_TYPE_PIPE
|
||||
assert sm['status'] == SCADA_ELEMENT_STATUS_ONLINE
|
||||
|
||||
set_scada_element(p, ChangeSet({'id': 'sm1', 'x': 0.0, 'y': 1.0, 'device_id': 'sd0', 'model_id': 'j1', 'model_type': SCADA_MODEL_TYPE_JUNCTION, 'status': SCADA_ELEMENT_STATUS_OFFLINE}))
|
||||
sm = get_scada_element(p, 'sm1')
|
||||
assert sm['id'] == 'sm1'
|
||||
assert sm['x'] == 0.0
|
||||
assert sm['y'] == 1.0
|
||||
assert sm['device_id'] == 'sd0'
|
||||
assert sm['model_id'] == 'j1'
|
||||
assert sm['model_type'] == SCADA_MODEL_TYPE_JUNCTION
|
||||
assert sm['status'] == SCADA_ELEMENT_STATUS_OFFLINE
|
||||
|
||||
set_scada_element(p, ChangeSet({'id': 'sm1', 'x': 0.0, 'y': 1.0, 'device_id': 'sd0', 'model_id': 'j1', 'model_type': SCADA_MODEL_TYPE_PIPE, 'status': SCADA_ELEMENT_STATUS_OFFLINE}))
|
||||
sm = get_scada_element(p, 'sm1')
|
||||
assert sm['id'] == 'sm1'
|
||||
assert sm['x'] == 0.0
|
||||
assert sm['y'] == 1.0
|
||||
assert sm['device_id'] == 'sd0'
|
||||
assert sm['model_id'] == 'j1'
|
||||
assert sm['model_type'] == SCADA_MODEL_TYPE_JUNCTION
|
||||
assert sm['status'] == SCADA_ELEMENT_STATUS_OFFLINE
|
||||
|
||||
delete_scada_element(p, ChangeSet({'id': 'sm0'}))
|
||||
@@ -5231,22 +5275,24 @@ class TestApi:
|
||||
|
||||
assert get_scada_elements(p) == []
|
||||
|
||||
add_scada_element(p, ChangeSet({'id': 'sm0', 'x': 0.0, 'y': 1.0, 'device_id': 'sd0', 'model_id': 'j1', 'status': SCADA_ELEMENT_STATUS_OFFLINE}))
|
||||
add_scada_element(p, ChangeSet({'id': 'sm0', 'x': 0.0, 'y': 1.0, 'device_id': 'sd0', 'model_id': 'j1', 'model_type': SCADA_MODEL_TYPE_JUNCTION, 'status': SCADA_ELEMENT_STATUS_OFFLINE}))
|
||||
sm = get_scada_element(p, 'sm0')
|
||||
assert sm['id'] == 'sm0'
|
||||
assert sm['x'] == 0.0
|
||||
assert sm['y'] == 1.0
|
||||
assert sm['device_id'] == 'sd0'
|
||||
assert sm['model_id'] == 'j1'
|
||||
assert sm['model_type'] == SCADA_MODEL_TYPE_JUNCTION
|
||||
assert sm['status'] == SCADA_ELEMENT_STATUS_OFFLINE
|
||||
|
||||
add_scada_element(p, ChangeSet({'id': 'sm1', 'x': 1.0, 'y': 2.0, 'device_id': 'sd1', 'model_id': 'p1', 'status': SCADA_ELEMENT_STATUS_ONLINE}))
|
||||
add_scada_element(p, ChangeSet({'id': 'sm1', 'x': 1.0, 'y': 2.0, 'device_id': 'sd1', 'model_id': 'p1', 'model_type': SCADA_MODEL_TYPE_PIPE, 'status': SCADA_ELEMENT_STATUS_ONLINE}))
|
||||
sm = get_scada_element(p, 'sm1')
|
||||
assert sm['id'] == 'sm1'
|
||||
assert sm['x'] == 1.0
|
||||
assert sm['y'] == 2.0
|
||||
assert sm['device_id'] == 'sd1'
|
||||
assert sm['model_id'] == 'p1'
|
||||
assert sm['model_type'] == SCADA_MODEL_TYPE_PIPE
|
||||
assert sm['status'] == SCADA_ELEMENT_STATUS_ONLINE
|
||||
|
||||
elements = get_scada_elements(p)
|
||||
@@ -5275,9 +5321,9 @@ class TestApi:
|
||||
add_scada_device(p, ChangeSet({'id': 'sd0', 'name': 'device0', 'address': 'x0', 'sd_type': SCADA_DEVICE_TYPE_PRESSURE}))
|
||||
add_scada_device(p, ChangeSet({'id': 'sd1', 'name': 'device1', 'address': 'x1', 'sd_type': SCADA_DEVICE_TYPE_FLOW}))
|
||||
|
||||
css = add_scada_element(p, ChangeSet({'id': 'sm0', 'x': 0.0, 'y': 1.0, 'device_id': 'sd0', 'model_id': 'j0', 'status': SCADA_ELEMENT_STATUS_OFFLINE})).operations
|
||||
css = add_scada_element(p, ChangeSet({'id': 'sm0', 'x': 0.0, 'y': 1.0, 'device_id': 'sd0', 'model_id': 'j0', 'model_type': SCADA_MODEL_TYPE_JUNCTION, 'status': SCADA_ELEMENT_STATUS_OFFLINE})).operations
|
||||
assert len(css) == 0
|
||||
cs = add_scada_element(p, ChangeSet({'id': 'sm0', 'x': 0.0, 'y': 1.0, 'device_id': 'sd0', 'model_id': 'j1', 'status': SCADA_ELEMENT_STATUS_OFFLINE})).operations[0]
|
||||
cs = add_scada_element(p, ChangeSet({'id': 'sm0', 'x': 0.0, 'y': 1.0, 'device_id': 'sd0', 'model_id': 'j1', 'model_type': SCADA_MODEL_TYPE_JUNCTION, 'status': SCADA_ELEMENT_STATUS_OFFLINE})).operations[0]
|
||||
assert cs['operation'] == API_ADD
|
||||
assert cs['type'] == 'scada_element'
|
||||
assert cs['id'] == 'sm0'
|
||||
@@ -5285,6 +5331,7 @@ class TestApi:
|
||||
assert cs['y'] == 1.0
|
||||
assert cs['device_id'] == 'sd0'
|
||||
assert cs['model_id'] == 'j1'
|
||||
assert cs['model_type'] == SCADA_MODEL_TYPE_JUNCTION
|
||||
assert cs['status'] == SCADA_ELEMENT_STATUS_OFFLINE
|
||||
|
||||
cs = execute_undo(p).operations[0]
|
||||
@@ -5300,11 +5347,12 @@ class TestApi:
|
||||
assert cs['y'] == 1.0
|
||||
assert cs['device_id'] == 'sd0'
|
||||
assert cs['model_id'] == 'j1'
|
||||
assert cs['model_type'] == SCADA_MODEL_TYPE_JUNCTION
|
||||
assert cs['status'] == SCADA_ELEMENT_STATUS_OFFLINE
|
||||
|
||||
css = add_scada_element(p, ChangeSet({'id': 'sm1', 'x': 1.0, 'y': 2.0, 'device_id': 'sd1', 'model_id': 'p0', 'status': SCADA_ELEMENT_STATUS_ONLINE})).operations
|
||||
css = add_scada_element(p, ChangeSet({'id': 'sm1', 'x': 1.0, 'y': 2.0, 'device_id': 'sd1', 'model_id': 'p0', 'model_type': SCADA_MODEL_TYPE_PIPE, 'status': SCADA_ELEMENT_STATUS_ONLINE})).operations
|
||||
assert len(css) == 0
|
||||
cs = add_scada_element(p, ChangeSet({'id': 'sm1', 'x': 1.0, 'y': 2.0, 'device_id': 'sd1', 'model_id': 'p1', 'status': SCADA_ELEMENT_STATUS_ONLINE})).operations[0]
|
||||
cs = add_scada_element(p, ChangeSet({'id': 'sm1', 'x': 1.0, 'y': 2.0, 'device_id': 'sd1', 'model_id': 'p1', 'model_type': SCADA_MODEL_TYPE_PIPE, 'status': SCADA_ELEMENT_STATUS_ONLINE})).operations[0]
|
||||
assert cs['operation'] == API_ADD
|
||||
assert cs['type'] == 'scada_element'
|
||||
assert cs['id'] == 'sm1'
|
||||
@@ -5312,6 +5360,7 @@ class TestApi:
|
||||
assert cs['y'] == 2.0
|
||||
assert cs['device_id'] == 'sd1'
|
||||
assert cs['model_id'] == 'p1'
|
||||
assert cs['model_type'] == SCADA_MODEL_TYPE_PIPE
|
||||
assert cs['status'] == SCADA_ELEMENT_STATUS_ONLINE
|
||||
|
||||
cs = execute_undo(p).operations[0]
|
||||
@@ -5327,9 +5376,10 @@ class TestApi:
|
||||
assert cs['y'] == 2.0
|
||||
assert cs['device_id'] == 'sd1'
|
||||
assert cs['model_id'] == 'p1'
|
||||
assert cs['model_type'] == SCADA_MODEL_TYPE_PIPE
|
||||
assert cs['status'] == SCADA_ELEMENT_STATUS_ONLINE
|
||||
|
||||
cs = set_scada_element(p, ChangeSet({'id': 'sm0', 'x': 1.0, 'y': 2.0, 'device_id': 'sd1', 'model_id': 'p1', 'status': SCADA_ELEMENT_STATUS_ONLINE})).operations[0]
|
||||
cs = set_scada_element(p, ChangeSet({'id': 'sm0', 'x': 1.0, 'y': 2.0, 'device_id': 'sd1', 'model_id': 'p1', 'model_type': SCADA_MODEL_TYPE_PIPE, 'status': SCADA_ELEMENT_STATUS_ONLINE})).operations[0]
|
||||
assert cs['operation'] == API_UPDATE
|
||||
assert cs['type'] == 'scada_element'
|
||||
assert cs['id'] == 'sm0'
|
||||
@@ -5337,6 +5387,7 @@ class TestApi:
|
||||
assert cs['y'] == 2.0
|
||||
assert cs['device_id'] == 'sd1'
|
||||
assert cs['model_id'] == 'p1'
|
||||
assert cs['model_type'] == SCADA_MODEL_TYPE_PIPE
|
||||
assert cs['status'] == SCADA_ELEMENT_STATUS_ONLINE
|
||||
|
||||
cs = execute_undo(p).operations[0]
|
||||
@@ -5347,6 +5398,7 @@ class TestApi:
|
||||
assert cs['y'] == 1.0
|
||||
assert cs['device_id'] == 'sd0'
|
||||
assert cs['model_id'] == 'j1'
|
||||
assert cs['model_type'] == SCADA_MODEL_TYPE_JUNCTION
|
||||
assert cs['status'] == SCADA_ELEMENT_STATUS_OFFLINE
|
||||
|
||||
cs = execute_redo(p).operations[0]
|
||||
@@ -5357,9 +5409,10 @@ class TestApi:
|
||||
assert cs['y'] == 2.0
|
||||
assert cs['device_id'] == 'sd1'
|
||||
assert cs['model_id'] == 'p1'
|
||||
assert cs['model_type'] == SCADA_MODEL_TYPE_PIPE
|
||||
assert cs['status'] == SCADA_ELEMENT_STATUS_ONLINE
|
||||
|
||||
cs = set_scada_element(p, ChangeSet({'id': 'sm1', 'x': 0.0, 'y': 1.0, 'device_id': 'sd0', 'model_id': 'j1', 'status': SCADA_ELEMENT_STATUS_OFFLINE})).operations[0]
|
||||
cs = set_scada_element(p, ChangeSet({'id': 'sm1', 'x': 0.0, 'y': 1.0, 'device_id': 'sd0', 'model_id': 'j1', 'model_type': SCADA_MODEL_TYPE_JUNCTION, 'status': SCADA_ELEMENT_STATUS_OFFLINE})).operations[0]
|
||||
assert cs['operation'] == API_UPDATE
|
||||
assert cs['type'] == 'scada_element'
|
||||
assert cs['id'] == 'sm1'
|
||||
@@ -5367,6 +5420,7 @@ class TestApi:
|
||||
assert cs['y'] == 1.0
|
||||
assert cs['device_id'] == 'sd0'
|
||||
assert cs['model_id'] == 'j1'
|
||||
assert cs['model_type'] == SCADA_MODEL_TYPE_JUNCTION
|
||||
assert cs['status'] == SCADA_ELEMENT_STATUS_OFFLINE
|
||||
|
||||
cs = execute_undo(p).operations[0]
|
||||
@@ -5377,6 +5431,7 @@ class TestApi:
|
||||
assert cs['y'] == 2.0
|
||||
assert cs['device_id'] == 'sd1'
|
||||
assert cs['model_id'] == 'p1'
|
||||
assert cs['model_type'] == SCADA_MODEL_TYPE_PIPE
|
||||
assert cs['status'] == SCADA_ELEMENT_STATUS_ONLINE
|
||||
|
||||
cs = execute_redo(p).operations[0]
|
||||
@@ -5387,6 +5442,7 @@ class TestApi:
|
||||
assert cs['y'] == 1.0
|
||||
assert cs['device_id'] == 'sd0'
|
||||
assert cs['model_id'] == 'j1'
|
||||
assert cs['model_type'] == SCADA_MODEL_TYPE_JUNCTION
|
||||
assert cs['status'] == SCADA_ELEMENT_STATUS_OFFLINE
|
||||
|
||||
cs = delete_scada_element(p, ChangeSet({'id': 'sm0'})).operations[0]
|
||||
@@ -5402,6 +5458,7 @@ class TestApi:
|
||||
assert cs['y'] == 2.0
|
||||
assert cs['device_id'] == 'sd1'
|
||||
assert cs['model_id'] == 'p1'
|
||||
assert cs['model_type'] == SCADA_MODEL_TYPE_PIPE
|
||||
assert cs['status'] == SCADA_ELEMENT_STATUS_ONLINE
|
||||
|
||||
cs = execute_redo(p).operations[0]
|
||||
@@ -5422,6 +5479,7 @@ class TestApi:
|
||||
assert cs['y'] == 1.0
|
||||
assert cs['device_id'] == 'sd0'
|
||||
assert cs['model_id'] == 'j1'
|
||||
assert cs['model_type'] == SCADA_MODEL_TYPE_JUNCTION
|
||||
assert cs['status'] == SCADA_ELEMENT_STATUS_OFFLINE
|
||||
|
||||
cs = execute_redo(p).operations[0]
|
||||
@@ -5429,7 +5487,7 @@ class TestApi:
|
||||
assert cs['type'] == 'scada_element'
|
||||
assert cs['id'] == 'sm1'
|
||||
|
||||
cs = add_scada_element(p, ChangeSet({'id': 'sm0', 'x': 0.0, 'y': 1.0, 'device_id': 'sd0', 'model_id': 'j1', 'status': SCADA_ELEMENT_STATUS_OFFLINE})).operations[0]
|
||||
cs = add_scada_element(p, ChangeSet({'id': 'sm0', 'x': 0.0, 'y': 1.0, 'device_id': 'sd0', 'model_id': 'j1', 'model_type': SCADA_MODEL_TYPE_JUNCTION, 'status': SCADA_ELEMENT_STATUS_OFFLINE})).operations[0]
|
||||
assert cs['operation'] == API_ADD
|
||||
assert cs['type'] == 'scada_element'
|
||||
assert cs['id'] == 'sm0'
|
||||
@@ -5437,9 +5495,10 @@ class TestApi:
|
||||
assert cs['y'] == 1.0
|
||||
assert cs['device_id'] == 'sd0'
|
||||
assert cs['model_id'] == 'j1'
|
||||
assert cs['model_type'] == SCADA_MODEL_TYPE_JUNCTION
|
||||
assert cs['status'] == SCADA_ELEMENT_STATUS_OFFLINE
|
||||
|
||||
cs = add_scada_element(p, ChangeSet({'id': 'sm1', 'x': 1.0, 'y': 2.0, 'device_id': 'sd1', 'model_id': 'p1', 'status': SCADA_ELEMENT_STATUS_ONLINE})).operations[0]
|
||||
cs = add_scada_element(p, ChangeSet({'id': 'sm1', 'x': 1.0, 'y': 2.0, 'device_id': 'sd1', 'model_id': 'p1', 'model_type': SCADA_MODEL_TYPE_PIPE, 'status': SCADA_ELEMENT_STATUS_ONLINE})).operations[0]
|
||||
assert cs['operation'] == API_ADD
|
||||
assert cs['type'] == 'scada_element'
|
||||
assert cs['id'] == 'sm1'
|
||||
@@ -5447,6 +5506,7 @@ class TestApi:
|
||||
assert cs['y'] == 2.0
|
||||
assert cs['device_id'] == 'sd1'
|
||||
assert cs['model_id'] == 'p1'
|
||||
assert cs['model_type'] == SCADA_MODEL_TYPE_PIPE
|
||||
assert cs['status'] == SCADA_ELEMENT_STATUS_ONLINE
|
||||
|
||||
css = clean_scada_element(p).operations
|
||||
@@ -5468,6 +5528,7 @@ class TestApi:
|
||||
assert cs['y'] == 2.0
|
||||
assert cs['device_id'] == 'sd1'
|
||||
assert cs['model_id'] == 'p1'
|
||||
assert cs['model_type'] == SCADA_MODEL_TYPE_PIPE
|
||||
assert cs['status'] == SCADA_ELEMENT_STATUS_ONLINE
|
||||
cs = css[1]
|
||||
assert cs['operation'] == API_ADD
|
||||
@@ -5477,6 +5538,7 @@ class TestApi:
|
||||
assert cs['y'] == 1.0
|
||||
assert cs['device_id'] == 'sd0'
|
||||
assert cs['model_id'] == 'j1'
|
||||
assert cs['model_type'] == SCADA_MODEL_TYPE_JUNCTION
|
||||
assert cs['status'] == SCADA_ELEMENT_STATUS_OFFLINE
|
||||
|
||||
css = execute_redo(p).operations
|
||||
|
||||
@@ -150,6 +150,15 @@ SCADA_DEVICE_TYPE_QUALITY = api.SCADA_DEVICE_TYPE_QUALITY
|
||||
SCADA_DEVICE_TYPE_LEVEL = api.SCADA_DEVICE_TYPE_LEVEL
|
||||
SCADA_DEVICE_TYPE_FLOW = api.SCADA_DEVICE_TYPE_FLOW
|
||||
|
||||
|
||||
SCADA_MODEL_TYPE_JUNCTION = api.SCADA_MODEL_TYPE_JUNCTION
|
||||
SCADA_MODEL_TYPE_RESERVOIR = api.SCADA_MODEL_TYPE_RESERVOIR
|
||||
SCADA_MODEL_TYPE_TANK = api.SCADA_MODEL_TYPE_TANK
|
||||
SCADA_MODEL_TYPE_PIPE = api.SCADA_MODEL_TYPE_PIPE
|
||||
SCADA_MODEL_TYPE_PUMP = api.SCADA_MODEL_TYPE_PUMP
|
||||
SCADA_MODEL_TYPE_VALVE = api.SCADA_MODEL_TYPE_VALVE
|
||||
|
||||
|
||||
SCADA_ELEMENT_STATUS_ONLINE = api.SCADA_ELEMENT_STATUS_ONLINE
|
||||
SCADA_ELEMENT_STATUS_OFFLINE = api.SCADA_ELEMENT_STATUS_OFFLINE
|
||||
|
||||
|
||||
Reference in New Issue
Block a user