labfreed 0.0.13__py2.py3-none-any.whl → 0.0.15__py2.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.
Potentially problematic release.
This version of labfreed might be problematic. Click here for more details.
- labfreed/__init__.py +1 -1
- labfreed/parse_pac.py +6 -6
- labfreed-0.0.15.dist-info/METADATA +171 -0
- {labfreed-0.0.13.dist-info → labfreed-0.0.15.dist-info}/RECORD +6 -6
- labfreed-0.0.13.dist-info/METADATA +0 -7
- {labfreed-0.0.13.dist-info → labfreed-0.0.15.dist-info}/WHEEL +0 -0
- {labfreed-0.0.13.dist-info → labfreed-0.0.15.dist-info}/licenses/LICENSE +0 -0
labfreed/__init__.py
CHANGED
labfreed/parse_pac.py
CHANGED
|
@@ -49,7 +49,7 @@ class PACID_With_Extensions(BaseModelWithValidationMessages):
|
|
|
49
49
|
@classmethod
|
|
50
50
|
def deserialize(cls, url, extension_interpreters ):
|
|
51
51
|
parser = PAC_Parser(extension_interpreters)
|
|
52
|
-
return parser.
|
|
52
|
+
return parser.parse(url)
|
|
53
53
|
|
|
54
54
|
|
|
55
55
|
|
|
@@ -87,15 +87,15 @@ class PAC_Parser():
|
|
|
87
87
|
def __init__(self, extension_interpreters:dict[str, Extension]=None):
|
|
88
88
|
self.extension_interpreters = extension_interpreters or {'TREX': TREX, 'N': DisplayNames}
|
|
89
89
|
|
|
90
|
-
def
|
|
90
|
+
def parse(self, pac_url:str) -> PACID_With_Extensions:
|
|
91
91
|
if '*' in pac_url:
|
|
92
92
|
id_str, ext_str = pac_url.split('*', 1)
|
|
93
93
|
else:
|
|
94
94
|
id_str = pac_url
|
|
95
95
|
ext_str = ""
|
|
96
96
|
|
|
97
|
-
pac_id = self.
|
|
98
|
-
extensions = self.
|
|
97
|
+
pac_id = self._parse_pac_id(id_str)
|
|
98
|
+
extensions = self._parse_extensions(ext_str)
|
|
99
99
|
|
|
100
100
|
pac_with_extension = PACID_With_Extensions(pac_id=pac_id, extensions=extensions)
|
|
101
101
|
if not pac_with_extension.is_valid():
|
|
@@ -104,7 +104,7 @@ class PAC_Parser():
|
|
|
104
104
|
return pac_with_extension
|
|
105
105
|
|
|
106
106
|
|
|
107
|
-
def
|
|
107
|
+
def _parse_pac_id(self,id_str:str) -> PACID:
|
|
108
108
|
m = re.match(f'(HTTPS://)?(PAC.)?(?P<issuer>.+?\..+?)/(?P<identifier>.*)', id_str)
|
|
109
109
|
d = m.groupdict()
|
|
110
110
|
|
|
@@ -148,7 +148,7 @@ class PAC_Parser():
|
|
|
148
148
|
|
|
149
149
|
|
|
150
150
|
|
|
151
|
-
def
|
|
151
|
+
def _parse_extensions(self, extensions_str:str|None) -> list[Extension]:
|
|
152
152
|
|
|
153
153
|
extensions = list()
|
|
154
154
|
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: labfreed
|
|
3
|
+
Version: 0.0.15
|
|
4
|
+
Summary: Python implementation of LabFREED building blocks
|
|
5
|
+
Author-email: Reto Thürer <thuerer.r@buchi.com>
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
|
|
10
|
+
# LabFREED for Python
|
|
11
|
+
|
|
12
|
+
[](LICENSE) [](https://pypi.org/project/labfreed/) 
|
|
13
|
+
|
|
14
|
+
<!--
|
|
15
|
+
[](https://github.com/retothuerer/LabFREED/actions/workflows/ci.yml)
|
|
16
|
+
-->
|
|
17
|
+
|
|
18
|
+
This is a Python implementation of [LabFREED](www.labfreed.wega-it.com) building blocks.
|
|
19
|
+
|
|
20
|
+
## Supported Building Blocks
|
|
21
|
+
- PAC-ID
|
|
22
|
+
- PAC-CAT
|
|
23
|
+
- TREX
|
|
24
|
+
- Display Extension
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
You can install LabFREED from [PyPI](https://pypi.org/project/labfreed/) using pip:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install labfreed
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
## Usage Examples
|
|
35
|
+
<!-- BEGIN EXAMPLES -->
|
|
36
|
+
```python
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Parse a simple PAC-ID
|
|
41
|
+
The
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from labfreed.parse_pac import PAC_Parser
|
|
45
|
+
|
|
46
|
+
# Parse the PAC-ID
|
|
47
|
+
pac_str = 'HTTPS://PAC.METTORIUS.COM/-MD/bal500/@1234'
|
|
48
|
+
pac_id = PAC_Parser().parse(pac_str).pac_id
|
|
49
|
+
|
|
50
|
+
# Check validity of this PAC-ID
|
|
51
|
+
pac_id = PAC_Parser().parse(pac_str).pac_id
|
|
52
|
+
is_valid = pac_id.is_valid()
|
|
53
|
+
print('PAC-ID is valid: {is_valid}')
|
|
54
|
+
# >> PAC-ID is valid: {is_valid}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Show recommendations:
|
|
58
|
+
Note that the PAC-ID, while valid uses characters, which are not recommended (results in larger QR code).
|
|
59
|
+
There is a nice function to highlight problems
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
pac_id.print_validation_messages()
|
|
63
|
+
# >>
|
|
64
|
+
# =======================================
|
|
65
|
+
# Validation Results
|
|
66
|
+
# ---------------------------------------
|
|
67
|
+
|
|
68
|
+
# Recommendation in id segment value bal500
|
|
69
|
+
# HTTPS://PAC.METTORIUS.COM/-MD/bal500/@1234
|
|
70
|
+
# Characters a b l should not be used.
|
|
71
|
+
|
|
72
|
+
# Recommendation in id segment value @1234
|
|
73
|
+
# HTTPS://PAC.METTORIUS.COM/-MD/bal500/@1234
|
|
74
|
+
# Characters @ should not be used.
|
|
75
|
+
|
|
76
|
+
# Warning in Category -MD
|
|
77
|
+
# HTTPS://PAC.METTORIUS.COM/-MD/bal500/@1234
|
|
78
|
+
# Category key -MD is not a well known key. It is recommended to use well known keys only
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Parse a PAC-ID with extensions
|
|
82
|
+
PAC-ID can have extensions. Here we parse a PAC-ID with attached display names and summary.
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
pac_str = 'HTTPS://PAC.METTORIUS.COM/-MD/BAL500/1234*N$N/WM633OV3E5DGJW2BEG0PDM1EA7*SUM$TREX/WEIGHT$GRM:67.89'
|
|
86
|
+
pac_id = PAC_Parser().parse(pac_str)
|
|
87
|
+
|
|
88
|
+
# Display Name
|
|
89
|
+
display_names = pac_id.get_extension('N') # display name has name 'N'
|
|
90
|
+
print(f'\n {display_names}')
|
|
91
|
+
# >> Display names: My Balance ❤️
|
|
92
|
+
|
|
93
|
+
# TREX
|
|
94
|
+
trexes = pac_id.get_extension_of_type('TREX')
|
|
95
|
+
trex = trexes[0] # there could be multiple trexes. In this example there is only one, though
|
|
96
|
+
v = trex.get_segment('WEIGHT').to_python_type()
|
|
97
|
+
print(f'WEIGHT = {v}')
|
|
98
|
+
# >> WEIGHT = 67.89 g
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Create a PAC-ID with Extensions
|
|
102
|
+
|
|
103
|
+
#### Create PAC-ID
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
from labfreed.PAC_ID.data_model import PACID, IDSegment
|
|
107
|
+
from labfreed.utilities.well_known_keys import WellKnownKeys
|
|
108
|
+
|
|
109
|
+
pac_id = PACID(issuer='METTORIUS:COM', identifier=[IDSegment(key=WellKnownKeys.SERIAL, value='1234')])
|
|
110
|
+
pac_str = pac_id.serialize()
|
|
111
|
+
pac_str = pac_id.serialize()
|
|
112
|
+
print(pac_str)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
#### Create a TREX
|
|
116
|
+
TREX can conveniently be created from a python dictionary.
|
|
117
|
+
Note that utility types for Quantity (number with unit) and table are needed
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
from datetime import datetime
|
|
121
|
+
from labfreed.TREX.data_model import TREX
|
|
122
|
+
from labfreed.utilities.utility_types import Quantity, DataTable, Unit
|
|
123
|
+
|
|
124
|
+
# Create TREX
|
|
125
|
+
trex = TREX(name_='DEMO')
|
|
126
|
+
# Add value segments of different type
|
|
127
|
+
trex.update(
|
|
128
|
+
{
|
|
129
|
+
'STOP': datetime(year=2024,month=5,day=5,hour=13,minute=6),
|
|
130
|
+
'TEMP': Quantity(value=10.15, unit=Unit(name='kelvin', symbol='K')),
|
|
131
|
+
'OK':False,
|
|
132
|
+
'COMMENT': 'FOO',
|
|
133
|
+
'COMMENT2':'£'
|
|
134
|
+
}
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
# Create a table
|
|
138
|
+
table = DataTable(['DURATION', 'DATE', 'OK', 'COMMENT'])
|
|
139
|
+
table.append([Quantity(value=1, unit=Unit(symbol='h', name='hour')), datetime.now(), True, 'FOO'])
|
|
140
|
+
table.append([ 1.1, datetime.now(), True, 'BAR'])
|
|
141
|
+
table.append([ 1.3, datetime.now(), False, 'BLUBB'])
|
|
142
|
+
#add the table to the trex
|
|
143
|
+
trex.update({'TABLE': table})
|
|
144
|
+
|
|
145
|
+
# Validation also works the same way for TREX
|
|
146
|
+
if trex.get_nested_validation_messages():
|
|
147
|
+
trex.print_validation_messages()
|
|
148
|
+
|
|
149
|
+
# Side Note: The TREX can be turned back into a dict
|
|
150
|
+
d = trex.dict()
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
#### Combine PAC-ID and TREX and serialize
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
from labfreed.parse_pac import PACID_With_Extensions
|
|
157
|
+
|
|
158
|
+
pac_with_trex = PACID_With_Extensions(pac_id=pac_id, extensions=[trex])
|
|
159
|
+
pac_str = pac_with_trex.serialize()
|
|
160
|
+
print(pac_str)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
<!-- END EXAMPLES -->
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
## Change Log
|
|
168
|
+
|
|
169
|
+
### v0.0.9
|
|
170
|
+
- supports PAC-ID, PAC-CAT, TREX and DisplayName
|
|
171
|
+
- ok-ish test coverage
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
labfreed/__init__.py,sha256=
|
|
2
|
-
labfreed/parse_pac.py,sha256=
|
|
1
|
+
labfreed/__init__.py,sha256=2kxIKF8hbBacIqi0RgHcYqemImSCpb62ejkGUuOMMkY,88
|
|
2
|
+
labfreed/parse_pac.py,sha256=7y65HO1A3OEr5zftiEtrCaiLLI_8LoRPtQpPcKUNVik,6251
|
|
3
3
|
labfreed/validation.py,sha256=QwkZWJhAjWbPUZtJJwjVYsw9TxeFhdbZaKjrPPIpuAA,5937
|
|
4
4
|
labfreed/DisplayNameExtension/DisplayNameExtension.py,sha256=l9JZY2eRS0V-H5h3-WXIHiiBJuljns-_e_t9Bp84_CU,1155
|
|
5
5
|
labfreed/PAC_CAT/__init__.py,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
|
|
@@ -16,7 +16,7 @@ labfreed/utilities/base36.py,sha256=_yX8aQ1OwrK5tnJU1NUEzQSFGr9xAVnNvPObpNzCPYs,
|
|
|
16
16
|
labfreed/utilities/extension_intertpreters.py,sha256=B3IFJLfVMJQuPfBBtX6ywlDUZEi7_x6tY4g8V7SpWSs,124
|
|
17
17
|
labfreed/utilities/utility_types.py,sha256=Zhk8Mu4hHjkn1gs8oh7vOxxaT7L7wLMVG40ZOWCKGK4,2865
|
|
18
18
|
labfreed/utilities/well_known_keys.py,sha256=nqk66kHdSwJTJfMKlP-xQbBglS8F_NoWsGkfOVITFN0,331
|
|
19
|
-
labfreed-0.0.
|
|
20
|
-
labfreed-0.0.
|
|
21
|
-
labfreed-0.0.
|
|
22
|
-
labfreed-0.0.
|
|
19
|
+
labfreed-0.0.15.dist-info/licenses/LICENSE,sha256=gHFOv9FRKHxO8cInP3YXyPoJnuNeqrvcHjaE_wPSsQ8,1100
|
|
20
|
+
labfreed-0.0.15.dist-info/WHEEL,sha256=BXjIu84EnBiZ4HkNUBN93Hamt5EPQMQ6VkF7-VZ_Pu0,100
|
|
21
|
+
labfreed-0.0.15.dist-info/METADATA,sha256=dxqZ7E2CeiqTaYKXuDLn4mxRSv3mH9aqRH96CS2EfFw,4997
|
|
22
|
+
labfreed-0.0.15.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|