PyAutomationIO 1.1.1__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 +1792 -0
- automation/dbmodels/__init__.py +23 -0
- automation/dbmodels/alarms.py +549 -0
- automation/dbmodels/core.py +86 -0
- automation/dbmodels/events.py +178 -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 +434 -0
- automation/logger/core.py +265 -0
- automation/logger/datalogger.py +877 -0
- automation/logger/events.py +202 -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 +81 -0
- automation/modules/events/__init__.py +0 -0
- automation/modules/events/resources/__init__.py +10 -0
- automation/modules/events/resources/events.py +85 -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 +254 -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 +1674 -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-1.1.1.dist-info/METADATA +199 -0
- pyautomationio-1.1.1.dist-info/RECORD +138 -0
- pyautomationio-1.1.1.dist-info/WHEEL +5 -0
- pyautomationio-1.1.1.dist-info/licenses/LICENSE +21 -0
- pyautomationio-1.1.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
from ..utils.units import *
|
|
2
|
+
|
|
3
|
+
class MassFlow(EngUnit):
|
|
4
|
+
"""Creates a mass flow object that can store a mass flow value and
|
|
5
|
+
convert between units of mass flow.
|
|
6
|
+
|
|
7
|
+
:param value: [int|float] Engineering value\n
|
|
8
|
+
:param unit: [str] Engineering unit\n
|
|
9
|
+
:return: [MassFlow Object]\n
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
>>> from automation.variables.mass_flow import MassFlow
|
|
13
|
+
>>> mass_flow = MassFlow(value=1.0, unit="kg/hr")
|
|
14
|
+
>>> mass_flow.value
|
|
15
|
+
1.0
|
|
16
|
+
>>> mass_flow.unit
|
|
17
|
+
'kg/hr'
|
|
18
|
+
>>> mass_flow.convert(to_unit="lb/sec")
|
|
19
|
+
0.0006123951727222222
|
|
20
|
+
>>> MassFlow.convert_value(value=1.0, from_unit="kg/hr", to_unit="lb/sec")
|
|
21
|
+
0.0006123951727222222
|
|
22
|
+
>>> MassFlow.convert_values(values=[1.0, 10.0], from_unit="kg/hr", to_unit="lb/sec")
|
|
23
|
+
[0.0006123951727222222, 0.0061239517272222216]
|
|
24
|
+
>>> mass_flow.change_unit(unit="lb/sec")
|
|
25
|
+
0.0006123951727222222
|
|
26
|
+
>>> mass_flow.unit
|
|
27
|
+
'lb/sec'
|
|
28
|
+
>>> mass_flow.get_value()
|
|
29
|
+
[0.0006123951727222222, 'lb/sec']
|
|
30
|
+
>>> print(mass_flow)
|
|
31
|
+
0.0006123951727222222 lb/sec
|
|
32
|
+
>>> mass_flow2 = MassFlow(value=3.0, unit="lb/sec")
|
|
33
|
+
>>> mass_flow_result = mass_flow + mass_flow2
|
|
34
|
+
>>> print(mass_flow_result)
|
|
35
|
+
3.0006123951727224 lb/sec
|
|
36
|
+
>>> mass_flow_result = mass_flow * mass_flow2
|
|
37
|
+
>>> print(mass_flow_result)
|
|
38
|
+
0.0018371855181666666 lb/sec
|
|
39
|
+
>>> mass_flow_result = mass_flow / mass_flow2
|
|
40
|
+
>>> print(mass_flow_result)
|
|
41
|
+
0.00020413172424074073 lb/sec
|
|
42
|
+
>>> mass_flow_result = mass_flow ** mass_flow2
|
|
43
|
+
>>> print(mass_flow_result)
|
|
44
|
+
2.2966524349040475e-10 lb/sec
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
class Units(UnitSerializer):
|
|
51
|
+
kg_day = 'kg/day'
|
|
52
|
+
kg_hr = 'kg/hr'
|
|
53
|
+
kg_min = 'kg/min'
|
|
54
|
+
kg_sec = 'kg/sec'
|
|
55
|
+
g_day = 'g/day'
|
|
56
|
+
g_hr = 'g/hr'
|
|
57
|
+
g_min = 'g/min'
|
|
58
|
+
g_sec = 'g/sec'
|
|
59
|
+
mg_day = 'mg/day'
|
|
60
|
+
mg_hr = 'mg/hr'
|
|
61
|
+
mg_min = 'mg/min'
|
|
62
|
+
mg_sec = 'mg/sec'
|
|
63
|
+
lb_day = 'lb/day'
|
|
64
|
+
lb_hr = 'lb/hr'
|
|
65
|
+
lb_min = 'lb/min'
|
|
66
|
+
lb_sec = 'lb/sec'
|
|
67
|
+
metricTon_day = 'metricTon/day'
|
|
68
|
+
metricTon_hr = 'metricTon/hr'
|
|
69
|
+
metricTon_min = 'metricTon/min'
|
|
70
|
+
metricTon_sec = 'metricTon/sec'
|
|
71
|
+
|
|
72
|
+
conversions = {
|
|
73
|
+
'kg/day' : 1.0,
|
|
74
|
+
'kg/hr' : 1.0 / 24,
|
|
75
|
+
'kg/min' : 1.0 / 24 / 60,
|
|
76
|
+
'kg/sec' : 1.0 / 24 / 60 / 60,
|
|
77
|
+
'g/day' : 1000.0,
|
|
78
|
+
'g/hr' : 1000.0 / 24,
|
|
79
|
+
'g/min' : 1000.0 / 24 / 60,
|
|
80
|
+
'g/sec' : 1000.0 / 24 / 60 / 60,
|
|
81
|
+
'mg/day' : 1000000.0,
|
|
82
|
+
'mg/hr' : 1000000.0 / 24,
|
|
83
|
+
'mg/min' : 1000000.0 / 24 / 60,
|
|
84
|
+
'mg/min' : 1000000.0 / 24 / 60 / 60,
|
|
85
|
+
'metricTon/day' : 1.0 / 1000.0,
|
|
86
|
+
'metricTon/hr' : 1.0 / 1000.0 / 24,
|
|
87
|
+
'metricTon/min' : 1.0 / 1000.0 / 24 / 60,
|
|
88
|
+
'metricTon/sec' : 1.0 / 1000.0 / 24 / 60 / 60,
|
|
89
|
+
'lb/day' : 2.2046226218,
|
|
90
|
+
'lb/hr' : 2.2046226218 / 24,
|
|
91
|
+
'lb/min' : 2.2046226218 / 24 / 60,
|
|
92
|
+
'lb/sec' : 2.2046226218 / 24 / 60 / 60
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
def __init__(self, value, unit):
|
|
96
|
+
|
|
97
|
+
if unit not in MassFlow.Units.list():
|
|
98
|
+
|
|
99
|
+
raise UnitError(f"{unit} value is not allowed for {self.__class__.__name__} object - you can use: {MassFlow.Units.list()}")
|
|
100
|
+
|
|
101
|
+
super(MassFlow, self).__init__(value=value, unit=unit)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from ..utils.units import EngUnit, UnitSerializer, UnitError
|
|
2
|
+
|
|
3
|
+
class Percentage(EngUnit):
|
|
4
|
+
"""Creates a percentage object that can store a percentage value and
|
|
5
|
+
convert between units of percentage.
|
|
6
|
+
|
|
7
|
+
:param value: [int|float] Engineering value\n
|
|
8
|
+
:param unit: [str] Engineering unit\n
|
|
9
|
+
:return: [Length Object]\n
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
class Units(UnitSerializer):
|
|
16
|
+
percentage = '%'
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
conversions = {
|
|
20
|
+
|
|
21
|
+
'%' : 1.0
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
def __init__(self, value, unit):
|
|
25
|
+
|
|
26
|
+
if unit not in Percentage.Units.list():
|
|
27
|
+
|
|
28
|
+
raise UnitError(f"{unit} value is not allowed for {self.__class__.__name__} object - you can use: {Percentage.Units.list()}")
|
|
29
|
+
|
|
30
|
+
super(Percentage, self).__init__(value=value, unit=unit)
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
from ..utils.units import *
|
|
2
|
+
|
|
3
|
+
class Power(EngUnit):
|
|
4
|
+
"""Creates a power object that can store a power value and
|
|
5
|
+
convert between units of power.
|
|
6
|
+
|
|
7
|
+
:param value: [int|float] Engineering value\n
|
|
8
|
+
:param unit: [str] Engineering unit\n
|
|
9
|
+
:return: [Power Object]\n
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
>>> from automation.variables.power import Power
|
|
13
|
+
>>> power = Power(value=1.0, unit="BTU/hr")
|
|
14
|
+
>>> power.value
|
|
15
|
+
1.0
|
|
16
|
+
>>> power.unit
|
|
17
|
+
'BTU/hr'
|
|
18
|
+
>>> power.convert(to_unit="mW")
|
|
19
|
+
293.0712104427134
|
|
20
|
+
>>> Power.convert_value(value=1.0, from_unit="BTU/hr", to_unit="kCal/sec")
|
|
21
|
+
7.03370905062512e-05
|
|
22
|
+
>>> Power.convert_values(values=[1.0, 10.0], from_unit="BTU/hr", to_unit="kCal/sec")
|
|
23
|
+
[7.03370905062512e-05, 0.0007033709050625121]
|
|
24
|
+
>>> power.change_unit(unit="mW")
|
|
25
|
+
293.0712104427134
|
|
26
|
+
>>> power.unit
|
|
27
|
+
'mW'
|
|
28
|
+
>>> power.get_value()
|
|
29
|
+
[293.0712104427134, 'mW']
|
|
30
|
+
>>> print(power)
|
|
31
|
+
293.0712104427134 mW
|
|
32
|
+
>>> power2 = Power(value=3.0, unit="kCal/sec")
|
|
33
|
+
>>> power_result = power + power2
|
|
34
|
+
>>> print(power_result)
|
|
35
|
+
12500293.071210442 mW
|
|
36
|
+
>>> power_result = power * power2
|
|
37
|
+
>>> print(power_result)
|
|
38
|
+
3663390130.5339174 mW
|
|
39
|
+
>>> power_result = power / power2
|
|
40
|
+
>>> print(power_result)
|
|
41
|
+
2.344569683541707e-05 mW
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
class Units(UnitSerializer):
|
|
47
|
+
kW = 'kW'
|
|
48
|
+
BTU_hr = 'BTU/hr'
|
|
49
|
+
BTU_min = 'BTU/min'
|
|
50
|
+
BTU_sec = 'BTU/sec'
|
|
51
|
+
cal_sec = 'cal/sec'
|
|
52
|
+
cal_min = 'cal/min'
|
|
53
|
+
cal_hr = 'cal/hr'
|
|
54
|
+
erg_sec = 'erg/sec'
|
|
55
|
+
erg_min = 'erg/min'
|
|
56
|
+
erg_hr = 'erg/hr'
|
|
57
|
+
ftlb_sec = 'ftlb/sec'
|
|
58
|
+
GW = 'GW'
|
|
59
|
+
MW = 'MW'
|
|
60
|
+
kCal_sec = 'kCal/sec'
|
|
61
|
+
kCal_min = 'kCal/min'
|
|
62
|
+
kCal_hr = 'kCal/hr'
|
|
63
|
+
mW = 'mW'
|
|
64
|
+
W = 'W'
|
|
65
|
+
VA = 'VA'
|
|
66
|
+
hp_mech = 'hp_mech'
|
|
67
|
+
hp_ele = 'hp_ele'
|
|
68
|
+
hp_metric = 'hp_metric'
|
|
69
|
+
metric_ton_ref = 'metric_ton_ref'
|
|
70
|
+
US_ton_ref = 'US_ton_ref'
|
|
71
|
+
J_sec = 'J/sec'
|
|
72
|
+
J_min = 'J/min'
|
|
73
|
+
J_hr = 'J/hr'
|
|
74
|
+
kgfm_sec = 'kgf-m/sec'
|
|
75
|
+
|
|
76
|
+
conversions = {
|
|
77
|
+
'kW' : 1.0,
|
|
78
|
+
'BTU/hr' : 3412.14,
|
|
79
|
+
'BTU/min' : 56.869,
|
|
80
|
+
'BTU/sec' : 0.94781666666,
|
|
81
|
+
'cal/sec' : 238.85,
|
|
82
|
+
'cal/min' : 238.85 * 60,
|
|
83
|
+
'cal/hr' : 238.85 * 60 * 60,
|
|
84
|
+
'erg/sec' : 10e9,
|
|
85
|
+
'erg/min' : 10e9 * 60,
|
|
86
|
+
'erg/hr' : 10e9 * 60 * 60,
|
|
87
|
+
'ftlb/sec' : 737.56,
|
|
88
|
+
'GW' : 1e-6,
|
|
89
|
+
'MW' : 1e-3,
|
|
90
|
+
'kCal/sec' : 0.24,
|
|
91
|
+
'kCal/min' : 0.24 * 60,
|
|
92
|
+
'kCal/hr' : 0.24 * 60 * 60,
|
|
93
|
+
'mW' : 1e6,
|
|
94
|
+
'W' : 1e3,
|
|
95
|
+
'VA' : 1e3,
|
|
96
|
+
'hp_mech' : 1.3410220888,
|
|
97
|
+
'hp_ele' : 1.3404825737,
|
|
98
|
+
'hp_metric' : 1.359621617304,
|
|
99
|
+
'metric_ton_ref' : 0.259,
|
|
100
|
+
'US_ton_ref' : 0.2843451361,
|
|
101
|
+
'J/sec' : 1000.0,
|
|
102
|
+
'J/min' : 1000.0 * 60,
|
|
103
|
+
'J/hr' : 1000.0 * 60 * 60,
|
|
104
|
+
'kgf-m/sec' : 101.97162129779
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
def __init__(self, value, unit):
|
|
108
|
+
|
|
109
|
+
if unit not in Power.Units.list():
|
|
110
|
+
|
|
111
|
+
raise UnitError(f"{unit} value is not allowed for {self.__class__.__name__} object - you can use: {Power.Units.list()}")
|
|
112
|
+
|
|
113
|
+
super(Power, self).__init__(value=value, unit=unit)
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
from ..utils.units import *
|
|
2
|
+
|
|
3
|
+
class Pressure(EngUnit):
|
|
4
|
+
"""Creates a pressure object that can store a pressure value and
|
|
5
|
+
convert between units of pressure.
|
|
6
|
+
|
|
7
|
+
:param value: [int|float] Engineering value\n
|
|
8
|
+
:param unit: [str] Engineering unit\n
|
|
9
|
+
:return: [Pressure Object]\n
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
>>> from automation.variables.pressure import Pressure
|
|
13
|
+
>>> pressure = Pressure(value=1.0, unit="atm")
|
|
14
|
+
>>> pressure.value
|
|
15
|
+
1.0
|
|
16
|
+
>>> pressure.unit
|
|
17
|
+
'atm'
|
|
18
|
+
>>> pressure.convert(to_unit="psi")
|
|
19
|
+
14.695979321588414
|
|
20
|
+
>>> Pressure.convert_value(value=1.0, from_unit="atm", to_unit="bar")
|
|
21
|
+
1.0132502738308866
|
|
22
|
+
>>> Pressure.convert_values(values=[1.0, 10.0], from_unit="atm", to_unit="bar")
|
|
23
|
+
[1.0132502738308866, 10.132502738308865]
|
|
24
|
+
>>> pressure.change_unit(unit="psi")
|
|
25
|
+
14.695979321588414
|
|
26
|
+
>>> pressure.unit
|
|
27
|
+
'psi'
|
|
28
|
+
>>> pressure.get_value()
|
|
29
|
+
[14.695979321588414, 'psi']
|
|
30
|
+
>>> print(pressure)
|
|
31
|
+
14.695979321588414 psi
|
|
32
|
+
>>> pressure2 = Pressure(value=3.0, unit="bar")
|
|
33
|
+
>>> pressure_result = pressure + pressure2
|
|
34
|
+
>>> print(pressure_result)
|
|
35
|
+
58.20737932158842 psi
|
|
36
|
+
>>> pressure_result = pressure * pressure2
|
|
37
|
+
>>> print(pressure_result)
|
|
38
|
+
639.4426346533621 psi
|
|
39
|
+
>>> pressure_result = pressure / pressure2
|
|
40
|
+
>>> print(pressure_result)
|
|
41
|
+
0.3377500912769622 psi
|
|
42
|
+
>>> pressure_result = pressure ** pressure2
|
|
43
|
+
>>> print(pressure_result)
|
|
44
|
+
6.115644251483115e+50 psi
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
class Units(UnitSerializer):
|
|
51
|
+
bar = 'bar'
|
|
52
|
+
mbar = 'mbar'
|
|
53
|
+
ubar = 'ubar'
|
|
54
|
+
Pa = 'Pa'
|
|
55
|
+
hPa = 'hPa'
|
|
56
|
+
kPa = 'kPa'
|
|
57
|
+
MPa = 'MPa'
|
|
58
|
+
kgcm2 = 'kgcm2'
|
|
59
|
+
atm = 'atm'
|
|
60
|
+
mmHg = 'mmHg'
|
|
61
|
+
mmH2O = 'mmH2O'
|
|
62
|
+
mH2O = 'mH2O'
|
|
63
|
+
psi = 'psi'
|
|
64
|
+
ftH2O = 'ftH2O'
|
|
65
|
+
inH2O = 'inH2O'
|
|
66
|
+
inHg = 'inHg'
|
|
67
|
+
|
|
68
|
+
conversions = {
|
|
69
|
+
'bar' : 1.0,
|
|
70
|
+
'mbar' : 1000.0,
|
|
71
|
+
'ubar' : 1000000.0,
|
|
72
|
+
'Pa' : 100000.0,
|
|
73
|
+
'hPa' : 1000.0,
|
|
74
|
+
'kPa' : 100.0,
|
|
75
|
+
'MPa' : 0.1,
|
|
76
|
+
'kgcm2' : 1.01972,
|
|
77
|
+
'atm' : 0.986923,
|
|
78
|
+
'mmHg' : 750.062,
|
|
79
|
+
'mmH2O' : 10197.162129779,
|
|
80
|
+
'mH2O' : 10.197162129779,
|
|
81
|
+
'psi' : 14.5038,
|
|
82
|
+
'ftH2O' : 33.455256555148,
|
|
83
|
+
'inH2O' : 401.865,
|
|
84
|
+
'inHg' : 29.53
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
def __init__(self, value, unit):
|
|
88
|
+
|
|
89
|
+
if unit not in Pressure.Units.list():
|
|
90
|
+
|
|
91
|
+
raise UnitError(f"{unit} value is not allowed for {self.__class__.__name__} object - you can use: {Pressure.Units.list()}")
|
|
92
|
+
|
|
93
|
+
super(Pressure, self).__init__(value=value, unit=unit)
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
from ..utils.units import EngUnit, UnitSerializer, UnitError
|
|
2
|
+
|
|
3
|
+
class Temperature(EngUnit):
|
|
4
|
+
"""Creates a temperature object that can store a temperature value and
|
|
5
|
+
convert between units of temperature.
|
|
6
|
+
|
|
7
|
+
:param value: [int|float] Engineering value\n
|
|
8
|
+
:param unit: [str] Engineering unit\n
|
|
9
|
+
:return: [Temperature Object]\n
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
>>> from automation.variables.temperature import Temperature
|
|
13
|
+
>>> temperature = Temperature(value=25, unit="C")
|
|
14
|
+
>>> temperature.value
|
|
15
|
+
25
|
|
16
|
+
>>> temperature.unit
|
|
17
|
+
'C'
|
|
18
|
+
>>> temperature.convert(to_unit="F")
|
|
19
|
+
76.99999999999994
|
|
20
|
+
>>> Temperature.convert_value(value=1.0, from_unit="C", to_unit="K")
|
|
21
|
+
274.15
|
|
22
|
+
>>> temperature.change_unit(unit="F")
|
|
23
|
+
76.99999999999994
|
|
24
|
+
>>> temperature.unit
|
|
25
|
+
'F'
|
|
26
|
+
>>> temperature.get_value()
|
|
27
|
+
[76.99999999999994, 'F']
|
|
28
|
+
>>> print(temperature)
|
|
29
|
+
76.99999999999994 F
|
|
30
|
+
>>> temperature2 = Temperature(value=3.0, unit="K")
|
|
31
|
+
>>> temperature_result = temperature + temperature2
|
|
32
|
+
>>> print(temperature_result)
|
|
33
|
+
82.39999999999992 F
|
|
34
|
+
>>> temperature_result = temperature * temperature2
|
|
35
|
+
>>> print(temperature_result)
|
|
36
|
+
894.4499999999999 K
|
|
37
|
+
>>> temperature_result = temperature / temperature2
|
|
38
|
+
>>> print(temperature_result)
|
|
39
|
+
99.38333333333333 K
|
|
40
|
+
>>> temperature_result = temperature ** temperature2
|
|
41
|
+
>>> print(temperature_result)
|
|
42
|
+
26503573.918374993 K
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
class Units(UnitSerializer):
|
|
48
|
+
degKelvin = 'K'
|
|
49
|
+
degCelsius = 'C'
|
|
50
|
+
degRankine = 'R'
|
|
51
|
+
degFarenheit = 'F'
|
|
52
|
+
|
|
53
|
+
# conversions { } is not used to convert the Temperature() class because
|
|
54
|
+
# temperature is not converted with a scalar. See the convert() function below.
|
|
55
|
+
conversions = {
|
|
56
|
+
'K' : 1.0,
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
def __init__(self, value, unit):
|
|
60
|
+
|
|
61
|
+
if unit not in Temperature.Units.list():
|
|
62
|
+
|
|
63
|
+
raise UnitError(f"{unit} value is not allowed for {self.__class__.__name__} object - you can use: {Temperature.Units.list()}")
|
|
64
|
+
|
|
65
|
+
super(Temperature, self).__init__(value=value, unit=unit)
|
|
66
|
+
|
|
67
|
+
def convert(self, to_unit):
|
|
68
|
+
"""
|
|
69
|
+
Converts a temperature value from one unit of measure to another.
|
|
70
|
+
Returns a float value of the temperature in requested units.
|
|
71
|
+
Returns None for incorrect value.
|
|
72
|
+
|
|
73
|
+
Units of Measure
|
|
74
|
+
---------------
|
|
75
|
+
Units of measure entered as a string.
|
|
76
|
+
'K' - Degree Kelvin\n
|
|
77
|
+
'F' - Degree Farenheit\n
|
|
78
|
+
'R' - Degree Rankine\n
|
|
79
|
+
'C' - Degree Celcius
|
|
80
|
+
|
|
81
|
+
Parameters
|
|
82
|
+
---------------
|
|
83
|
+
value : float
|
|
84
|
+
Value of the temperature measurement.\n
|
|
85
|
+
from_unit : str
|
|
86
|
+
Unit of measurement to convert from.\n
|
|
87
|
+
to_unit : str
|
|
88
|
+
Unit of measurement to convert to.
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
temperature_kelvin = 0
|
|
92
|
+
if self.unit.upper() == 'K':
|
|
93
|
+
temperature_kelvin = self.value
|
|
94
|
+
elif self.unit == 'R':
|
|
95
|
+
temperature_kelvin = self.value * 5.0 / 9.0
|
|
96
|
+
elif self.unit == 'C':
|
|
97
|
+
temperature_kelvin = self.value + 273.15
|
|
98
|
+
elif self.unit == 'F':
|
|
99
|
+
temperature_kelvin = (self.value + 459.67) / 9.0 * 5.0
|
|
100
|
+
else:
|
|
101
|
+
return None
|
|
102
|
+
|
|
103
|
+
# Return Value in Required Unit
|
|
104
|
+
if to_unit == 'K':
|
|
105
|
+
return float(temperature_kelvin)
|
|
106
|
+
elif to_unit == 'R':
|
|
107
|
+
return temperature_kelvin * 9.0 / 5.0
|
|
108
|
+
elif to_unit == 'C':
|
|
109
|
+
return temperature_kelvin - 273.15
|
|
110
|
+
elif to_unit == 'F':
|
|
111
|
+
return temperature_kelvin * 9.0 / 5.0 - 459.67
|
|
112
|
+
else:
|
|
113
|
+
return None
|
|
114
|
+
|
|
115
|
+
@classmethod
|
|
116
|
+
def convert_value(cls, value, from_unit:str, to_unit:str):
|
|
117
|
+
|
|
118
|
+
temperature_kelvin = 0
|
|
119
|
+
if from_unit.upper() == 'K':
|
|
120
|
+
temperature_kelvin = value
|
|
121
|
+
elif from_unit.upper() == 'R':
|
|
122
|
+
temperature_kelvin = value * 5.0 / 9.0
|
|
123
|
+
elif from_unit.upper() == 'C':
|
|
124
|
+
temperature_kelvin = value + 273.15
|
|
125
|
+
elif from_unit.upper() == 'F':
|
|
126
|
+
temperature_kelvin = (value + 459.67) / 9.0 * 5.0
|
|
127
|
+
else:
|
|
128
|
+
return None
|
|
129
|
+
|
|
130
|
+
# Return Value in Required Unit
|
|
131
|
+
if to_unit == 'K':
|
|
132
|
+
return float(temperature_kelvin)
|
|
133
|
+
elif to_unit == 'R':
|
|
134
|
+
return temperature_kelvin * 9.0 / 5.0
|
|
135
|
+
elif to_unit == 'C':
|
|
136
|
+
return temperature_kelvin - 273.15
|
|
137
|
+
elif to_unit == 'F':
|
|
138
|
+
return temperature_kelvin * 9.0 / 5.0 - 459.67
|
|
139
|
+
else:
|
|
140
|
+
return None
|
|
141
|
+
|
|
142
|
+
def __add__(self, other):
|
|
143
|
+
self_original_unit = self.unit
|
|
144
|
+
|
|
145
|
+
self.change_unit('K')
|
|
146
|
+
|
|
147
|
+
if other.unit in ('K', 'C'):
|
|
148
|
+
new_value = self.value + other.value
|
|
149
|
+
else:
|
|
150
|
+
new_value = self.value + (other.value * 5.0 / 9.0)
|
|
151
|
+
|
|
152
|
+
new_unit = self.__class__(new_value, 'K')
|
|
153
|
+
new_unit.change_unit(self_original_unit)
|
|
154
|
+
return new_unit
|
|
155
|
+
|
|
156
|
+
def __sub__(self, other):
|
|
157
|
+
self_original_unit = self.unit
|
|
158
|
+
|
|
159
|
+
self.change_unit('K')
|
|
160
|
+
|
|
161
|
+
if other.unit in ('K', 'C'):
|
|
162
|
+
new_value = self.value - other.value
|
|
163
|
+
else:
|
|
164
|
+
new_value = self.value - (other.value * 5.0 / 9.0)
|
|
165
|
+
|
|
166
|
+
new_unit = self.__class__(new_value, 'K')
|
|
167
|
+
new_unit.change_unit(self_original_unit)
|
|
168
|
+
return new_unit
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from ..utils.units import *
|
|
2
|
+
|
|
3
|
+
class Volume(EngUnit):
|
|
4
|
+
"""Creates a flow object that can store a flow value and
|
|
5
|
+
convert between units of flow.
|
|
6
|
+
|
|
7
|
+
:param value: [int|float] Engineering value\n
|
|
8
|
+
:param unit: [str] Engineering unit\n
|
|
9
|
+
:return: [Volume Object]\n
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
>>> from automation.variables.volume import Volume
|
|
13
|
+
>>> volume = Volume(value=1.0, unit="bbl")
|
|
14
|
+
>>> volume.value
|
|
15
|
+
1.0
|
|
16
|
+
>>> volume.unit
|
|
17
|
+
'bbl'
|
|
18
|
+
>>> volume.convert(to_unit="m3")
|
|
19
|
+
0.158987294928
|
|
20
|
+
>>> Volume.convert_value(value=1.0, from_unit="gal", to_unit="bbl")
|
|
21
|
+
0.023809523809523808
|
|
22
|
+
>>> Volume.convert_values(values=[1.0, 10.0], from_unit="gal", to_unit="bbl")
|
|
23
|
+
[0.023809523809523808, 0.23809523809523808]
|
|
24
|
+
>>> volume.change_unit(unit="gal")
|
|
25
|
+
42.0
|
|
26
|
+
>>> volume.unit
|
|
27
|
+
'gal'
|
|
28
|
+
>>> volume.get_value()
|
|
29
|
+
[42.0, 'gal']
|
|
30
|
+
>>> print(volume)
|
|
31
|
+
42.0 gal
|
|
32
|
+
>>> volume2 = Volume(value=120.0, unit="lt")
|
|
33
|
+
>>> volume_result = volume + volume2
|
|
34
|
+
>>> print(volume_result)
|
|
35
|
+
73.7006462829778 gal
|
|
36
|
+
>>> volume_result = volume * volume2
|
|
37
|
+
>>> print(volume_result)
|
|
38
|
+
1331.4271438850678 gal
|
|
39
|
+
>>> volume_result = volume / volume2
|
|
40
|
+
>>> print(volume_result)
|
|
41
|
+
1.3248941244 gal
|
|
42
|
+
>>> volume_result = volume ** volume2
|
|
43
|
+
>>> print(volume_result)
|
|
44
|
+
2.8711215836780378e+51 gal
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
class Units(UnitSerializer):
|
|
50
|
+
bbl = 'bbl'
|
|
51
|
+
gal = 'gal'
|
|
52
|
+
cubic_meter = 'm3'
|
|
53
|
+
liter_sec = 'lt'
|
|
54
|
+
milliliter = 'ml'
|
|
55
|
+
|
|
56
|
+
conversions = {
|
|
57
|
+
'bbl' : 1.0,
|
|
58
|
+
'gal' : 42.0,
|
|
59
|
+
'm3' : 0.158987294928,
|
|
60
|
+
'lt' : 158.987294928,
|
|
61
|
+
'ml' : 158987.294928
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
def __init__(self, value, unit):
|
|
65
|
+
|
|
66
|
+
if unit not in Volume.Units.list():
|
|
67
|
+
|
|
68
|
+
raise UnitError(f"{unit} value is not allowed for {self.__class__.__name__} object - you can use: {Volume.Units.list()}")
|
|
69
|
+
|
|
70
|
+
super(Volume, self).__init__(value=value, unit=unit)
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
from ..utils.units import *
|
|
2
|
+
|
|
3
|
+
class VolumetricFlow(EngUnit):
|
|
4
|
+
"""Creates a flow object that can store a flow value and
|
|
5
|
+
convert between units of flow.
|
|
6
|
+
|
|
7
|
+
:param value: [int|float] Engineering value\n
|
|
8
|
+
:param unit: [str] Engineering unit\n
|
|
9
|
+
:return: [VolumetricFlow Object]\n
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
>>> from automation.variables.volumetric_flow import VolumetricFlow
|
|
13
|
+
>>> volumetric_flow = VolumetricFlow(value=1.0, unit="bbl/sec")
|
|
14
|
+
>>> volumetric_flow.value
|
|
15
|
+
1.0
|
|
16
|
+
>>> volumetric_flow.unit
|
|
17
|
+
'bbl/sec'
|
|
18
|
+
>>> volumetric_flow.convert(to_unit="m3/day")
|
|
19
|
+
13736.5022817792
|
|
20
|
+
>>> VolumetricFlow.convert_value(value=1.0, from_unit="gal/sec", to_unit="bbl/sec")
|
|
21
|
+
0.023809523809523808
|
|
22
|
+
>>> VolumetricFlow.convert_values(values=[1.0, 10.0], from_unit="gal/sec", to_unit="bbl/sec")
|
|
23
|
+
[0.023809523809523808, 0.23809523809523808]
|
|
24
|
+
>>> volumetric_flow.change_unit(unit="gal/sec")
|
|
25
|
+
42.0
|
|
26
|
+
>>> volumetric_flow.unit
|
|
27
|
+
'gal/sec'
|
|
28
|
+
>>> volumetric_flow.get_value()
|
|
29
|
+
[42.0, 'gal/sec']
|
|
30
|
+
>>> print(volumetric_flow)
|
|
31
|
+
42.0 gal/sec
|
|
32
|
+
>>> volumetric_flow2 = VolumetricFlow(value=120.0, unit="gal/min")
|
|
33
|
+
>>> volumetric_flow_result = volumetric_flow + volumetric_flow2
|
|
34
|
+
>>> print(volumetric_flow_result)
|
|
35
|
+
44.0 gal/sec
|
|
36
|
+
>>> volumetric_flow_result = volumetric_flow * volumetric_flow2
|
|
37
|
+
>>> print(volumetric_flow_result)
|
|
38
|
+
84.0 gal/sec
|
|
39
|
+
>>> volumetric_flow_result = volumetric_flow / volumetric_flow2
|
|
40
|
+
>>> print(volumetric_flow_result)
|
|
41
|
+
21.0 gal/sec
|
|
42
|
+
>>> volumetric_flow_result = volumetric_flow ** volumetric_flow2
|
|
43
|
+
>>> print(volumetric_flow_result)
|
|
44
|
+
1764.0 gal/sec
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
class Units(UnitSerializer):
|
|
50
|
+
bbl_day = 'bbl/day'
|
|
51
|
+
bbl_hr = 'bbl/hr'
|
|
52
|
+
bbl_min = 'bbl/min'
|
|
53
|
+
bbl_sec = 'bbl/sec'
|
|
54
|
+
gal_day = 'gal/day'
|
|
55
|
+
gal_hr = 'gal/hr'
|
|
56
|
+
gal_min = 'gal/min'
|
|
57
|
+
gal_sec = 'gal/sec'
|
|
58
|
+
cubic_meter_day = 'm3/day'
|
|
59
|
+
cubic_meter_hr = 'm3/hr'
|
|
60
|
+
cubic_meter_min = 'm3/min'
|
|
61
|
+
cubic_meter_sec = 'm3/sec'
|
|
62
|
+
liter_day = 'lt/day'
|
|
63
|
+
liter_hr = 'lt/hr'
|
|
64
|
+
liter_min = 'lt/min'
|
|
65
|
+
liter_sec = 'lt/sec'
|
|
66
|
+
cubic_centimeter_day = 'cc/day'
|
|
67
|
+
cubic_centimeter_hr = 'cc/hr'
|
|
68
|
+
cubic_centimeter_min = 'cc/min'
|
|
69
|
+
cubic_centimeter_sec = 'cc/sec'
|
|
70
|
+
|
|
71
|
+
conversions = {
|
|
72
|
+
'bbl/day' : 1.0 * 60.0 * 60.0 * 24.0,
|
|
73
|
+
'bbl/hr' : 1.0 * 60 * 60,
|
|
74
|
+
'bbl/min' : 1.0 * 60.0,
|
|
75
|
+
'bbl/sec' : 1.0,
|
|
76
|
+
'gal/day' : 42.0 * 60.0 * 60.0 * 24.0,
|
|
77
|
+
'gal/hr' : 42.0 * 60.0 * 60.0,
|
|
78
|
+
'gal/min' : 42.0 * 60.0,
|
|
79
|
+
'gal/sec' : 42.0,
|
|
80
|
+
'm3/day' : 0.158987294928 * 60 * 60 * 24,
|
|
81
|
+
'm3/hr' : 0.158987294928 * 60 * 60,
|
|
82
|
+
'm3/min' : 0.158987294928 * 60,
|
|
83
|
+
'm3/sec' : 0.158987294928,
|
|
84
|
+
'lt/day' : 158.987294928 * 60 * 60 * 24,
|
|
85
|
+
'lt/hr' : 158.987294928 * 60 * 60,
|
|
86
|
+
'lt/min' : 158.987294928 * 60,
|
|
87
|
+
'lt/sec' : 158.987294928,
|
|
88
|
+
'ml/day' : 158987.294928 * 60 * 60 * 24,
|
|
89
|
+
'ml/hr' : 158987.294928 * 60 * 60,
|
|
90
|
+
'ml/min' : 158987.294928 * 60,
|
|
91
|
+
'ml/sec' : 158987.294928
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
def __init__(self, value, unit):
|
|
95
|
+
|
|
96
|
+
if unit not in VolumetricFlow.Units.list():
|
|
97
|
+
|
|
98
|
+
raise UnitError(f"{unit} value is not allowed for {self.__class__.__name__} object - you can use: {VolumetricFlow.Units.list()}")
|
|
99
|
+
|
|
100
|
+
super(VolumetricFlow, self).__init__(value=value, unit=unit)
|