epyt-flow 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- epyt_flow/EPANET/EPANET/SRC_engines/AUTHORS +28 -0
- epyt_flow/EPANET/EPANET/SRC_engines/LICENSE +21 -0
- epyt_flow/EPANET/EPANET/SRC_engines/Readme_SRC_Engines.txt +18 -0
- epyt_flow/EPANET/EPANET/SRC_engines/enumstxt.h +134 -0
- epyt_flow/EPANET/EPANET/SRC_engines/epanet.c +5578 -0
- epyt_flow/EPANET/EPANET/SRC_engines/epanet2.c +865 -0
- epyt_flow/EPANET/EPANET/SRC_engines/epanet2.def +131 -0
- epyt_flow/EPANET/EPANET/SRC_engines/errors.dat +73 -0
- epyt_flow/EPANET/EPANET/SRC_engines/funcs.h +193 -0
- epyt_flow/EPANET/EPANET/SRC_engines/genmmd.c +1000 -0
- epyt_flow/EPANET/EPANET/SRC_engines/hash.c +177 -0
- epyt_flow/EPANET/EPANET/SRC_engines/hash.h +28 -0
- epyt_flow/EPANET/EPANET/SRC_engines/hydcoeffs.c +1151 -0
- epyt_flow/EPANET/EPANET/SRC_engines/hydraul.c +1117 -0
- epyt_flow/EPANET/EPANET/SRC_engines/hydsolver.c +720 -0
- epyt_flow/EPANET/EPANET/SRC_engines/hydstatus.c +476 -0
- epyt_flow/EPANET/EPANET/SRC_engines/include/epanet2.h +431 -0
- epyt_flow/EPANET/EPANET/SRC_engines/include/epanet2_2.h +1786 -0
- epyt_flow/EPANET/EPANET/SRC_engines/include/epanet2_enums.h +468 -0
- epyt_flow/EPANET/EPANET/SRC_engines/inpfile.c +810 -0
- epyt_flow/EPANET/EPANET/SRC_engines/input1.c +707 -0
- epyt_flow/EPANET/EPANET/SRC_engines/input2.c +864 -0
- epyt_flow/EPANET/EPANET/SRC_engines/input3.c +2170 -0
- epyt_flow/EPANET/EPANET/SRC_engines/main.c +93 -0
- epyt_flow/EPANET/EPANET/SRC_engines/mempool.c +142 -0
- epyt_flow/EPANET/EPANET/SRC_engines/mempool.h +24 -0
- epyt_flow/EPANET/EPANET/SRC_engines/output.c +852 -0
- epyt_flow/EPANET/EPANET/SRC_engines/project.c +1359 -0
- epyt_flow/EPANET/EPANET/SRC_engines/quality.c +685 -0
- epyt_flow/EPANET/EPANET/SRC_engines/qualreact.c +743 -0
- epyt_flow/EPANET/EPANET/SRC_engines/qualroute.c +694 -0
- epyt_flow/EPANET/EPANET/SRC_engines/report.c +1489 -0
- epyt_flow/EPANET/EPANET/SRC_engines/rules.c +1362 -0
- epyt_flow/EPANET/EPANET/SRC_engines/smatrix.c +871 -0
- epyt_flow/EPANET/EPANET/SRC_engines/text.h +497 -0
- epyt_flow/EPANET/EPANET/SRC_engines/types.h +874 -0
- epyt_flow/EPANET/EPANET-MSX/MSX_Updates.txt +53 -0
- epyt_flow/EPANET/EPANET-MSX/Src/dispersion.h +27 -0
- epyt_flow/EPANET/EPANET-MSX/Src/hash.c +107 -0
- epyt_flow/EPANET/EPANET-MSX/Src/hash.h +28 -0
- epyt_flow/EPANET/EPANET-MSX/Src/include/epanetmsx.h +102 -0
- epyt_flow/EPANET/EPANET-MSX/Src/include/epanetmsx_export.h +42 -0
- epyt_flow/EPANET/EPANET-MSX/Src/mathexpr.c +937 -0
- epyt_flow/EPANET/EPANET-MSX/Src/mathexpr.h +39 -0
- epyt_flow/EPANET/EPANET-MSX/Src/mempool.c +204 -0
- epyt_flow/EPANET/EPANET-MSX/Src/mempool.h +24 -0
- epyt_flow/EPANET/EPANET-MSX/Src/msxchem.c +1285 -0
- epyt_flow/EPANET/EPANET-MSX/Src/msxcompiler.c +368 -0
- epyt_flow/EPANET/EPANET-MSX/Src/msxdict.h +42 -0
- epyt_flow/EPANET/EPANET-MSX/Src/msxdispersion.c +586 -0
- epyt_flow/EPANET/EPANET-MSX/Src/msxerr.c +116 -0
- epyt_flow/EPANET/EPANET-MSX/Src/msxfile.c +260 -0
- epyt_flow/EPANET/EPANET-MSX/Src/msxfuncs.c +175 -0
- epyt_flow/EPANET/EPANET-MSX/Src/msxfuncs.h +35 -0
- epyt_flow/EPANET/EPANET-MSX/Src/msxinp.c +1504 -0
- epyt_flow/EPANET/EPANET-MSX/Src/msxout.c +401 -0
- epyt_flow/EPANET/EPANET-MSX/Src/msxproj.c +791 -0
- epyt_flow/EPANET/EPANET-MSX/Src/msxqual.c +2010 -0
- epyt_flow/EPANET/EPANET-MSX/Src/msxrpt.c +400 -0
- epyt_flow/EPANET/EPANET-MSX/Src/msxtank.c +422 -0
- epyt_flow/EPANET/EPANET-MSX/Src/msxtoolkit.c +1164 -0
- epyt_flow/EPANET/EPANET-MSX/Src/msxtypes.h +551 -0
- epyt_flow/EPANET/EPANET-MSX/Src/msxutils.c +524 -0
- epyt_flow/EPANET/EPANET-MSX/Src/msxutils.h +56 -0
- epyt_flow/EPANET/EPANET-MSX/Src/newton.c +158 -0
- epyt_flow/EPANET/EPANET-MSX/Src/newton.h +34 -0
- epyt_flow/EPANET/EPANET-MSX/Src/rk5.c +287 -0
- epyt_flow/EPANET/EPANET-MSX/Src/rk5.h +39 -0
- epyt_flow/EPANET/EPANET-MSX/Src/ros2.c +293 -0
- epyt_flow/EPANET/EPANET-MSX/Src/ros2.h +35 -0
- epyt_flow/EPANET/EPANET-MSX/Src/smatrix.c +816 -0
- epyt_flow/EPANET/EPANET-MSX/Src/smatrix.h +29 -0
- epyt_flow/EPANET/EPANET-MSX/readme.txt +14 -0
- epyt_flow/EPANET/compile.sh +4 -0
- epyt_flow/VERSION +1 -0
- epyt_flow/__init__.py +24 -0
- epyt_flow/data/__init__.py +0 -0
- epyt_flow/data/benchmarks/__init__.py +11 -0
- epyt_flow/data/benchmarks/batadal.py +257 -0
- epyt_flow/data/benchmarks/batadal_data.py +28 -0
- epyt_flow/data/benchmarks/battledim.py +473 -0
- epyt_flow/data/benchmarks/battledim_data.py +51 -0
- epyt_flow/data/benchmarks/gecco_water_quality.py +267 -0
- epyt_flow/data/benchmarks/leakdb.py +592 -0
- epyt_flow/data/benchmarks/leakdb_data.py +18923 -0
- epyt_flow/data/benchmarks/water_usage.py +123 -0
- epyt_flow/data/networks.py +650 -0
- epyt_flow/gym/__init__.py +4 -0
- epyt_flow/gym/control_gyms.py +47 -0
- epyt_flow/gym/scenario_control_env.py +101 -0
- epyt_flow/metrics.py +404 -0
- epyt_flow/models/__init__.py +2 -0
- epyt_flow/models/event_detector.py +31 -0
- epyt_flow/models/sensor_interpolation_detector.py +118 -0
- epyt_flow/rest_api/__init__.py +4 -0
- epyt_flow/rest_api/base_handler.py +70 -0
- epyt_flow/rest_api/res_manager.py +95 -0
- epyt_flow/rest_api/scada_data_handler.py +476 -0
- epyt_flow/rest_api/scenario_handler.py +352 -0
- epyt_flow/rest_api/server.py +106 -0
- epyt_flow/serialization.py +438 -0
- epyt_flow/simulation/__init__.py +5 -0
- epyt_flow/simulation/events/__init__.py +6 -0
- epyt_flow/simulation/events/actuator_events.py +259 -0
- epyt_flow/simulation/events/event.py +81 -0
- epyt_flow/simulation/events/leakages.py +404 -0
- epyt_flow/simulation/events/sensor_faults.py +267 -0
- epyt_flow/simulation/events/sensor_reading_attack.py +185 -0
- epyt_flow/simulation/events/sensor_reading_event.py +170 -0
- epyt_flow/simulation/events/system_event.py +88 -0
- epyt_flow/simulation/parallel_simulation.py +147 -0
- epyt_flow/simulation/scada/__init__.py +3 -0
- epyt_flow/simulation/scada/advanced_control.py +134 -0
- epyt_flow/simulation/scada/scada_data.py +1589 -0
- epyt_flow/simulation/scada/scada_data_export.py +255 -0
- epyt_flow/simulation/scenario_config.py +608 -0
- epyt_flow/simulation/scenario_simulator.py +1897 -0
- epyt_flow/simulation/scenario_visualizer.py +61 -0
- epyt_flow/simulation/sensor_config.py +1289 -0
- epyt_flow/topology.py +290 -0
- epyt_flow/uncertainty/__init__.py +3 -0
- epyt_flow/uncertainty/model_uncertainty.py +302 -0
- epyt_flow/uncertainty/sensor_noise.py +73 -0
- epyt_flow/uncertainty/uncertainties.py +555 -0
- epyt_flow/uncertainty/utils.py +206 -0
- epyt_flow/utils.py +306 -0
- epyt_flow-0.1.0.dist-info/LICENSE +21 -0
- epyt_flow-0.1.0.dist-info/METADATA +139 -0
- epyt_flow-0.1.0.dist-info/RECORD +131 -0
- epyt_flow-0.1.0.dist-info/WHEEL +5 -0
- epyt_flow-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module provides a base handler with some useful methods for all REST API handlers.
|
|
3
|
+
"""
|
|
4
|
+
from typing import Any
|
|
5
|
+
import falcon
|
|
6
|
+
|
|
7
|
+
from ..serialization import my_load_from_json, my_to_json
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class BaseHandler():
|
|
11
|
+
"""
|
|
12
|
+
Base class for all REST API handlers.
|
|
13
|
+
"""
|
|
14
|
+
def send_invalid_resource_id_error(self, resp: falcon.Response) -> None:
|
|
15
|
+
"""
|
|
16
|
+
Sends an error that th given resource ID (e.g. scenario ID, or SCADA data ID) is invalid.
|
|
17
|
+
|
|
18
|
+
Parameters
|
|
19
|
+
----------
|
|
20
|
+
resp : `falcon.Response`
|
|
21
|
+
Response instance.
|
|
22
|
+
"""
|
|
23
|
+
resp.status = falcon.HTTP_BAD_REQUEST
|
|
24
|
+
resp.data = "Invalid resource ID".encode()
|
|
25
|
+
|
|
26
|
+
def send_json_parsing_error(self, resp: falcon.Response) -> None:
|
|
27
|
+
"""
|
|
28
|
+
Sends an error that the JSON parsing failed.
|
|
29
|
+
|
|
30
|
+
Parameters
|
|
31
|
+
----------
|
|
32
|
+
resp : `falcon.Response`
|
|
33
|
+
Response instance.
|
|
34
|
+
"""
|
|
35
|
+
resp.status = falcon.HTTP_BAD_REQUEST
|
|
36
|
+
resp.data = "Failed to parse JSON".encode()
|
|
37
|
+
|
|
38
|
+
def load_json_data_from_request(self, req: falcon.Request) -> Any:
|
|
39
|
+
"""
|
|
40
|
+
Loads/Parses an object from given JSON data.
|
|
41
|
+
|
|
42
|
+
Parameters
|
|
43
|
+
----------
|
|
44
|
+
req : `falcon.Request`
|
|
45
|
+
Request instance.
|
|
46
|
+
|
|
47
|
+
Returns
|
|
48
|
+
-------
|
|
49
|
+
`Any`
|
|
50
|
+
Loaded object.
|
|
51
|
+
"""
|
|
52
|
+
try:
|
|
53
|
+
return my_load_from_json(req.bounded_stream.read())
|
|
54
|
+
except Exception:
|
|
55
|
+
return None
|
|
56
|
+
|
|
57
|
+
def send_json_response(self, resp: falcon.Response, data: Any) -> None:
|
|
58
|
+
"""
|
|
59
|
+
Sends a JSON response.
|
|
60
|
+
|
|
61
|
+
Parameters
|
|
62
|
+
----------
|
|
63
|
+
resp : `falcon.Response`
|
|
64
|
+
Response instance.
|
|
65
|
+
data : `Any`
|
|
66
|
+
Data to be sent.
|
|
67
|
+
"""
|
|
68
|
+
resp.content_type = falcon.MEDIA_JSON
|
|
69
|
+
resp.status = falcon.HTTP_200
|
|
70
|
+
resp.data = my_to_json(data).encode()
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module contains a class for managing recourses such as scenarios or SCADA data.
|
|
3
|
+
"""
|
|
4
|
+
from typing import Any
|
|
5
|
+
import uuid
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ResourceManager():
|
|
9
|
+
"""
|
|
10
|
+
Class implementing a simple resource manager where resources are associated with UUIDs.
|
|
11
|
+
"""
|
|
12
|
+
def __init__(self):
|
|
13
|
+
self.__resources = {}
|
|
14
|
+
|
|
15
|
+
def __create_uuid(self) -> str:
|
|
16
|
+
return str(uuid.uuid4())
|
|
17
|
+
|
|
18
|
+
def validate_uuid(self, item_uuid: str) -> bool:
|
|
19
|
+
"""
|
|
20
|
+
Validates a given UUID -- i.e. checks if there is a resource associated with the given UUID.
|
|
21
|
+
|
|
22
|
+
Parameters
|
|
23
|
+
----------
|
|
24
|
+
item_uuid : `str`
|
|
25
|
+
UUID of the item.
|
|
26
|
+
|
|
27
|
+
Returns
|
|
28
|
+
-------
|
|
29
|
+
`bool`
|
|
30
|
+
True if the given UUID is valid, False otherwise.
|
|
31
|
+
"""
|
|
32
|
+
return item_uuid in self.__resources
|
|
33
|
+
|
|
34
|
+
def create_new_item(self, item: Any) -> str:
|
|
35
|
+
"""
|
|
36
|
+
Adds a new item to the resource manager.
|
|
37
|
+
|
|
38
|
+
Parameters
|
|
39
|
+
----------
|
|
40
|
+
item : `Any`
|
|
41
|
+
Item to be added.
|
|
42
|
+
|
|
43
|
+
Returns
|
|
44
|
+
-------
|
|
45
|
+
`str`
|
|
46
|
+
UUID of the new item.
|
|
47
|
+
"""
|
|
48
|
+
new_item_uuid = self.__create_uuid()
|
|
49
|
+
self.__resources[new_item_uuid] = item
|
|
50
|
+
|
|
51
|
+
return new_item_uuid
|
|
52
|
+
|
|
53
|
+
def get(self, item_uuid: str) -> Any:
|
|
54
|
+
"""
|
|
55
|
+
Gets the item associated with a given UUID.
|
|
56
|
+
|
|
57
|
+
Parameters
|
|
58
|
+
----------
|
|
59
|
+
item_uuid : `str`
|
|
60
|
+
UUID of the item.
|
|
61
|
+
|
|
62
|
+
Returns
|
|
63
|
+
-------
|
|
64
|
+
`Any`
|
|
65
|
+
Resource item.
|
|
66
|
+
"""
|
|
67
|
+
if item_uuid not in self.__resources:
|
|
68
|
+
raise ValueError(f"Invalid UUID '{item_uuid}'")
|
|
69
|
+
|
|
70
|
+
return self.__resources[item_uuid]
|
|
71
|
+
|
|
72
|
+
def close_item(self, item: Any):
|
|
73
|
+
"""
|
|
74
|
+
Closes a given resource item -- i.e. all clean-up logic for an item should be called here.
|
|
75
|
+
|
|
76
|
+
Parameters
|
|
77
|
+
----------
|
|
78
|
+
item : `Any`
|
|
79
|
+
Resource item.
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
def remove(self, item_uuid: str) -> None:
|
|
83
|
+
"""
|
|
84
|
+
Removes the scenario associated with a given UUID
|
|
85
|
+
|
|
86
|
+
Parameters
|
|
87
|
+
----------
|
|
88
|
+
item_uuid : `str`
|
|
89
|
+
UUID of the item.
|
|
90
|
+
"""
|
|
91
|
+
if item_uuid not in self.__resources:
|
|
92
|
+
raise ValueError(f"Invalid UUID '{item_uuid}'")
|
|
93
|
+
|
|
94
|
+
self.close_item(self.__resources[item_uuid])
|
|
95
|
+
del self.__resources[item_uuid]
|
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The module provides all handlers for SCADA data requests.
|
|
3
|
+
"""
|
|
4
|
+
import warnings
|
|
5
|
+
import falcon
|
|
6
|
+
|
|
7
|
+
from .base_handler import BaseHandler
|
|
8
|
+
from .res_manager import ResourceManager
|
|
9
|
+
from ..simulation import SensorConfig, SensorFault
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ScadaDataManager(ResourceManager):
|
|
13
|
+
"""
|
|
14
|
+
Class for managing SCADA data.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ScadaDataBaseHandler(BaseHandler):
|
|
19
|
+
"""
|
|
20
|
+
Base class for all handlers concerning SCADA data.
|
|
21
|
+
|
|
22
|
+
Parameters
|
|
23
|
+
----------
|
|
24
|
+
scada_data_mgr : `~epyt_flow.rest_api.scenario_handler.ScadaDataBaseHandler`
|
|
25
|
+
SCADA data manager.
|
|
26
|
+
"""
|
|
27
|
+
def __init__(self, scada_data_mgr: ScadaDataManager):
|
|
28
|
+
self.scada_data_mgr = scada_data_mgr
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class ScadaDataRemoveHandler(ScadaDataBaseHandler):
|
|
32
|
+
"""
|
|
33
|
+
Class for handling a DELETE request for a given SCADA data instance.
|
|
34
|
+
"""
|
|
35
|
+
def on_delete(self, _, resp: falcon.Response, data_id: str) -> None:
|
|
36
|
+
"""
|
|
37
|
+
Deletes a given SCADA data instance.
|
|
38
|
+
|
|
39
|
+
Parameters
|
|
40
|
+
----------
|
|
41
|
+
resp : `falcon.Response`
|
|
42
|
+
Response instance.
|
|
43
|
+
data_id : `str`
|
|
44
|
+
UUID of the SCADA data instance.
|
|
45
|
+
"""
|
|
46
|
+
try:
|
|
47
|
+
if self.scada_data_mgr.validate_uuid(data_id) is False:
|
|
48
|
+
self.send_invalid_resource_id_error(resp)
|
|
49
|
+
return
|
|
50
|
+
|
|
51
|
+
self.scada_data_mgr.remove(data_id)
|
|
52
|
+
except Exception as ex:
|
|
53
|
+
warnings.warn(str(ex))
|
|
54
|
+
resp.status = falcon.HTTP_INTERNAL_SERVER_ERROR
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class ScadaDataSensorConfigHandler(ScadaDataBaseHandler):
|
|
58
|
+
"""
|
|
59
|
+
Class for handling GET and POST requests for the sensor configuration
|
|
60
|
+
of a given SCADA data instance.
|
|
61
|
+
"""
|
|
62
|
+
def on_get(self, _, resp: falcon.Response, data_id: str) -> None:
|
|
63
|
+
"""
|
|
64
|
+
Gets the sensor configuration of a given SCADA data instance.
|
|
65
|
+
|
|
66
|
+
Parameters
|
|
67
|
+
----------
|
|
68
|
+
resp : `falcon.Response`
|
|
69
|
+
Response instance.
|
|
70
|
+
data_id : `str`
|
|
71
|
+
UUID of the SCADA data.
|
|
72
|
+
"""
|
|
73
|
+
try:
|
|
74
|
+
if self.scada_data_mgr.validate_uuid(data_id) is False:
|
|
75
|
+
self.send_invalid_resource_id_error(resp)
|
|
76
|
+
return
|
|
77
|
+
|
|
78
|
+
my_sensor_config = self.scada_data_mgr.get(data_id).sensor_config
|
|
79
|
+
self.send_json_response(resp, my_sensor_config)
|
|
80
|
+
except Exception as ex:
|
|
81
|
+
warnings.warn(str(ex))
|
|
82
|
+
resp.status = falcon.HTTP_INTERNAL_SERVER_ERROR
|
|
83
|
+
|
|
84
|
+
def on_post(self, req: falcon.Request, resp: falcon.Response, data_id: str) -> None:
|
|
85
|
+
"""
|
|
86
|
+
Sets the sensor configuration of a given SCADA data instance.
|
|
87
|
+
|
|
88
|
+
Parameters
|
|
89
|
+
----------
|
|
90
|
+
req : `falcon.Request`
|
|
91
|
+
Request instance.
|
|
92
|
+
resp : `falcon.Response`
|
|
93
|
+
Response instance.
|
|
94
|
+
data_id : `str`
|
|
95
|
+
UUID of the SCADA data.
|
|
96
|
+
"""
|
|
97
|
+
try:
|
|
98
|
+
if self.scada_data_mgr.validate_uuid(data_id) is False:
|
|
99
|
+
self.send_invalid_resource_id_error(resp)
|
|
100
|
+
return
|
|
101
|
+
|
|
102
|
+
sensor_config = self.load_json_data_from_request(req)
|
|
103
|
+
if not isinstance(sensor_config, SensorConfig):
|
|
104
|
+
self.send_json_parsing_error(resp)
|
|
105
|
+
return
|
|
106
|
+
|
|
107
|
+
self.scada_data_mgr.get(data_id).sensor_config = sensor_config
|
|
108
|
+
except Exception as ex:
|
|
109
|
+
warnings.warn(str(ex))
|
|
110
|
+
resp.status = falcon.HTTP_INTERNAL_SERVER_ERROR
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
class ScadaDataSensorFaultsHandler(ScadaDataBaseHandler):
|
|
114
|
+
"""
|
|
115
|
+
Class for handling GET and POST requests concerning sensor faults in a
|
|
116
|
+
given SCADA data instance.
|
|
117
|
+
"""
|
|
118
|
+
def on_get(self, _, resp: falcon.Response, data_id: str) -> None:
|
|
119
|
+
"""
|
|
120
|
+
Gets all sensor faults of a given SCADA data instance.
|
|
121
|
+
|
|
122
|
+
Parameters
|
|
123
|
+
----------
|
|
124
|
+
resp : `falcon.Response`
|
|
125
|
+
Response instance.
|
|
126
|
+
data_id : `str`
|
|
127
|
+
UUID of the SCADA data.
|
|
128
|
+
"""
|
|
129
|
+
try:
|
|
130
|
+
if self.scada_data_mgr.validate_uuid(data_id) is False:
|
|
131
|
+
self.send_invalid_resource_id_error(resp)
|
|
132
|
+
return
|
|
133
|
+
|
|
134
|
+
sensor_faults = self.scada_data_mgr.get(data_id).sensor_faults
|
|
135
|
+
self.send_json_response(resp, sensor_faults)
|
|
136
|
+
except Exception as ex:
|
|
137
|
+
warnings.warn(str(ex))
|
|
138
|
+
resp.status = falcon.HTTP_INTERNAL_SERVER_ERROR
|
|
139
|
+
|
|
140
|
+
def on_post(self, req: falcon.Request, resp: falcon.Response, data_id: str) -> None:
|
|
141
|
+
"""
|
|
142
|
+
Sets (i.e. overrides) the sensor faults in a given SCADA data instance.
|
|
143
|
+
|
|
144
|
+
Parameters
|
|
145
|
+
----------
|
|
146
|
+
req : `falcon.Request`
|
|
147
|
+
Request instance.
|
|
148
|
+
resp : `falcon.Response`
|
|
149
|
+
Response instance.
|
|
150
|
+
data_id : `str`
|
|
151
|
+
UUID of the SCADA data.
|
|
152
|
+
"""
|
|
153
|
+
try:
|
|
154
|
+
if self.scada_data_mgr.validate_uuid(data_id) is False:
|
|
155
|
+
self.send_invalid_resource_id_error(resp)
|
|
156
|
+
return
|
|
157
|
+
|
|
158
|
+
sensor_faults = self.load_json_data_from_request(req)
|
|
159
|
+
if not isinstance(sensor_faults, list) or \
|
|
160
|
+
any(not isinstance(e, SensorFault) for e in sensor_faults):
|
|
161
|
+
self.send_json_parsing_error(resp)
|
|
162
|
+
return
|
|
163
|
+
|
|
164
|
+
self.scada_data_mgr.get(data_id).sensor_faults = sensor_faults
|
|
165
|
+
except Exception as ex:
|
|
166
|
+
warnings.warn(str(ex))
|
|
167
|
+
resp.status = falcon.HTTP_INTERNAL_SERVER_ERROR
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
class ScadaDataPressuresHandler(ScadaDataBaseHandler):
|
|
171
|
+
"""
|
|
172
|
+
Class for handling GET requests for the pressure sensor readings of a given SCADA data instance.
|
|
173
|
+
"""
|
|
174
|
+
def on_get(self, _, resp: falcon.Response, data_id: str) -> None:
|
|
175
|
+
"""
|
|
176
|
+
Gets the pressure sensor readings of a given SCADA data instance.
|
|
177
|
+
|
|
178
|
+
Parameters
|
|
179
|
+
----------
|
|
180
|
+
resp : `falcon.Response`
|
|
181
|
+
Response instance.
|
|
182
|
+
data_id : `str`
|
|
183
|
+
UUID of the SCADA data.
|
|
184
|
+
"""
|
|
185
|
+
try:
|
|
186
|
+
if self.scada_data_mgr.validate_uuid(data_id) is False:
|
|
187
|
+
self.send_invalid_resource_id_error(resp)
|
|
188
|
+
return
|
|
189
|
+
|
|
190
|
+
data_pressures = self.scada_data_mgr.get(data_id).get_data_pressures().tolist()
|
|
191
|
+
self.send_json_response(resp, data_pressures)
|
|
192
|
+
except Exception as ex:
|
|
193
|
+
warnings.warn(str(ex))
|
|
194
|
+
resp.status = falcon.HTTP_INTERNAL_SERVER_ERROR
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
class ScadaDataFlowsHandler(ScadaDataBaseHandler):
|
|
198
|
+
"""
|
|
199
|
+
Class for handling GET requests for the flow sensor readings of a given SCADA data instance.
|
|
200
|
+
"""
|
|
201
|
+
def on_get(self, _, resp: falcon.Response, data_id: str) -> None:
|
|
202
|
+
"""
|
|
203
|
+
Gets the flow sensor readings of a given SCADA data instance.
|
|
204
|
+
|
|
205
|
+
Parameters
|
|
206
|
+
----------
|
|
207
|
+
resp : `falcon.Response`
|
|
208
|
+
Response instance.
|
|
209
|
+
data_id : `str`
|
|
210
|
+
UUID of the SCADA data.
|
|
211
|
+
"""
|
|
212
|
+
try:
|
|
213
|
+
if self.scada_data_mgr.validate_uuid(data_id) is False:
|
|
214
|
+
self.send_invalid_resource_id_error(resp)
|
|
215
|
+
return
|
|
216
|
+
|
|
217
|
+
data_flows = self.scada_data_mgr.get(data_id).get_data_flows().tolist()
|
|
218
|
+
self.send_json_response(resp, data_flows)
|
|
219
|
+
except Exception as ex:
|
|
220
|
+
warnings.warn(str(ex))
|
|
221
|
+
resp.status = falcon.HTTP_INTERNAL_SERVER_ERROR
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
class ScadaDataDemandsHandler(ScadaDataBaseHandler):
|
|
225
|
+
"""
|
|
226
|
+
Class for handling GET requests for the demand sensor readings of a given SCADA data instance.
|
|
227
|
+
"""
|
|
228
|
+
def on_get(self, _, resp: falcon.Response, data_id: str) -> None:
|
|
229
|
+
"""
|
|
230
|
+
Gets the demand sensor readings of a given SCADA data instance.
|
|
231
|
+
|
|
232
|
+
Parameters
|
|
233
|
+
----------
|
|
234
|
+
resp : `falcon.Response`
|
|
235
|
+
Response instance.
|
|
236
|
+
data_id : `str`
|
|
237
|
+
UUID of the SCADA data.
|
|
238
|
+
"""
|
|
239
|
+
try:
|
|
240
|
+
if self.scada_data_mgr.validate_uuid(data_id) is False:
|
|
241
|
+
self.send_invalid_resource_id_error(resp)
|
|
242
|
+
return
|
|
243
|
+
|
|
244
|
+
data_demands = self.scada_data_mgr.get(data_id).get_data_demands().tolist()
|
|
245
|
+
self.send_json_response(resp, data_demands)
|
|
246
|
+
except Exception as ex:
|
|
247
|
+
warnings.warn(str(ex))
|
|
248
|
+
resp.status = falcon.HTTP_INTERNAL_SERVER_ERROR
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
class ScadaDataValveStatesHandler(ScadaDataBaseHandler):
|
|
252
|
+
"""
|
|
253
|
+
Class for handling GET requests for the valve state sensor readings
|
|
254
|
+
of a given SCADA data instance.
|
|
255
|
+
"""
|
|
256
|
+
def on_get(self, _, resp: falcon.Response, data_id: str) -> None:
|
|
257
|
+
"""
|
|
258
|
+
Gets the valve state sensor readings of a given SCADA data instance.
|
|
259
|
+
|
|
260
|
+
Parameters
|
|
261
|
+
----------
|
|
262
|
+
resp : `falcon.Response`
|
|
263
|
+
Response instance.
|
|
264
|
+
data_id : `str`
|
|
265
|
+
UUID of the SCADA data.
|
|
266
|
+
"""
|
|
267
|
+
try:
|
|
268
|
+
if self.scada_data_mgr.validate_uuid(data_id) is False:
|
|
269
|
+
self.send_invalid_resource_id_error(resp)
|
|
270
|
+
return
|
|
271
|
+
|
|
272
|
+
data_demands = self.scada_data_mgr.get(data_id).get_data_valves_state().tolist()
|
|
273
|
+
self.send_json_response(resp, data_demands)
|
|
274
|
+
except Exception as ex:
|
|
275
|
+
warnings.warn(str(ex))
|
|
276
|
+
resp.status = falcon.HTTP_INTERNAL_SERVER_ERROR
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
class ScadaDataPumpStatesHandler(ScadaDataBaseHandler):
|
|
280
|
+
"""
|
|
281
|
+
Class for handling GET requests for the pump state sensor readings
|
|
282
|
+
of a given SCADA data instance.
|
|
283
|
+
"""
|
|
284
|
+
def on_get(self, _, resp: falcon.Response, data_id: str) -> None:
|
|
285
|
+
"""
|
|
286
|
+
Gets the pump state sensor readings of a given SCADA data instance.
|
|
287
|
+
|
|
288
|
+
Parameters
|
|
289
|
+
----------
|
|
290
|
+
resp : `falcon.Response`
|
|
291
|
+
Response instance.
|
|
292
|
+
data_id : `str`
|
|
293
|
+
UUID of the SCADA data.
|
|
294
|
+
"""
|
|
295
|
+
try:
|
|
296
|
+
if self.scada_data_mgr.validate_uuid(data_id) is False:
|
|
297
|
+
self.send_invalid_resource_id_error(resp)
|
|
298
|
+
return
|
|
299
|
+
|
|
300
|
+
data_demands = self.scada_data_mgr.get(data_id).get_data_pumps_state().tolist()
|
|
301
|
+
self.send_json_response(resp, data_demands)
|
|
302
|
+
except Exception as ex:
|
|
303
|
+
warnings.warn(str(ex))
|
|
304
|
+
resp.status = falcon.HTTP_INTERNAL_SERVER_ERROR
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
class ScadaDataTankVolumesHandler(ScadaDataBaseHandler):
|
|
308
|
+
"""
|
|
309
|
+
Class for handling GET requests for the tank volume sensor readings
|
|
310
|
+
of a given SCADA data instance.
|
|
311
|
+
"""
|
|
312
|
+
def on_get(self, _, resp: falcon.Response, data_id: str) -> None:
|
|
313
|
+
"""
|
|
314
|
+
Gets the tank volume sensor readings of a given SCADA data instance.
|
|
315
|
+
|
|
316
|
+
Parameters
|
|
317
|
+
----------
|
|
318
|
+
resp : `falcon.Response`
|
|
319
|
+
Response instance.
|
|
320
|
+
data_id : `str`
|
|
321
|
+
UUID of the SCADA data.
|
|
322
|
+
"""
|
|
323
|
+
try:
|
|
324
|
+
if self.scada_data_mgr.validate_uuid(data_id) is False:
|
|
325
|
+
self.send_invalid_resource_id_error(resp)
|
|
326
|
+
return
|
|
327
|
+
|
|
328
|
+
data_demands = self.scada_data_mgr.get(data_id).get_data_tanks_water_volume().tolist()
|
|
329
|
+
self.send_json_response(resp, data_demands)
|
|
330
|
+
except Exception as ex:
|
|
331
|
+
warnings.warn(str(ex))
|
|
332
|
+
resp.status = falcon.HTTP_INTERNAL_SERVER_ERROR
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
class ScadaDataNodesQualityHandler(ScadaDataBaseHandler):
|
|
336
|
+
"""
|
|
337
|
+
Class for handling GET requests for the node quality sensor readings
|
|
338
|
+
of a given SCADA data instance.
|
|
339
|
+
"""
|
|
340
|
+
def on_get(self, _, resp: falcon.Response, data_id: str) -> None:
|
|
341
|
+
"""
|
|
342
|
+
Gets the node quality sensor readings of a given SCADA data instance.
|
|
343
|
+
|
|
344
|
+
Parameters
|
|
345
|
+
----------
|
|
346
|
+
resp : `falcon.Response`
|
|
347
|
+
Response instance.
|
|
348
|
+
data_id : `str`
|
|
349
|
+
UUID of the SCADA data.
|
|
350
|
+
"""
|
|
351
|
+
try:
|
|
352
|
+
if self.scada_data_mgr.validate_uuid(data_id) is False:
|
|
353
|
+
self.send_invalid_resource_id_error(resp)
|
|
354
|
+
return
|
|
355
|
+
|
|
356
|
+
data_nodes_quality = self.scada_data_mgr.get(data_id).get_data_nodes_quality().tolist()
|
|
357
|
+
self.send_json_response(resp, data_nodes_quality)
|
|
358
|
+
except Exception as ex:
|
|
359
|
+
warnings.warn(str(ex))
|
|
360
|
+
resp.status = falcon.HTTP_INTERNAL_SERVER_ERROR
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
class ScadaDataLinksQualityHandler(ScadaDataBaseHandler):
|
|
364
|
+
"""
|
|
365
|
+
Class for handling GET requests for the link quality sensor readings
|
|
366
|
+
of a given SCADA data instance.
|
|
367
|
+
"""
|
|
368
|
+
def on_get(self, _, resp: falcon.Response, data_id: str) -> None:
|
|
369
|
+
"""
|
|
370
|
+
Gets the link/pipe quality sensor readings of a given SCADA data instance.
|
|
371
|
+
|
|
372
|
+
Parameters
|
|
373
|
+
----------
|
|
374
|
+
resp : `falcon.Response`
|
|
375
|
+
Response instance.
|
|
376
|
+
data_id : `str`
|
|
377
|
+
UUID of the SCADA data.
|
|
378
|
+
"""
|
|
379
|
+
try:
|
|
380
|
+
if self.scada_data_mgr.validate_uuid(data_id) is False:
|
|
381
|
+
self.send_invalid_resource_id_error(resp)
|
|
382
|
+
return
|
|
383
|
+
|
|
384
|
+
data_links_quality = self.scada_data_mgr.get(data_id).get_data_links_quality().tolist()
|
|
385
|
+
self.send_json_response(resp, data_links_quality)
|
|
386
|
+
except Exception as ex:
|
|
387
|
+
warnings.warn(str(ex))
|
|
388
|
+
resp.status = falcon.HTTP_INTERNAL_SERVER_ERROR
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
class ScadaDataNodeBulkSpeciesHandler(ScadaDataBaseHandler):
|
|
392
|
+
"""
|
|
393
|
+
Class for handling GET requests for the bulk species node concentration sensor readings
|
|
394
|
+
of a given SCADA data instance.
|
|
395
|
+
"""
|
|
396
|
+
def on_get(self, _, resp: falcon.Response, data_id: str) -> None:
|
|
397
|
+
"""
|
|
398
|
+
Gets the bulk species node concentrations sensor readings of a given SCADA data instance.
|
|
399
|
+
|
|
400
|
+
Parameters
|
|
401
|
+
----------
|
|
402
|
+
resp : `falcon.Response`
|
|
403
|
+
Response instance.
|
|
404
|
+
data_id : `str`
|
|
405
|
+
UUID of the SCADA data.
|
|
406
|
+
"""
|
|
407
|
+
try:
|
|
408
|
+
if self.scada_data_mgr.validate_uuid(data_id) is False:
|
|
409
|
+
self.send_invalid_resource_id_error(resp)
|
|
410
|
+
return
|
|
411
|
+
|
|
412
|
+
data_conc = self.scada_data_mgr.get(data_id).\
|
|
413
|
+
get_data_bulk_species_node_concentration().tolist()
|
|
414
|
+
self.send_json_response(resp, data_conc)
|
|
415
|
+
except Exception as ex:
|
|
416
|
+
warnings.warn(str(ex))
|
|
417
|
+
resp.status = falcon.HTTP_INTERNAL_SERVER_ERROR
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
class ScadaDataLinkBulkSpeciesHandler(ScadaDataBaseHandler):
|
|
421
|
+
"""
|
|
422
|
+
Class for handling GET requests for the bulk species link/pipe concentration sensor readings
|
|
423
|
+
of a given SCADA data instance.
|
|
424
|
+
"""
|
|
425
|
+
def on_get(self, _, resp: falcon.Response, data_id: str) -> None:
|
|
426
|
+
"""
|
|
427
|
+
Gets the bulk species link/pipe concentrations sensor readings of a
|
|
428
|
+
given SCADA data instance.
|
|
429
|
+
|
|
430
|
+
Parameters
|
|
431
|
+
----------
|
|
432
|
+
resp : `falcon.Response`
|
|
433
|
+
Response instance.
|
|
434
|
+
data_id : `str`
|
|
435
|
+
UUID of the SCADA data.
|
|
436
|
+
"""
|
|
437
|
+
try:
|
|
438
|
+
if self.scada_data_mgr.validate_uuid(data_id) is False:
|
|
439
|
+
self.send_invalid_resource_id_error(resp)
|
|
440
|
+
return
|
|
441
|
+
|
|
442
|
+
data_conc = self.scada_data_mgr.get(data_id).\
|
|
443
|
+
get_data_bulk_species_link_concentration().tolist()
|
|
444
|
+
self.send_json_response(resp, data_conc)
|
|
445
|
+
except Exception as ex:
|
|
446
|
+
warnings.warn(str(ex))
|
|
447
|
+
resp.status = falcon.HTTP_INTERNAL_SERVER_ERROR
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
class ScadaDataSurfaceSpeciesHandler(ScadaDataBaseHandler):
|
|
451
|
+
"""
|
|
452
|
+
Class for handling GET requests for the surface species concentration sensor readings
|
|
453
|
+
of a given SCADA data instance.
|
|
454
|
+
"""
|
|
455
|
+
def on_get(self, _, resp: falcon.Response, data_id: str) -> None:
|
|
456
|
+
"""
|
|
457
|
+
Gets the surface species concentrations sensor readings of a given SCADA data instance.
|
|
458
|
+
|
|
459
|
+
Parameters
|
|
460
|
+
----------
|
|
461
|
+
resp : `falcon.Response`
|
|
462
|
+
Response instance.
|
|
463
|
+
data_id : `str`
|
|
464
|
+
UUID of the SCADA data.
|
|
465
|
+
"""
|
|
466
|
+
try:
|
|
467
|
+
if self.scada_data_mgr.validate_uuid(data_id) is False:
|
|
468
|
+
self.send_invalid_resource_id_error(resp)
|
|
469
|
+
return
|
|
470
|
+
|
|
471
|
+
data_links_quality = self.scada_data_mgr.get(data_id).\
|
|
472
|
+
get_data_surface_species_concentration().tolist()
|
|
473
|
+
self.send_json_response(resp, data_links_quality)
|
|
474
|
+
except Exception as ex:
|
|
475
|
+
warnings.warn(str(ex))
|
|
476
|
+
resp.status = falcon.HTTP_INTERNAL_SERVER_ERROR
|