Accept Merge Request #148: (api -> master)
Merge Request: More scada api and set restore operation Created By: @王琼钰 Accepted By: @王琼钰 URL: https://tjwater.coding.net/p/tjwatercloud/d/TJWaterServer/git/merge/148
This commit is contained in:
@@ -9,7 +9,7 @@ from .database import ChangeSet
|
||||
from .database import get_current_operation
|
||||
from .database import execute_undo, execute_redo
|
||||
from .database import have_snapshot, take_snapshot, pick_snapshot
|
||||
from .database import pick_operation, sync_with_server, get_restore_operation
|
||||
from .database import pick_operation, sync_with_server, get_restore_operation, set_restore_operation
|
||||
|
||||
from .batch_cmd import execute_batch_command
|
||||
from .batch_cmds import execute_batch_commands
|
||||
@@ -100,6 +100,7 @@ from .s26_labels import get_label_schema, get_label, set_label, add_label, delet
|
||||
from .s27_backdrop import get_backdrop_schema, get_backdrop, set_backdrop
|
||||
|
||||
from .s29_scada_model import SCADA_TYPE_PRESSURE, SCADA_TYPE_DEMAND, SCADA_TYPE_QUALITY, SCADA_TYPE_LEVEL, SCADA_TYPE_FLOW
|
||||
from .s29_scada_model import SCADA_STATUS_OFFLINE, SCADA_STATUS_ONLINE
|
||||
from .s29_scada_model import get_scada_model_schema, get_scada_model, set_scada_model, add_scada_model, delete_scada_model
|
||||
|
||||
from .s30_scada_data import get_scada_data_schema, get_scada_data, set_scada_data
|
||||
from .s30_scada_data import get_scada_data_schema, get_scada_data, set_scada_data, add_scada_data, delete_scada_data
|
||||
|
||||
@@ -278,3 +278,7 @@ def sync_with_server(name: str, operation: int) -> ChangeSet:
|
||||
|
||||
def get_restore_operation(name: str) -> int:
|
||||
return read(name, f'select * from restore_operation')['id']
|
||||
|
||||
|
||||
def set_restore_operation(name: str, operation: int) -> None:
|
||||
write(name, f'update restore_operation set id = {operation}')
|
||||
|
||||
@@ -229,7 +229,7 @@ def read_inp(project: str, inp: str):
|
||||
|
||||
execute_batch_commands(project, _read_inp(inp))
|
||||
op = get_current_operation(project)
|
||||
write(project, f'update restore_operation set id = {op}')
|
||||
set_restore_operation(project, op)
|
||||
|
||||
|
||||
def dump_inp(project: str, inp: str):
|
||||
|
||||
@@ -7,6 +7,10 @@ SCADA_TYPE_QUALITY = 'QUALITY'
|
||||
SCADA_TYPE_LEVEL = 'LEVEL'
|
||||
SCADA_TYPE_FLOW = 'FLOW'
|
||||
|
||||
SCADA_STATUS_OFFLINE = 'OFF'
|
||||
SCADA_STATUS_ONLINE = 'ON'
|
||||
|
||||
|
||||
def _check_model_id(name: str, cs: ChangeSet) -> bool:
|
||||
if 'model_id' not in cs.operations[0]:
|
||||
return True
|
||||
@@ -24,7 +28,8 @@ def get_scada_model_schema(name: str) -> dict[str, dict[str, Any]]:
|
||||
'device_name' : {'type': 'str' , 'optional': True , 'readonly': False},
|
||||
'address' : {'type': 'str' , 'optional': True , 'readonly': False},
|
||||
'sm_type' : {'type': 'str' , 'optional': True , 'readonly': False},
|
||||
'model_id' : {'type': 'str' , 'optional': True , 'readonly': False} }
|
||||
'model_id' : {'type': 'str' , 'optional': True , 'readonly': False},
|
||||
'status' : {'type': 'str' , 'optional': True , 'readonly': False} }
|
||||
|
||||
|
||||
def get_scada_model(name: str, id: str) -> dict[str, Any]:
|
||||
@@ -40,6 +45,7 @@ def get_scada_model(name: str, id: str) -> dict[str, Any]:
|
||||
d['address'] = str(sm['address']) if sm['address'] != None else None
|
||||
d['sm_type'] = str(sm['type']) if sm['type'] != None else None
|
||||
d['model_id'] = str(sm['model_id']) if sm['model_id'] != None else None
|
||||
d['status'] = str(sm['status'])
|
||||
return d
|
||||
|
||||
|
||||
@@ -54,6 +60,7 @@ class ScadaModel(object):
|
||||
self.address = str(input['address']) if 'address' in input and input['address'] != None else None
|
||||
self.sm_type = str(input['sm_type']) if 'sm_type' in input and input['sm_type'] != None else None
|
||||
self.model_id = str(input['model_id']) if 'model_id' in input and input['model_id'] != None else None
|
||||
self.status = str(input['status']) if 'status' in input and input['status'] != None else SCADA_STATUS_OFFLINE
|
||||
|
||||
self.f_type = f"'{self.type}'"
|
||||
self.f_id = f"'{self.id}'"
|
||||
@@ -64,9 +71,10 @@ class ScadaModel(object):
|
||||
self.f_address = f"'{self.address}'" if self.address != None else 'null'
|
||||
self.f_sm_type = f"'{self.sm_type}'" if self.sm_type != None else 'null'
|
||||
self.f_model_id = f"'{self.model_id}'" if self.model_id != 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, 'device_name': self.device_name, 'address': self.address, 'sm_type': self.sm_type, 'model_id': self.model_id }
|
||||
return { 'type': self.type, 'id': self.id, 'x': self.x, 'y': self.y, 'device_id': self.device_id, 'device_name': self.device_name, 'address': self.address, 'sm_type': self.sm_type, 'model_id': self.model_id, 'status': self.status }
|
||||
|
||||
def as_id_dict(self) -> dict[str, Any]:
|
||||
return { 'type': self.type, 'id': self.id }
|
||||
@@ -83,8 +91,8 @@ def set_scada_model_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
raw_new[key] = new_dict[key]
|
||||
new = ScadaModel(raw_new)
|
||||
|
||||
redo_sql = f"update scada_model set x = {new.f_x}, y = {new.f_y}, device_id = {new.f_device_id}, device_name = {new.f_device_name}, address = {new.f_address}, type = {new.f_sm_type}, model_id = {new.f_model_id} where id = {new.f_id};"
|
||||
undo_sql = f"update scada_model set x = {old.f_x}, y = {old.f_y}, device_id = {old.f_device_id}, device_name = {old.f_device_name}, address = {old.f_address}, type = {old.f_sm_type}, model_id = {old.f_model_id} where id = {old.f_id};"
|
||||
redo_sql = f"update scada_model set x = {new.f_x}, y = {new.f_y}, device_id = {new.f_device_id}, device_name = {new.f_device_name}, address = {new.f_address}, type = {new.f_sm_type}, model_id = {new.f_model_id}, status = {new.f_status} where id = {new.f_id};"
|
||||
undo_sql = f"update scada_model set x = {old.f_x}, y = {old.f_y}, device_id = {old.f_device_id}, device_name = {old.f_device_name}, address = {old.f_address}, type = {old.f_sm_type}, model_id = {old.f_model_id}, 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()
|
||||
@@ -103,7 +111,7 @@ def set_scada_model(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
def add_scada_model_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
new = ScadaModel(cs.operations[0])
|
||||
|
||||
redo_sql = f"insert into scada_model (id, x, y, device_id, device_name, address, type, model_id) values ({new.f_id}, {new.f_x}, {new.f_y}, {new.f_device_id}, {new.f_device_name}, {new.f_address}, {new.f_sm_type}, {new.f_model_id});"
|
||||
redo_sql = f"insert into scada_model (id, x, y, device_id, device_name, address, type, model_id, status) values ({new.f_id}, {new.f_x}, {new.f_y}, {new.f_device_id}, {new.f_device_name}, {new.f_address}, {new.f_sm_type}, {new.f_model_id}, {new.f_status});"
|
||||
undo_sql = f"delete from scada_model where id = {new.f_id};"
|
||||
|
||||
redo_cs = g_add_prefix | new.as_dict()
|
||||
@@ -124,7 +132,7 @@ def delete_scada_model_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
old = ScadaModel(get_scada_model(name, cs.operations[0]['id']))
|
||||
|
||||
redo_sql = f"delete from scada_model where id = {old.f_id};"
|
||||
undo_sql = f"insert into scada_model (id, x, y, device_id, device_name, address, type, model_id) values ({old.f_id}, {old.f_x}, {old.f_y}, {old.f_device_id}, {old.f_device_name}, {old.f_address}, {old.f_sm_type}, {old.f_model_id});"
|
||||
undo_sql = f"insert into scada_model (id, x, y, device_id, device_name, address, type, model_id, status) values ({old.f_id}, {old.f_x}, {old.f_y}, {old.f_device_id}, {old.f_device_name}, {old.f_address}, {old.f_sm_type}, {old.f_model_id}, {old.f_status});"
|
||||
|
||||
redo_cs = g_delete_prefix | old.as_id_dict()
|
||||
undo_cs = g_add_prefix | old.as_dict()
|
||||
|
||||
@@ -49,3 +49,45 @@ def set_scada_data(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
result.redo_cs[0] |= g_update_prefix
|
||||
result.undo_cs[0] |= g_update_prefix
|
||||
return execute_command(name, result)
|
||||
|
||||
|
||||
def add_scada_data_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
values = cs.operations[0]
|
||||
device_id = values['device_id']
|
||||
time = values['time']
|
||||
value = float(values['value'])
|
||||
|
||||
redo_sql = f"insert into scada_data (device_id, time, value) values ('{device_id}', '{time}', {value});"
|
||||
undo_sql = f"delete from scada_data where device_id = '{device_id}' and time = '{time}';"
|
||||
redo_cs = g_add_prefix | { 'type': 'scada_data', 'device_id': device_id, 'time': time, 'value': value }
|
||||
undo_cs = g_delete_prefix | { 'type': 'scada_data', 'device_id': device_id, 'time': time }
|
||||
|
||||
return DbChangeSet(redo_sql, undo_sql, [redo_cs], [undo_cs])
|
||||
|
||||
|
||||
def add_scada_data(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
row = try_read(name, f"select * from scada_data where device_id = '{cs.operations[0]['device_id']}' and time = '{cs.operations[0]['time']}'")
|
||||
if row != None:
|
||||
return ChangeSet()
|
||||
return execute_command(name, add_scada_data_cmd(name, cs))
|
||||
|
||||
|
||||
def delete_scada_data_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
values = cs.operations[0]
|
||||
device_id = values['device_id']
|
||||
time = values['time']
|
||||
value = float(read(name, f"select * from scada_data where device_id = '{device_id}' and time = '{time}'")['value'])
|
||||
|
||||
redo_sql = f"delete from scada_data where device_id = '{device_id}' and time = '{time}';"
|
||||
undo_sql = f"insert into scada_data (device_id, time, value) values ('{device_id}', '{time}', {value});"
|
||||
redo_cs = g_delete_prefix | { 'type': 'scada_data', 'device_id': device_id, 'time': time }
|
||||
undo_cs = g_add_prefix | { 'type': 'scada_data', 'device_id': device_id, 'time': time, 'value': value }
|
||||
|
||||
return DbChangeSet(redo_sql, undo_sql, [redo_cs], [undo_cs])
|
||||
|
||||
|
||||
def delete_scada_data(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
row = try_read(name, f"select * from scada_data where device_id = '{cs.operations[0]['device_id']}' and time = '{cs.operations[0]['time']}'")
|
||||
if row == None:
|
||||
return ChangeSet()
|
||||
return execute_command(name, delete_scada_data_cmd(name, cs))
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
create type scada_type as enum ('PRESSURE', 'DEMAND', 'QUALITY', 'LEVEL', 'FLOW');
|
||||
create type scada_status as enum ('OFF', 'ON');
|
||||
|
||||
create table scada_model
|
||||
(
|
||||
@@ -10,4 +11,5 @@ create table scada_model
|
||||
, address text
|
||||
, type scada_type
|
||||
, model_id varchar(32) -- add constraint in API
|
||||
, status scada_status not null default 'OFF'
|
||||
);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
drop table if exists scada_model;
|
||||
|
||||
drop type if exists scada_status;
|
||||
|
||||
drop type if exists scada_type;
|
||||
|
||||
@@ -3677,6 +3677,7 @@ class TestApi:
|
||||
assert sm['address'] == None
|
||||
assert sm['sm_type'] == None
|
||||
assert sm['model_id'] == None
|
||||
assert sm['status'] == SCADA_STATUS_OFFLINE
|
||||
|
||||
add_scada_model(p, ChangeSet({'id': 'sm0', 'x': 0.0, 'y': 10.0, 'device_id': 'sm_device_0', 'device_name': 'sm_device_name', 'address': 'xxx', 'sm_type': SCADA_TYPE_PRESSURE, 'model_id': 'j0'}))
|
||||
sm0 = get_scada_model(p, 'sm0')
|
||||
@@ -3696,8 +3697,9 @@ class TestApi:
|
||||
assert sm1['address'] == 'xxx'
|
||||
assert sm1['sm_type'] == SCADA_TYPE_PRESSURE
|
||||
assert sm1['model_id'] == 'j1'
|
||||
assert sm1['status'] == SCADA_STATUS_OFFLINE
|
||||
|
||||
add_scada_model(p, ChangeSet({'id': 'sm2', 'x': 0.0, 'y': 10.0, 'device_id': 'sm_device_2', 'device_name': 'sm_device_name', 'address': 'xxx', 'sm_type': SCADA_TYPE_PRESSURE, 'model_id': 'p1'}))
|
||||
add_scada_model(p, ChangeSet({'id': 'sm2', 'x': 0.0, 'y': 10.0, 'device_id': 'sm_device_2', 'device_name': 'sm_device_name', 'address': 'xxx', 'sm_type': SCADA_TYPE_PRESSURE, 'model_id': 'p1', 'status': SCADA_STATUS_ONLINE}))
|
||||
sm2 = get_scada_model(p, 'sm2')
|
||||
assert sm2['id'] == 'sm2'
|
||||
assert sm2['x'] == 0.0
|
||||
@@ -3707,8 +3709,9 @@ class TestApi:
|
||||
assert sm2['address'] == 'xxx'
|
||||
assert sm2['sm_type'] == SCADA_TYPE_PRESSURE
|
||||
assert sm2['model_id'] == 'p1'
|
||||
assert sm2['status'] == SCADA_STATUS_ONLINE
|
||||
|
||||
set_scada_model(p, ChangeSet({'id': 'sm', 'device_name': 'sm_device_name', 'address': 'xxx', 'sm_type': SCADA_TYPE_PRESSURE, 'model_id': 'j0'}))
|
||||
set_scada_model(p, ChangeSet({'id': 'sm', 'device_name': 'sm_device_name', 'address': 'xxx', 'sm_type': SCADA_TYPE_PRESSURE, 'model_id': 'j0', 'status': SCADA_STATUS_ONLINE}))
|
||||
sm = get_scada_model(p, 'sm')
|
||||
assert sm['id'] == 'sm'
|
||||
assert sm['x'] == 0.0
|
||||
@@ -3718,8 +3721,9 @@ class TestApi:
|
||||
assert sm['address'] == None
|
||||
assert sm['sm_type'] == None
|
||||
assert sm['model_id'] == None
|
||||
assert sm['status'] == SCADA_STATUS_OFFLINE
|
||||
|
||||
set_scada_model(p, ChangeSet({'id': 'sm', 'device_name': 'sm_device_name', 'address': 'xxx', 'sm_type': SCADA_TYPE_PRESSURE, 'model_id': 'j1'}))
|
||||
set_scada_model(p, ChangeSet({'id': 'sm', 'device_name': 'sm_device_name', 'address': 'xxx', 'sm_type': SCADA_TYPE_PRESSURE, 'model_id': 'j1', 'status': SCADA_STATUS_ONLINE}))
|
||||
sm = get_scada_model(p, 'sm')
|
||||
assert sm['id'] == 'sm'
|
||||
assert sm['x'] == 0.0
|
||||
@@ -3729,6 +3733,7 @@ class TestApi:
|
||||
assert sm['address'] == 'xxx'
|
||||
assert sm['sm_type'] == SCADA_TYPE_PRESSURE
|
||||
assert sm['model_id'] == 'j1'
|
||||
assert sm['status'] == SCADA_STATUS_ONLINE
|
||||
|
||||
delete_scada_model(p, ChangeSet({'id': 'sm'}))
|
||||
sm = get_scada_model(p, 'sm')
|
||||
@@ -3753,7 +3758,7 @@ class TestApi:
|
||||
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}))
|
||||
|
||||
cs = add_scada_model(p, ChangeSet({'id': 'sm', 'x': 0.0, 'y': 10.0, 'device_id': 'sm_device', 'device_name': 'sm_device_name', 'address': 'xxx', 'sm_type': SCADA_TYPE_PRESSURE, 'model_id': 'j1'})).operations[0]
|
||||
cs = add_scada_model(p, ChangeSet({'id': 'sm', 'x': 0.0, 'y': 10.0, 'device_id': 'sm_device', 'device_name': 'sm_device_name', 'address': 'xxx', 'sm_type': SCADA_TYPE_PRESSURE, 'model_id': 'j1', 'status': SCADA_STATUS_ONLINE})).operations[0]
|
||||
assert cs['operation'] == API_ADD
|
||||
assert cs['type'] == 'scada_model'
|
||||
assert cs['id'] == 'sm'
|
||||
@@ -3764,6 +3769,7 @@ class TestApi:
|
||||
assert cs['address'] == 'xxx'
|
||||
assert cs['sm_type'] == SCADA_TYPE_PRESSURE
|
||||
assert cs['model_id'] == 'j1'
|
||||
assert cs['status'] == SCADA_STATUS_ONLINE
|
||||
|
||||
cs = execute_undo(p).operations[0]
|
||||
assert cs['operation'] == API_DELETE
|
||||
@@ -3781,8 +3787,9 @@ class TestApi:
|
||||
assert cs['address'] == 'xxx'
|
||||
assert cs['sm_type'] == SCADA_TYPE_PRESSURE
|
||||
assert cs['model_id'] == 'j1'
|
||||
assert cs['status'] == SCADA_STATUS_ONLINE
|
||||
|
||||
cs = set_scada_model(p, ChangeSet({'id': 'sm', 'device_name': 'sm_device_name_', 'address': 'xxx_', 'sm_type': SCADA_TYPE_DEMAND, 'model_id': 'j2'})).operations[0]
|
||||
cs = set_scada_model(p, ChangeSet({'id': 'sm', 'device_name': 'sm_device_name_', 'address': 'xxx_', 'sm_type': SCADA_TYPE_DEMAND, 'model_id': 'j2', 'status': SCADA_STATUS_OFFLINE})).operations[0]
|
||||
assert cs['operation'] == API_UPDATE
|
||||
assert cs['type'] == 'scada_model'
|
||||
assert cs['id'] == 'sm'
|
||||
@@ -3793,6 +3800,7 @@ class TestApi:
|
||||
assert cs['address'] == 'xxx_'
|
||||
assert cs['sm_type'] == SCADA_TYPE_DEMAND
|
||||
assert cs['model_id'] == 'j2'
|
||||
assert cs['status'] == SCADA_STATUS_OFFLINE
|
||||
|
||||
cs = execute_undo(p).operations[0]
|
||||
assert cs['operation'] == API_UPDATE
|
||||
@@ -3805,6 +3813,7 @@ class TestApi:
|
||||
assert cs['address'] == 'xxx'
|
||||
assert cs['sm_type'] == SCADA_TYPE_PRESSURE
|
||||
assert cs['model_id'] == 'j1'
|
||||
assert cs['status'] == SCADA_STATUS_ONLINE
|
||||
|
||||
cs = execute_redo(p).operations[0]
|
||||
assert cs['operation'] == API_UPDATE
|
||||
@@ -3817,6 +3826,7 @@ class TestApi:
|
||||
assert cs['address'] == 'xxx_'
|
||||
assert cs['sm_type'] == SCADA_TYPE_DEMAND
|
||||
assert cs['model_id'] == 'j2'
|
||||
assert cs['status'] == SCADA_STATUS_OFFLINE
|
||||
|
||||
cs = delete_scada_model(p, ChangeSet({'id': 'sm'})).operations[0]
|
||||
assert cs['operation'] == API_DELETE
|
||||
@@ -3834,6 +3844,7 @@ class TestApi:
|
||||
assert cs['address'] == 'xxx_'
|
||||
assert cs['sm_type'] == SCADA_TYPE_DEMAND
|
||||
assert cs['model_id'] == 'j2'
|
||||
assert cs['status'] == SCADA_STATUS_OFFLINE
|
||||
|
||||
cs = execute_redo(p).operations[0]
|
||||
assert cs['operation'] == API_DELETE
|
||||
@@ -3874,6 +3885,46 @@ class TestApi:
|
||||
assert sa['data'][1]['time'] == '2023-02-10 00:03:22'
|
||||
assert sa['data'][1]['value'] == 200.0
|
||||
|
||||
add_scada_data(p, ChangeSet({'device_id': 'sm_device', 'time': '2023-02-10 00:02:22', 'value': 100.0}))
|
||||
sa = get_scada_data(p, 'sm_device')
|
||||
assert sa['device_id'] == 'sm_device'
|
||||
assert len(sa['data']) == 2
|
||||
assert sa['data'][0]['time'] == '2023-02-10 00:02:22'
|
||||
assert sa['data'][0]['value'] == 100.0
|
||||
assert sa['data'][1]['time'] == '2023-02-10 00:03:22'
|
||||
assert sa['data'][1]['value'] == 200.0
|
||||
|
||||
add_scada_data(p, ChangeSet({'device_id': 'sm_device', 'time': '2023-02-11 00:02:22', 'value': 100.0}))
|
||||
sa = get_scada_data(p, 'sm_device')
|
||||
assert sa['device_id'] == 'sm_device'
|
||||
assert len(sa['data']) == 3
|
||||
assert sa['data'][0]['time'] == '2023-02-10 00:02:22'
|
||||
assert sa['data'][0]['value'] == 100.0
|
||||
assert sa['data'][1]['time'] == '2023-02-10 00:03:22'
|
||||
assert sa['data'][1]['value'] == 200.0
|
||||
assert sa['data'][2]['time'] == '2023-02-11 00:02:22'
|
||||
assert sa['data'][2]['value'] == 100.0
|
||||
|
||||
delete_scada_data(p, ChangeSet({'device_id': 'sm_device', 'time': '2023-02-12 00:02:22'}))
|
||||
sa = get_scada_data(p, 'sm_device')
|
||||
assert sa['device_id'] == 'sm_device'
|
||||
assert len(sa['data']) == 3
|
||||
assert sa['data'][0]['time'] == '2023-02-10 00:02:22'
|
||||
assert sa['data'][0]['value'] == 100.0
|
||||
assert sa['data'][1]['time'] == '2023-02-10 00:03:22'
|
||||
assert sa['data'][1]['value'] == 200.0
|
||||
assert sa['data'][2]['time'] == '2023-02-11 00:02:22'
|
||||
assert sa['data'][2]['value'] == 100.0
|
||||
|
||||
delete_scada_data(p, ChangeSet({'device_id': 'sm_device', 'time': '2023-02-11 00:02:22'}))
|
||||
sa = get_scada_data(p, 'sm_device')
|
||||
assert sa['device_id'] == 'sm_device'
|
||||
assert len(sa['data']) == 2
|
||||
assert sa['data'][0]['time'] == '2023-02-10 00:02:22'
|
||||
assert sa['data'][0]['value'] == 100.0
|
||||
assert sa['data'][1]['time'] == '2023-02-10 00:03:22'
|
||||
assert sa['data'][1]['value'] == 200.0
|
||||
|
||||
set_scada_data(p, ChangeSet({'device_id': 'sm_device', 'data': []}))
|
||||
sa = get_scada_data(p, 'sm_device')
|
||||
assert sa['device_id'] == 'sm_device'
|
||||
@@ -3940,6 +3991,51 @@ class TestApi:
|
||||
assert cs['data'][1]['time'] == '2023-02-10 00:03:22'
|
||||
assert cs['data'][1]['value'] == 200.0
|
||||
|
||||
cs = add_scada_data(p, ChangeSet({'device_id': 'sm_device', 'time': '2023-02-10 00:02:22', 'value': 100.0}))
|
||||
assert len(cs.operations) == 0
|
||||
|
||||
cs = add_scada_data(p, ChangeSet({'device_id': 'sm_device', 'time': '2023-02-11 00:02:22', 'value': 100.0})).operations[0]
|
||||
assert cs['operation'] == API_ADD
|
||||
assert cs['type'] == 'scada_data'
|
||||
assert cs['device_id'] == 'sm_device'
|
||||
assert cs['time'] == '2023-02-11 00:02:22'
|
||||
assert cs['value'] == 100.0
|
||||
|
||||
cs = execute_undo(p).operations[0]
|
||||
assert cs['operation'] == API_DELETE
|
||||
assert cs['type'] == 'scada_data'
|
||||
assert cs['device_id'] == 'sm_device'
|
||||
assert cs['time'] == '2023-02-11 00:02:22'
|
||||
|
||||
cs = execute_redo(p).operations[0]
|
||||
assert cs['operation'] == API_ADD
|
||||
assert cs['type'] == 'scada_data'
|
||||
assert cs['device_id'] == 'sm_device'
|
||||
assert cs['time'] == '2023-02-11 00:02:22'
|
||||
assert cs['value'] == 100.0
|
||||
|
||||
cs = delete_scada_data(p, ChangeSet({'device_id': 'sm_device', 'time': '2023-02-12 00:02:22'}))
|
||||
assert len(cs.operations) == 0
|
||||
|
||||
cs = delete_scada_data(p, ChangeSet({'device_id': 'sm_device', 'time': '2023-02-11 00:02:22'})).operations[0]
|
||||
assert cs['operation'] == API_DELETE
|
||||
assert cs['type'] == 'scada_data'
|
||||
assert cs['device_id'] == 'sm_device'
|
||||
assert cs['time'] == '2023-02-11 00:02:22'
|
||||
|
||||
cs = execute_undo(p).operations[0]
|
||||
assert cs['operation'] == API_ADD
|
||||
assert cs['type'] == 'scada_data'
|
||||
assert cs['device_id'] == 'sm_device'
|
||||
assert cs['time'] == '2023-02-11 00:02:22'
|
||||
assert cs['value'] == 100.0
|
||||
|
||||
cs = execute_redo(p).operations[0]
|
||||
assert cs['operation'] == API_DELETE
|
||||
assert cs['type'] == 'scada_data'
|
||||
assert cs['device_id'] == 'sm_device'
|
||||
assert cs['time'] == '2023-02-11 00:02:22'
|
||||
|
||||
cs = set_scada_data(p, ChangeSet({'device_id': 'sm_device', 'data': []})).operations[0]
|
||||
assert cs['operation'] == API_UPDATE
|
||||
assert cs['type'] == 'scada_data'
|
||||
|
||||
12
tjnetwork.py
12
tjnetwork.py
@@ -101,6 +101,9 @@ SCADA_TYPE_QUALITY = api.SCADA_TYPE_QUALITY
|
||||
SCADA_TYPE_LEVEL = api.SCADA_TYPE_LEVEL
|
||||
SCADA_TYPE_FLOW = api.SCADA_TYPE_FLOW
|
||||
|
||||
SCADA_STATUS_ONLINE = api.SCADA_STATUS_ONLINE
|
||||
SCADA_STATUS_OFFLINE = api.SCADA_STATUS_OFFLINE
|
||||
|
||||
|
||||
############################################################
|
||||
# project
|
||||
@@ -190,6 +193,9 @@ def execute_batch_commands(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
def get_restore_operation(name: str) -> int:
|
||||
return api.get_restore_operation(name)
|
||||
|
||||
def set_restore_operation(name: str, operation: int) -> None:
|
||||
return api.set_restore_operation(name, operation)
|
||||
|
||||
|
||||
############################################################
|
||||
# type
|
||||
@@ -764,3 +770,9 @@ def get_scada_data(name: str, device_id: str) -> dict[str, Any]:
|
||||
# time format must be 'YYYY-MM-DD HH:MM:SS'
|
||||
def set_scada_data(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return api.set_scada_data(name, cs)
|
||||
|
||||
def add_scada_data(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return api.add_scada_data(name, cs)
|
||||
|
||||
def delete_scada_data(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return api.delete_scada_data(name, cs)
|
||||
|
||||
Reference in New Issue
Block a user