PyAutomationIO 0.0.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.
- automation/__init__.py +46 -0
- automation/alarms/__init__.py +563 -0
- automation/alarms/states.py +192 -0
- automation/alarms/trigger.py +64 -0
- automation/buffer.py +132 -0
- automation/core.py +1775 -0
- automation/dbmodels/__init__.py +23 -0
- automation/dbmodels/alarms.py +524 -0
- automation/dbmodels/core.py +86 -0
- automation/dbmodels/events.py +153 -0
- automation/dbmodels/logs.py +155 -0
- automation/dbmodels/machines.py +181 -0
- automation/dbmodels/opcua.py +81 -0
- automation/dbmodels/opcua_server.py +174 -0
- automation/dbmodels/tags.py +921 -0
- automation/dbmodels/users.py +259 -0
- automation/extensions/__init__.py +15 -0
- automation/extensions/api.py +149 -0
- automation/extensions/cors.py +18 -0
- automation/filter/__init__.py +19 -0
- automation/iad/__init__.py +3 -0
- automation/iad/frozen_data.py +54 -0
- automation/iad/out_of_range.py +51 -0
- automation/iad/outliers.py +51 -0
- automation/logger/__init__.py +0 -0
- automation/logger/alarms.py +426 -0
- automation/logger/core.py +265 -0
- automation/logger/datalogger.py +646 -0
- automation/logger/events.py +194 -0
- automation/logger/logdict.py +53 -0
- automation/logger/logs.py +203 -0
- automation/logger/machines.py +248 -0
- automation/logger/opcua_server.py +130 -0
- automation/logger/users.py +96 -0
- automation/managers/__init__.py +4 -0
- automation/managers/alarms.py +455 -0
- automation/managers/db.py +328 -0
- automation/managers/opcua_client.py +186 -0
- automation/managers/state_machine.py +183 -0
- automation/models.py +174 -0
- automation/modules/__init__.py +14 -0
- automation/modules/alarms/__init__.py +0 -0
- automation/modules/alarms/resources/__init__.py +10 -0
- automation/modules/alarms/resources/alarms.py +280 -0
- automation/modules/alarms/resources/summary.py +79 -0
- automation/modules/events/__init__.py +0 -0
- automation/modules/events/resources/__init__.py +10 -0
- automation/modules/events/resources/events.py +83 -0
- automation/modules/events/resources/logs.py +109 -0
- automation/modules/tags/__init__.py +0 -0
- automation/modules/tags/resources/__init__.py +8 -0
- automation/modules/tags/resources/tags.py +201 -0
- automation/modules/users/__init__.py +2 -0
- automation/modules/users/resources/__init__.py +10 -0
- automation/modules/users/resources/models/__init__.py +2 -0
- automation/modules/users/resources/models/roles.py +5 -0
- automation/modules/users/resources/models/users.py +14 -0
- automation/modules/users/resources/roles.py +38 -0
- automation/modules/users/resources/users.py +113 -0
- automation/modules/users/roles.py +121 -0
- automation/modules/users/users.py +335 -0
- automation/opcua/__init__.py +1 -0
- automation/opcua/models.py +541 -0
- automation/opcua/subscription.py +259 -0
- automation/pages/__init__.py +0 -0
- automation/pages/alarms.py +34 -0
- automation/pages/alarms_history.py +21 -0
- automation/pages/assets/styles.css +7 -0
- automation/pages/callbacks/__init__.py +28 -0
- automation/pages/callbacks/alarms.py +218 -0
- automation/pages/callbacks/alarms_summary.py +20 -0
- automation/pages/callbacks/db.py +222 -0
- automation/pages/callbacks/filter.py +238 -0
- automation/pages/callbacks/machines.py +29 -0
- automation/pages/callbacks/machines_detailed.py +581 -0
- automation/pages/callbacks/opcua.py +266 -0
- automation/pages/callbacks/opcua_server.py +244 -0
- automation/pages/callbacks/tags.py +495 -0
- automation/pages/callbacks/trends.py +119 -0
- automation/pages/communications.py +129 -0
- automation/pages/components/__init__.py +123 -0
- automation/pages/components/alarms.py +151 -0
- automation/pages/components/alarms_summary.py +45 -0
- automation/pages/components/database.py +128 -0
- automation/pages/components/gaussian_filter.py +69 -0
- automation/pages/components/machines.py +396 -0
- automation/pages/components/opcua.py +384 -0
- automation/pages/components/opcua_server.py +53 -0
- automation/pages/components/tags.py +253 -0
- automation/pages/components/trends.py +66 -0
- automation/pages/database.py +26 -0
- automation/pages/filter.py +55 -0
- automation/pages/machines.py +20 -0
- automation/pages/machines_detailed.py +41 -0
- automation/pages/main.py +63 -0
- automation/pages/opcua_server.py +28 -0
- automation/pages/tags.py +40 -0
- automation/pages/trends.py +35 -0
- automation/singleton.py +30 -0
- automation/state_machine.py +1672 -0
- automation/tags/__init__.py +2 -0
- automation/tags/cvt.py +1198 -0
- automation/tags/filter.py +55 -0
- automation/tags/tag.py +418 -0
- automation/tests/__init__.py +10 -0
- automation/tests/test_alarms.py +110 -0
- automation/tests/test_core.py +257 -0
- automation/tests/test_unit.py +21 -0
- automation/tests/test_user.py +155 -0
- automation/utils/__init__.py +164 -0
- automation/utils/decorators.py +222 -0
- automation/utils/npw.py +294 -0
- automation/utils/observer.py +21 -0
- automation/utils/units.py +118 -0
- automation/variables/__init__.py +55 -0
- automation/variables/adimentional.py +30 -0
- automation/variables/current.py +71 -0
- automation/variables/density.py +115 -0
- automation/variables/eng_time.py +68 -0
- automation/variables/force.py +90 -0
- automation/variables/length.py +104 -0
- automation/variables/mass.py +80 -0
- automation/variables/mass_flow.py +101 -0
- automation/variables/percentage.py +30 -0
- automation/variables/power.py +113 -0
- automation/variables/pressure.py +93 -0
- automation/variables/temperature.py +168 -0
- automation/variables/volume.py +70 -0
- automation/variables/volumetric_flow.py +100 -0
- automation/workers/__init__.py +2 -0
- automation/workers/logger.py +164 -0
- automation/workers/state_machine.py +207 -0
- automation/workers/worker.py +36 -0
- pyautomationio-0.0.0.dist-info/METADATA +198 -0
- pyautomationio-0.0.0.dist-info/RECORD +138 -0
- pyautomationio-0.0.0.dist-info/WHEEL +5 -0
- pyautomationio-0.0.0.dist-info/licenses/LICENSE +21 -0
- pyautomationio-0.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""pyhades/logger/machines.py
|
|
3
|
+
"""
|
|
4
|
+
from ..dbmodels import OPCUAServer
|
|
5
|
+
from .core import BaseEngine, BaseLogger
|
|
6
|
+
from ..utils.decorators import db_rollback
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class OPCUAServerLogger(BaseLogger):
|
|
10
|
+
|
|
11
|
+
def __init__(self):
|
|
12
|
+
|
|
13
|
+
super(OPCUAServerLogger, self).__init__()
|
|
14
|
+
|
|
15
|
+
@db_rollback
|
|
16
|
+
def create(
|
|
17
|
+
self,
|
|
18
|
+
name:str,
|
|
19
|
+
namespace:str,
|
|
20
|
+
access_type:str="Read"
|
|
21
|
+
):
|
|
22
|
+
r"""
|
|
23
|
+
Documentation here
|
|
24
|
+
"""
|
|
25
|
+
if not self.check_connectivity():
|
|
26
|
+
|
|
27
|
+
return None
|
|
28
|
+
|
|
29
|
+
OPCUAServer.create(
|
|
30
|
+
name=name,
|
|
31
|
+
namespace=namespace,
|
|
32
|
+
access_type=access_type
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
@db_rollback
|
|
36
|
+
def put(
|
|
37
|
+
self,
|
|
38
|
+
namespace:str,
|
|
39
|
+
access_type:str
|
|
40
|
+
):
|
|
41
|
+
|
|
42
|
+
if not self.check_connectivity():
|
|
43
|
+
|
|
44
|
+
return None
|
|
45
|
+
|
|
46
|
+
if access_type:
|
|
47
|
+
|
|
48
|
+
OPCUAServer.update_access_type(namespace=namespace, access_type=access_type)
|
|
49
|
+
|
|
50
|
+
obj = OPCUAServer.read_by_namespace(namespace=namespace)
|
|
51
|
+
|
|
52
|
+
return obj
|
|
53
|
+
|
|
54
|
+
@db_rollback
|
|
55
|
+
def read_all(self):
|
|
56
|
+
if not self.check_connectivity():
|
|
57
|
+
|
|
58
|
+
return list()
|
|
59
|
+
|
|
60
|
+
return OPCUAServer.read_all()
|
|
61
|
+
|
|
62
|
+
@db_rollback
|
|
63
|
+
def read_by_namespace(self, namespace:str):
|
|
64
|
+
if not self.check_connectivity():
|
|
65
|
+
|
|
66
|
+
return list()
|
|
67
|
+
|
|
68
|
+
return OPCUAServer.read_by_namespace(namespace=namespace)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class OPCUAServerLoggerEngine(BaseEngine):
|
|
72
|
+
r"""
|
|
73
|
+
OPCUA Server logger Engine class for Tag thread-safe database logging.
|
|
74
|
+
|
|
75
|
+
"""
|
|
76
|
+
|
|
77
|
+
def __init__(self):
|
|
78
|
+
|
|
79
|
+
super(OPCUAServerLoggerEngine, self).__init__()
|
|
80
|
+
self.logger = OPCUAServerLogger()
|
|
81
|
+
|
|
82
|
+
def create(
|
|
83
|
+
self,
|
|
84
|
+
name:str,
|
|
85
|
+
namespace:str,
|
|
86
|
+
access_type:str="Read"
|
|
87
|
+
):
|
|
88
|
+
|
|
89
|
+
_query = dict()
|
|
90
|
+
_query["action"] = "create"
|
|
91
|
+
_query["parameters"] = dict()
|
|
92
|
+
_query["parameters"]["name"] = name
|
|
93
|
+
_query["parameters"]["namespace"] = namespace
|
|
94
|
+
_query["parameters"]["access_type"] = access_type
|
|
95
|
+
|
|
96
|
+
return self.query(_query)
|
|
97
|
+
|
|
98
|
+
def put(
|
|
99
|
+
self,
|
|
100
|
+
namespace:str,
|
|
101
|
+
access_type:str
|
|
102
|
+
):
|
|
103
|
+
|
|
104
|
+
_query = dict()
|
|
105
|
+
_query["action"] = "put"
|
|
106
|
+
_query["parameters"] = dict()
|
|
107
|
+
_query["parameters"]["namespace"] = namespace
|
|
108
|
+
_query["parameters"]["access_type"] = access_type
|
|
109
|
+
|
|
110
|
+
return self.query(_query)
|
|
111
|
+
|
|
112
|
+
def read_by_namespace(
|
|
113
|
+
self,
|
|
114
|
+
namespace:str
|
|
115
|
+
):
|
|
116
|
+
|
|
117
|
+
_query = dict()
|
|
118
|
+
_query["action"] = "read_by_namespace"
|
|
119
|
+
_query["parameters"] = dict()
|
|
120
|
+
_query["parameters"]["namespace"] = namespace
|
|
121
|
+
|
|
122
|
+
return self.query(_query)
|
|
123
|
+
|
|
124
|
+
def read_all(self):
|
|
125
|
+
|
|
126
|
+
_query = dict()
|
|
127
|
+
_query["action"] = "read_all"
|
|
128
|
+
_query["parameters"] = dict()
|
|
129
|
+
return self.query(_query)
|
|
130
|
+
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""pyhades/logger/users.py
|
|
3
|
+
"""
|
|
4
|
+
from ..modules.users.users import User
|
|
5
|
+
from ..dbmodels import Users, Roles
|
|
6
|
+
from .core import BaseEngine, BaseLogger
|
|
7
|
+
from ..utils.decorators import db_rollback
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class UsersLogger(BaseLogger):
|
|
11
|
+
|
|
12
|
+
def __init__(self):
|
|
13
|
+
|
|
14
|
+
super(UsersLogger, self).__init__()
|
|
15
|
+
|
|
16
|
+
@db_rollback
|
|
17
|
+
def set_role(self, name:str, level:int, identifier:str):
|
|
18
|
+
r"""
|
|
19
|
+
Documentation here
|
|
20
|
+
"""
|
|
21
|
+
return Roles.create(
|
|
22
|
+
name=name,
|
|
23
|
+
level=level,
|
|
24
|
+
identifier=identifier
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
@db_rollback
|
|
28
|
+
def set_user(
|
|
29
|
+
self,
|
|
30
|
+
user:User
|
|
31
|
+
):
|
|
32
|
+
r"""
|
|
33
|
+
Documentation here
|
|
34
|
+
"""
|
|
35
|
+
return Users.create(
|
|
36
|
+
user=user
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
@db_rollback
|
|
40
|
+
def login(
|
|
41
|
+
self,
|
|
42
|
+
password:str,
|
|
43
|
+
username:str="",
|
|
44
|
+
email:str=""
|
|
45
|
+
):
|
|
46
|
+
r"""
|
|
47
|
+
Documentation here
|
|
48
|
+
"""
|
|
49
|
+
return Users.login(
|
|
50
|
+
password=password,
|
|
51
|
+
username=username,
|
|
52
|
+
email=email
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
class UsersLoggerEngine(BaseEngine):
|
|
56
|
+
r"""
|
|
57
|
+
Users logger Engine class for Tag thread-safe database logging.
|
|
58
|
+
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
def __init__(self):
|
|
62
|
+
|
|
63
|
+
super(UsersLoggerEngine, self).__init__()
|
|
64
|
+
self.logger = UsersLogger()
|
|
65
|
+
|
|
66
|
+
def set_role(self, name:str, level:int, identifier:str):
|
|
67
|
+
|
|
68
|
+
_query = dict()
|
|
69
|
+
_query["action"] = "set_role"
|
|
70
|
+
_query["parameters"] = dict()
|
|
71
|
+
_query["parameters"]["name"] = name
|
|
72
|
+
_query["parameters"]["level"] = level
|
|
73
|
+
_query["parameters"]["identifier"] = identifier
|
|
74
|
+
|
|
75
|
+
return self.query(_query)
|
|
76
|
+
|
|
77
|
+
def set_user(self, user:User):
|
|
78
|
+
|
|
79
|
+
_query = dict()
|
|
80
|
+
_query["action"] = "set_user"
|
|
81
|
+
_query["parameters"] = dict()
|
|
82
|
+
_query["parameters"]["user"] = user
|
|
83
|
+
|
|
84
|
+
return self.query(_query)
|
|
85
|
+
|
|
86
|
+
def login(self,password:str, username:str="", email:str=""):
|
|
87
|
+
|
|
88
|
+
_query = dict()
|
|
89
|
+
_query["action"] = "login"
|
|
90
|
+
_query["parameters"] = dict()
|
|
91
|
+
_query["parameters"]["password"] = password
|
|
92
|
+
_query["parameters"]["username"] = username
|
|
93
|
+
_query["parameters"]["email"] = email
|
|
94
|
+
|
|
95
|
+
return self.query(_query)
|
|
96
|
+
|
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""pyhades/managers/alarms.py
|
|
3
|
+
This module implements Alarm Manager.
|
|
4
|
+
"""
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
import queue
|
|
7
|
+
from ..singleton import Singleton
|
|
8
|
+
from ..tags import CVTEngine, TagObserver
|
|
9
|
+
from ..alarms import AlarmState, Alarm
|
|
10
|
+
from ..dbmodels.alarms import AlarmSummary
|
|
11
|
+
from ..modules.users.users import User
|
|
12
|
+
from ..models import FloatType, StringType
|
|
13
|
+
from ..utils.decorators import set_event, logging_error_handler
|
|
14
|
+
from flask_socketio import SocketIO
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class AlarmManager(Singleton):
|
|
18
|
+
r"""
|
|
19
|
+
This class implements all definitions for the Alarm Management System
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
def __init__(self):
|
|
23
|
+
|
|
24
|
+
self._alarms:dict[Alarm] = dict()
|
|
25
|
+
self._tag_queue = queue.Queue()
|
|
26
|
+
self.tag_engine = CVTEngine()
|
|
27
|
+
|
|
28
|
+
def get_queue(self)->queue.Queue:
|
|
29
|
+
r"""
|
|
30
|
+
Documentation here
|
|
31
|
+
"""
|
|
32
|
+
return self._tag_queue
|
|
33
|
+
|
|
34
|
+
@logging_error_handler
|
|
35
|
+
def append_alarm(
|
|
36
|
+
self,
|
|
37
|
+
name:str,
|
|
38
|
+
tag:str,
|
|
39
|
+
type:str="BOOL",
|
|
40
|
+
trigger_value:bool|float=True,
|
|
41
|
+
description:str="",
|
|
42
|
+
identifier:str=None,
|
|
43
|
+
state:str="Normal",
|
|
44
|
+
timestamp:str=None,
|
|
45
|
+
ack_timestamp:str=None,
|
|
46
|
+
user:User=None,
|
|
47
|
+
reload:bool=False,
|
|
48
|
+
sio:SocketIO|None=None
|
|
49
|
+
)->tuple[Alarm, str]:
|
|
50
|
+
r"""
|
|
51
|
+
Append alarm to the Alarm Manager
|
|
52
|
+
|
|
53
|
+
**Paramters**
|
|
54
|
+
|
|
55
|
+
* **alarm**: (Alarm Object)
|
|
56
|
+
|
|
57
|
+
**Returns**
|
|
58
|
+
|
|
59
|
+
* **None**
|
|
60
|
+
"""
|
|
61
|
+
# Check alarm name duplicated
|
|
62
|
+
alarm = self.get_alarm_by_name(name)
|
|
63
|
+
if alarm:
|
|
64
|
+
|
|
65
|
+
return alarm, f"Alarm {name} is already defined"
|
|
66
|
+
|
|
67
|
+
# Check if alarm is associated to same tag with same alarm type
|
|
68
|
+
trigger_value_message = self.__check_trigger_values(name=name, tag=tag, type=type, trigger_value=trigger_value)
|
|
69
|
+
if trigger_value_message:
|
|
70
|
+
|
|
71
|
+
return None, trigger_value_message
|
|
72
|
+
|
|
73
|
+
if timestamp:
|
|
74
|
+
|
|
75
|
+
timestamp = datetime.strptime(timestamp, self.tag_engine.DATETIME_FORMAT)
|
|
76
|
+
|
|
77
|
+
if ack_timestamp:
|
|
78
|
+
|
|
79
|
+
ack_timestamp = datetime.strptime(ack_timestamp, self.tag_engine.DATETIME_FORMAT)
|
|
80
|
+
|
|
81
|
+
alarm = Alarm(
|
|
82
|
+
name=name,
|
|
83
|
+
tag=self.tag_engine.get_tag_by_name(name=tag),
|
|
84
|
+
description=description,
|
|
85
|
+
alarm_type=StringType(type),
|
|
86
|
+
alarm_setpoint=FloatType(trigger_value),
|
|
87
|
+
identifier=identifier,
|
|
88
|
+
state=state,
|
|
89
|
+
timestamp=timestamp,
|
|
90
|
+
ack_timestamp=ack_timestamp,
|
|
91
|
+
user=user,
|
|
92
|
+
reload=reload
|
|
93
|
+
)
|
|
94
|
+
alarm.set_socketio(sio=sio)
|
|
95
|
+
self._alarms[alarm.identifier] = alarm
|
|
96
|
+
|
|
97
|
+
return alarm, f"Alarm creation successful"
|
|
98
|
+
|
|
99
|
+
@logging_error_handler
|
|
100
|
+
def put(
|
|
101
|
+
self,
|
|
102
|
+
id:str,
|
|
103
|
+
name:str=None,
|
|
104
|
+
tag:str=None,
|
|
105
|
+
description:str=None,
|
|
106
|
+
alarm_type:str=None,
|
|
107
|
+
trigger_value:float=None,
|
|
108
|
+
user:User=None
|
|
109
|
+
)->tuple[Alarm, str]:
|
|
110
|
+
r"""
|
|
111
|
+
Updates alarm attributes
|
|
112
|
+
|
|
113
|
+
**Parameters**
|
|
114
|
+
|
|
115
|
+
* **id** (int).
|
|
116
|
+
* **name** (str)[Optional]:
|
|
117
|
+
* **tag** (str)[Optional]:
|
|
118
|
+
* **description** (str)[Optional]:
|
|
119
|
+
* **type** (str)[Optional]:
|
|
120
|
+
* **trigger** (float)[Optional]:
|
|
121
|
+
|
|
122
|
+
**Returns**
|
|
123
|
+
|
|
124
|
+
* **alarm** (dict) Alarm Object jsonable
|
|
125
|
+
"""
|
|
126
|
+
alarm = self.get_alarm(id=id)
|
|
127
|
+
if name:
|
|
128
|
+
|
|
129
|
+
if self.get_alarm_by_name(name=name):
|
|
130
|
+
|
|
131
|
+
return f"Alarm {name} is already defined"
|
|
132
|
+
|
|
133
|
+
# Check if alarm is associated to same tag with same alarm type
|
|
134
|
+
if not tag:
|
|
135
|
+
tag = alarm.tag
|
|
136
|
+
if not alarm_type:
|
|
137
|
+
alarm_type = alarm.alarm_setpoint.type
|
|
138
|
+
if not trigger_value:
|
|
139
|
+
trigger_value = FloatType(alarm.alarm_setpoint.value)
|
|
140
|
+
|
|
141
|
+
trigger_value_message = self.__check_trigger_values(
|
|
142
|
+
name=alarm.name,
|
|
143
|
+
tag=tag,
|
|
144
|
+
type=alarm_type,
|
|
145
|
+
trigger_value=trigger_value
|
|
146
|
+
)
|
|
147
|
+
if trigger_value_message:
|
|
148
|
+
|
|
149
|
+
return None, trigger_value_message
|
|
150
|
+
|
|
151
|
+
alarm, message = alarm.put(
|
|
152
|
+
user=user,
|
|
153
|
+
name=name,
|
|
154
|
+
tag=tag,
|
|
155
|
+
description=description,
|
|
156
|
+
alarm_type=alarm_type,
|
|
157
|
+
trigger_value=trigger_value
|
|
158
|
+
)
|
|
159
|
+
self._alarms[id] = alarm
|
|
160
|
+
|
|
161
|
+
@logging_error_handler
|
|
162
|
+
@set_event(message=f"Deleted", classification="Alarm", priority=3, criticity=5)
|
|
163
|
+
def delete_alarm(self, id:str, user:User=None):
|
|
164
|
+
r"""
|
|
165
|
+
Removes alarm
|
|
166
|
+
|
|
167
|
+
**Paramters**
|
|
168
|
+
|
|
169
|
+
* **id** (int): Alarm ID
|
|
170
|
+
"""
|
|
171
|
+
if id in self._alarms:
|
|
172
|
+
|
|
173
|
+
alarm = self._alarms.pop(id)
|
|
174
|
+
alarm.remove_from_service(user=user)
|
|
175
|
+
|
|
176
|
+
return alarm, f"Alarm: {alarm.name} - Tag: {alarm.tag}"
|
|
177
|
+
|
|
178
|
+
@logging_error_handler
|
|
179
|
+
def get_alarm(self, id:str)->Alarm:
|
|
180
|
+
r"""
|
|
181
|
+
Gets alarm from the Alarm Manager by id
|
|
182
|
+
|
|
183
|
+
**Paramters**
|
|
184
|
+
|
|
185
|
+
* **id**: (int) Alarm ID
|
|
186
|
+
|
|
187
|
+
**Returns**
|
|
188
|
+
|
|
189
|
+
* **alarm** (Alarm Object)
|
|
190
|
+
"""
|
|
191
|
+
|
|
192
|
+
if id in self._alarms:
|
|
193
|
+
|
|
194
|
+
return self._alarms[id]
|
|
195
|
+
|
|
196
|
+
@logging_error_handler
|
|
197
|
+
def get_alarm_by_name(self, name:str)->Alarm:
|
|
198
|
+
r"""
|
|
199
|
+
Gets alarm from the Alarm Manager by name
|
|
200
|
+
|
|
201
|
+
**Paramters**
|
|
202
|
+
|
|
203
|
+
* **name**: (str) Alarm name
|
|
204
|
+
|
|
205
|
+
**Returns**
|
|
206
|
+
|
|
207
|
+
* **alarm** (Alarm Object)
|
|
208
|
+
"""
|
|
209
|
+
for id, alarm in self._alarms.items():
|
|
210
|
+
|
|
211
|
+
if name == alarm.name:
|
|
212
|
+
|
|
213
|
+
return self._alarms[str(id)]
|
|
214
|
+
|
|
215
|
+
@logging_error_handler
|
|
216
|
+
def get_alarms_by_tag(self, tag:str)->dict:
|
|
217
|
+
r"""
|
|
218
|
+
Gets all alarms associated to some tag
|
|
219
|
+
|
|
220
|
+
**Parameters**
|
|
221
|
+
|
|
222
|
+
* **tag**: (str) tag name binded to alarm
|
|
223
|
+
|
|
224
|
+
**Returns**
|
|
225
|
+
|
|
226
|
+
* **alarm** (dict) of alarm objects
|
|
227
|
+
"""
|
|
228
|
+
alarms = dict()
|
|
229
|
+
for id, alarm in self._alarms.items():
|
|
230
|
+
|
|
231
|
+
if tag == alarm.tag:
|
|
232
|
+
|
|
233
|
+
alarms[id] = alarm
|
|
234
|
+
|
|
235
|
+
return alarms
|
|
236
|
+
|
|
237
|
+
@logging_error_handler
|
|
238
|
+
def get_alarm_by_tag(self, tag:str)->list[Alarm]:
|
|
239
|
+
r"""
|
|
240
|
+
Gets alarm associated to some tag
|
|
241
|
+
|
|
242
|
+
**Parameters**
|
|
243
|
+
|
|
244
|
+
* **tag**: (str) tag name binded to alarm
|
|
245
|
+
|
|
246
|
+
**Returns**
|
|
247
|
+
|
|
248
|
+
* **alarm** (list) of alarm objects
|
|
249
|
+
"""
|
|
250
|
+
alarms = list()
|
|
251
|
+
for _, alarm in self._alarms.items():
|
|
252
|
+
|
|
253
|
+
if tag == alarm.tag:
|
|
254
|
+
|
|
255
|
+
alarms.append(alarm)
|
|
256
|
+
|
|
257
|
+
return alarms
|
|
258
|
+
|
|
259
|
+
@logging_error_handler
|
|
260
|
+
def get_alarms(self)->dict:
|
|
261
|
+
r"""
|
|
262
|
+
Gets all alarms
|
|
263
|
+
|
|
264
|
+
**Returns**
|
|
265
|
+
|
|
266
|
+
* **alarms**: (dict) Alarm objects
|
|
267
|
+
"""
|
|
268
|
+
return self._alarms
|
|
269
|
+
|
|
270
|
+
@logging_error_handler
|
|
271
|
+
def get_lasts_active_alarms(self, lasts:int=None)->list:
|
|
272
|
+
r"""
|
|
273
|
+
Documentation here
|
|
274
|
+
"""
|
|
275
|
+
original_list = [alarm.serialize() for _, alarm in self.get_alarms().items()]
|
|
276
|
+
filtered_list = [elem for elem in original_list if elem['state']['alarm_status'].lower()=="active"]
|
|
277
|
+
sorted_list = sorted(filtered_list, key=lambda x: x['timestamp'] if x['timestamp'] else '')
|
|
278
|
+
if lasts:
|
|
279
|
+
|
|
280
|
+
if len(sorted_list)>lasts:
|
|
281
|
+
|
|
282
|
+
sorted_list = sorted_list[0:lasts]
|
|
283
|
+
|
|
284
|
+
return sorted_list
|
|
285
|
+
|
|
286
|
+
@logging_error_handler
|
|
287
|
+
def serialize(self)->list:
|
|
288
|
+
r"""
|
|
289
|
+
Documentation here
|
|
290
|
+
"""
|
|
291
|
+
|
|
292
|
+
return [alarm.serialize() for _, alarm in self._alarms.items()]
|
|
293
|
+
|
|
294
|
+
@logging_error_handler
|
|
295
|
+
def get_tag_alarms(self)->list:
|
|
296
|
+
r"""
|
|
297
|
+
Gets all tag alarms defined
|
|
298
|
+
|
|
299
|
+
**Returns**
|
|
300
|
+
|
|
301
|
+
* **tags_alarms**: (list) alarm tags
|
|
302
|
+
"""
|
|
303
|
+
result = [_alarm.tag_alarm for id, _alarm in self.get_alarms().items()]
|
|
304
|
+
|
|
305
|
+
return result
|
|
306
|
+
|
|
307
|
+
@logging_error_handler
|
|
308
|
+
def tags(self)->list:
|
|
309
|
+
r"""
|
|
310
|
+
Gets all tags variables binded into alarms
|
|
311
|
+
|
|
312
|
+
**Returns**
|
|
313
|
+
|
|
314
|
+
* **tags**: (list)
|
|
315
|
+
"""
|
|
316
|
+
result = set([_alarm.tag for id, _alarm in self.get_alarms().items()])
|
|
317
|
+
|
|
318
|
+
return list(result)
|
|
319
|
+
|
|
320
|
+
@logging_error_handler
|
|
321
|
+
def __check_trigger_values(self, name:str, tag:str, type:str, trigger_value:float)->None|str:
|
|
322
|
+
r"""
|
|
323
|
+
Documentation here
|
|
324
|
+
"""
|
|
325
|
+
alarms = self.get_alarm_by_tag(tag=tag)
|
|
326
|
+
|
|
327
|
+
if alarms:
|
|
328
|
+
|
|
329
|
+
for alarm in alarms:
|
|
330
|
+
|
|
331
|
+
if alarm.name!=name:
|
|
332
|
+
|
|
333
|
+
if type==alarm.alarm_setpoint.type.value:
|
|
334
|
+
|
|
335
|
+
return f"Alarm Type {type} and alarm's tag {tag} duplicated"
|
|
336
|
+
|
|
337
|
+
if type=="LOW-LOW":
|
|
338
|
+
|
|
339
|
+
if trigger_value>=alarm.alarm_setpoint.value:
|
|
340
|
+
|
|
341
|
+
return f"Conflict definition with {alarm.name} in trigger value {trigger_value}>={alarm.alarm_setpoint.value}"
|
|
342
|
+
|
|
343
|
+
if type=="LOW":
|
|
344
|
+
|
|
345
|
+
if alarm.alarm_setpoint.type.value=="LOW-LOW":
|
|
346
|
+
|
|
347
|
+
if trigger_value<=alarm.alarm_setpoint.value:
|
|
348
|
+
|
|
349
|
+
return f"Conflict definition with {alarm.name} in trigger value {trigger_value}>={alarm.alarm_setpoint.value}"
|
|
350
|
+
|
|
351
|
+
else:
|
|
352
|
+
|
|
353
|
+
if trigger_value>=alarm.alarm_setpoint.value:
|
|
354
|
+
|
|
355
|
+
return f"Conflict definition with {alarm.name} in trigger value {trigger_value}>={alarm.alarm_setpoint.value}"
|
|
356
|
+
|
|
357
|
+
if type=="HIGH":
|
|
358
|
+
|
|
359
|
+
if alarm.alarm_setpoint.type.value=="HIGH-HIGH":
|
|
360
|
+
|
|
361
|
+
if trigger_value>=alarm.alarm_setpoint.value:
|
|
362
|
+
|
|
363
|
+
return f"Conflict definition with {alarm.name} in trigger value {trigger_value}<={alarm.alarm_setpoint.value}"
|
|
364
|
+
|
|
365
|
+
else:
|
|
366
|
+
|
|
367
|
+
if trigger_value<=alarm.alarm_setpoint.value:
|
|
368
|
+
|
|
369
|
+
return f"Conflict definition with {alarm.name} in trigger value {trigger_value}<={alarm.alarm_setpoint.value}"
|
|
370
|
+
|
|
371
|
+
if type=="HIGH-HIGH":
|
|
372
|
+
|
|
373
|
+
if trigger_value<=alarm.alarm_setpoint.value:
|
|
374
|
+
|
|
375
|
+
return f"Conflict definition with {alarm.name} in trigger value {trigger_value}<={alarm.alarm_setpoint.value}"
|
|
376
|
+
|
|
377
|
+
@logging_error_handler
|
|
378
|
+
def filter_by(self, **fields):
|
|
379
|
+
r"""
|
|
380
|
+
Documentation here
|
|
381
|
+
"""
|
|
382
|
+
|
|
383
|
+
return AlarmSummary.filter_by(**fields), 200
|
|
384
|
+
|
|
385
|
+
@logging_error_handler
|
|
386
|
+
def get_lasts(self, lasts:int=10):
|
|
387
|
+
r"""
|
|
388
|
+
Documentation here
|
|
389
|
+
"""
|
|
390
|
+
|
|
391
|
+
return AlarmSummary.read_lasts(lasts=lasts), 200
|
|
392
|
+
|
|
393
|
+
@logging_error_handler
|
|
394
|
+
def summary(self)->dict:
|
|
395
|
+
r"""
|
|
396
|
+
Summarizes all Alarm Manager
|
|
397
|
+
|
|
398
|
+
**Returns**
|
|
399
|
+
|
|
400
|
+
* **summary**: (dict)
|
|
401
|
+
"""
|
|
402
|
+
result = dict()
|
|
403
|
+
alarms = [_alarm.name for id, _alarm in self.get_alarms().items()]
|
|
404
|
+
result["length"] = len(alarms)
|
|
405
|
+
result["alarms"] = alarms
|
|
406
|
+
result["alarm_tags"] = self.get_tag_alarms()
|
|
407
|
+
result["tags"] = self.tags()
|
|
408
|
+
|
|
409
|
+
return result
|
|
410
|
+
|
|
411
|
+
@logging_error_handler
|
|
412
|
+
def attach(self, alarm_name:str):
|
|
413
|
+
|
|
414
|
+
def attach_observer(entity):
|
|
415
|
+
|
|
416
|
+
_tag = entity.tag
|
|
417
|
+
|
|
418
|
+
observer = TagObserver(self._tag_queue)
|
|
419
|
+
self.tag_engine.attach(name=_tag, observer=observer)
|
|
420
|
+
|
|
421
|
+
alarm = self.get_alarm_by_name(name=alarm_name)
|
|
422
|
+
attach_observer(alarm)
|
|
423
|
+
|
|
424
|
+
@logging_error_handler
|
|
425
|
+
def execute(self, tag_name:str):
|
|
426
|
+
r"""
|
|
427
|
+
Execute update state value of alarm if the value store in cvt for tag
|
|
428
|
+
reach alarm threshold values
|
|
429
|
+
|
|
430
|
+
**Paramters**
|
|
431
|
+
|
|
432
|
+
* **tag**: (str) Tag in CVT
|
|
433
|
+
"""
|
|
434
|
+
value = self.tag_engine.get_value_by_name(tag_name=tag_name)['value']
|
|
435
|
+
|
|
436
|
+
for _, _alarm in self._alarms.items():
|
|
437
|
+
|
|
438
|
+
if _alarm.state == AlarmState.SHLVD:
|
|
439
|
+
|
|
440
|
+
_now = datetime.now()
|
|
441
|
+
|
|
442
|
+
if _alarm._shelved_until:
|
|
443
|
+
|
|
444
|
+
if _now >= _alarm._shelved_until:
|
|
445
|
+
|
|
446
|
+
_alarm.unshelve()
|
|
447
|
+
continue
|
|
448
|
+
|
|
449
|
+
continue
|
|
450
|
+
|
|
451
|
+
continue
|
|
452
|
+
|
|
453
|
+
if tag_name==_alarm.tag:
|
|
454
|
+
|
|
455
|
+
_alarm.update(value)
|