labfreed 0.0.14__py2.py3-none-any.whl → 0.0.16__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/PAC_CAT/data_model.py +26 -8
- labfreed/TREX/data_model.py +1 -0
- labfreed/__init__.py +1 -1
- labfreed/parse_pac.py +6 -6
- labfreed-0.0.16.dist-info/METADATA +194 -0
- {labfreed-0.0.14.dist-info → labfreed-0.0.16.dist-info}/RECORD +8 -9
- labfreed/PAC_CAT/data_model copy.py +0 -232
- labfreed-0.0.14.dist-info/METADATA +0 -161
- {labfreed-0.0.14.dist-info → labfreed-0.0.16.dist-info}/WHEEL +0 -0
- {labfreed-0.0.14.dist-info → labfreed-0.0.16.dist-info}/licenses/LICENSE +0 -0
labfreed/PAC_CAT/data_model.py
CHANGED
|
@@ -138,6 +138,19 @@ class PAC_CAT(PACID):
|
|
|
138
138
|
)
|
|
139
139
|
return self
|
|
140
140
|
|
|
141
|
+
def print_categories(self):
|
|
142
|
+
s = ''
|
|
143
|
+
for i, c in enumerate(self.categories):
|
|
144
|
+
if i == 0:
|
|
145
|
+
title = 'Main Category\n----------'
|
|
146
|
+
else:
|
|
147
|
+
title = 'Category\n------ '
|
|
148
|
+
|
|
149
|
+
s += f'{title}\n'
|
|
150
|
+
s += str(c)
|
|
151
|
+
s += '\n'
|
|
152
|
+
print(s)
|
|
153
|
+
|
|
141
154
|
|
|
142
155
|
# @classmethod
|
|
143
156
|
# def from_categories(cls, issuer:str, categories:list[Category]):
|
|
@@ -198,6 +211,11 @@ class Category(BaseModelWithValidationMessages):
|
|
|
198
211
|
return self
|
|
199
212
|
|
|
200
213
|
|
|
214
|
+
def __str__(self):
|
|
215
|
+
s = '\n'.join( [f'{field_name} \t ({field_info.alias or ''}): \t {getattr(self, field_name)}' for field_name, field_info in self.model_fields.items() if getattr(self, field_name)])
|
|
216
|
+
return s
|
|
217
|
+
|
|
218
|
+
|
|
201
219
|
# def to_identifier_category(self, use_short_notation=False):
|
|
202
220
|
# '''Creates a Category with the correct segments.
|
|
203
221
|
# Segments are in order of the Pydantic model fields.
|
|
@@ -261,14 +279,14 @@ class Material_Device(Category):
|
|
|
261
279
|
self.add_validation_message(
|
|
262
280
|
source=f"Category {self.key}",
|
|
263
281
|
type="Error",
|
|
264
|
-
msg=f'Category key {self.key} is missing mandatory field Model
|
|
282
|
+
msg=f'Category key {self.key} is missing mandatory field Model Number',
|
|
265
283
|
highlight_pattern = f"{self.key}"
|
|
266
284
|
)
|
|
267
285
|
if not self.serial_number:
|
|
268
286
|
self.add_validation_message(
|
|
269
287
|
source=f"Category {self.key}",
|
|
270
288
|
type="Error",
|
|
271
|
-
msg=f'Category key {self.key} is missing mandatory field Serial
|
|
289
|
+
msg=f'Category key {self.key} is missing mandatory field Serial Number',
|
|
272
290
|
highlight_pattern = f"{self.key}"
|
|
273
291
|
)
|
|
274
292
|
|
|
@@ -286,7 +304,7 @@ class Material_Substance(Category):
|
|
|
286
304
|
self.add_validation_message(
|
|
287
305
|
source=f"Category {self.key}",
|
|
288
306
|
type="Error",
|
|
289
|
-
msg=f'Category key {self.key} is missing mandatory field Product
|
|
307
|
+
msg=f'Category key {self.key} is missing mandatory field Product Number',
|
|
290
308
|
highlight_pattern = f"{self.key}"
|
|
291
309
|
)
|
|
292
310
|
|
|
@@ -328,19 +346,19 @@ class Data_Abstract(Category, ABC):
|
|
|
328
346
|
highlight_pattern = f"{self.key}"
|
|
329
347
|
)
|
|
330
348
|
|
|
331
|
-
class Data_Result(
|
|
349
|
+
class Data_Result(Data_Abstract):
|
|
332
350
|
key: str = Field(default='-DR', frozen=True)
|
|
333
351
|
|
|
334
|
-
class Data_Method(
|
|
352
|
+
class Data_Method(Data_Abstract):
|
|
335
353
|
key: str = Field(default='-DM', frozen=True)
|
|
336
354
|
|
|
337
|
-
class Data_Calibration(
|
|
355
|
+
class Data_Calibration(Data_Abstract):
|
|
338
356
|
key: str = Field(default='-DC', frozen=True)
|
|
339
357
|
|
|
340
|
-
class Data_Progress(
|
|
358
|
+
class Data_Progress(Data_Abstract):
|
|
341
359
|
key: str = Field(default='-DP', frozen=True)
|
|
342
360
|
|
|
343
|
-
class Data_Static(
|
|
361
|
+
class Data_Static(Data_Abstract):
|
|
344
362
|
key: str = Field(default='-DS', frozen=True)
|
|
345
363
|
|
|
346
364
|
|
labfreed/TREX/data_model.py
CHANGED
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,194 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: labfreed
|
|
3
|
+
Version: 0.0.16
|
|
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
|
+
> ⚠️ **Note:** These examples are building on each other. Imports and parsing are not repeated in each example.
|
|
36
|
+
<!-- BEGIN EXAMPLES -->
|
|
37
|
+
### Parse a simple PAC-ID
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from labfreed.parse_pac import PAC_Parser
|
|
41
|
+
|
|
42
|
+
# Parse the PAC-ID
|
|
43
|
+
pac_str = 'HTTPS://PAC.METTORIUS.COM/-MD/bal500/@1234'
|
|
44
|
+
pac_id = PAC_Parser().parse(pac_str).pac_id
|
|
45
|
+
|
|
46
|
+
# Check validity of this PAC-ID
|
|
47
|
+
pac_id = PAC_Parser().parse(pac_str).pac_id
|
|
48
|
+
is_valid = pac_id.is_valid()
|
|
49
|
+
print('PAC-ID is valid: {is_valid}')
|
|
50
|
+
```
|
|
51
|
+
```text
|
|
52
|
+
>> PAC-ID is valid: {is_valid}
|
|
53
|
+
```
|
|
54
|
+
### Show recommendations:
|
|
55
|
+
Note that the PAC-ID -- while valid -- uses characters which are not recommended (results in larger QR code).
|
|
56
|
+
There is a nice function to highlight problems
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
pac_id.print_validation_messages()
|
|
60
|
+
```
|
|
61
|
+
```text
|
|
62
|
+
>> =======================================
|
|
63
|
+
>> Validation Results
|
|
64
|
+
>> ---------------------------------------
|
|
65
|
+
>>
|
|
66
|
+
>> Recommendation in id segment value bal500
|
|
67
|
+
>> HTTPS://PAC.METTORIUS.COM/-MD/bal500/@1234
|
|
68
|
+
>> Characters a b l should not be used.
|
|
69
|
+
>>
|
|
70
|
+
>> Recommendation in id segment value @1234
|
|
71
|
+
>> HTTPS://PAC.METTORIUS.COM/-MD/bal500/@1234
|
|
72
|
+
>> Characters @ should not be used.
|
|
73
|
+
>>
|
|
74
|
+
>> Warning in Category -MD
|
|
75
|
+
>> HTTPS://PAC.METTORIUS.COM/-MD/bal500/@1234
|
|
76
|
+
>> Category key -MD is not a well known key. It is recommended to use well known keys only
|
|
77
|
+
```
|
|
78
|
+
### PAC-CAT
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
from labfreed.PAC_CAT.data_model import PAC_CAT
|
|
82
|
+
pac_str = 'HTTPS://PAC.METTORIUS.COM/-DR/XQ908756/-MD/bal500/@1234'
|
|
83
|
+
pac_id = PAC_Parser().parse(pac_str).pac_id
|
|
84
|
+
if isinstance(pac_id, PAC_CAT):
|
|
85
|
+
pac_id.print_categories()
|
|
86
|
+
```
|
|
87
|
+
```text
|
|
88
|
+
>> Main Category
|
|
89
|
+
>> ----------
|
|
90
|
+
>> key (): -DR
|
|
91
|
+
>> id (21): XQ908756
|
|
92
|
+
>> Category
|
|
93
|
+
>> ------
|
|
94
|
+
>> key (): -MD
|
|
95
|
+
>> model_number (240): bal500
|
|
96
|
+
>> serial_number (21): @1234
|
|
97
|
+
```
|
|
98
|
+
### Parse a PAC-ID with extensions
|
|
99
|
+
PAC-ID can have extensions. Here we parse a PAC-ID with attached display names and summary.
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
pac_str = 'HTTPS://PAC.METTORIUS.COM/-MD/BAL500/1234*N$N/WM633OV3E5DGJW2BEG0PDM1EA7*SUM$TREX/WEIGHT$GRM:67.89'
|
|
103
|
+
pac_id = PAC_Parser().parse(pac_str)
|
|
104
|
+
|
|
105
|
+
# Display Name
|
|
106
|
+
display_names = pac_id.get_extension('N') # display name has name 'N'
|
|
107
|
+
print(display_names)
|
|
108
|
+
```
|
|
109
|
+
```text
|
|
110
|
+
>> Display names: My Balance ❤️
|
|
111
|
+
```
|
|
112
|
+
```python
|
|
113
|
+
# TREX
|
|
114
|
+
trexes = pac_id.get_extension_of_type('TREX')
|
|
115
|
+
trex = trexes[0] # there could be multiple trexes. In this example there is only one, though
|
|
116
|
+
v = trex.get_segment('WEIGHT').to_python_type()
|
|
117
|
+
print(f'WEIGHT = {v}')
|
|
118
|
+
```
|
|
119
|
+
```text
|
|
120
|
+
>> WEIGHT = 67.89 g
|
|
121
|
+
```
|
|
122
|
+
### Create a PAC-ID with Extensions
|
|
123
|
+
|
|
124
|
+
#### Create PAC-ID
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
from labfreed.PAC_ID.data_model import PACID, IDSegment
|
|
128
|
+
from labfreed.utilities.well_known_keys import WellKnownKeys
|
|
129
|
+
|
|
130
|
+
pac_id = PACID(issuer='METTORIUS:COM', identifier=[IDSegment(key=WellKnownKeys.SERIAL, value='1234')])
|
|
131
|
+
pac_str = pac_id.serialize()
|
|
132
|
+
print(pac_str)
|
|
133
|
+
```
|
|
134
|
+
```text
|
|
135
|
+
>> HTTPS://PAC.METTORIUS:COM/21:1234
|
|
136
|
+
```
|
|
137
|
+
#### Create a TREX
|
|
138
|
+
TREX can conveniently be created from a python dictionary.
|
|
139
|
+
Note that utility types for Quantity (number with unit) and table are needed
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
from datetime import datetime
|
|
143
|
+
from labfreed.TREX.data_model import TREX
|
|
144
|
+
from labfreed.utilities.utility_types import Quantity, DataTable, Unit
|
|
145
|
+
|
|
146
|
+
# Create TREX
|
|
147
|
+
trex = TREX(name_='DEMO')
|
|
148
|
+
# Add value segments of different type
|
|
149
|
+
trex.update(
|
|
150
|
+
{
|
|
151
|
+
'STOP': datetime(year=2024,month=5,day=5,hour=13,minute=6),
|
|
152
|
+
'TEMP': Quantity(value=10.15, unit=Unit(name='kelvin', symbol='K')),
|
|
153
|
+
'OK':False,
|
|
154
|
+
'COMMENT': 'FOO',
|
|
155
|
+
'COMMENT2':'£'
|
|
156
|
+
}
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
# Create a table
|
|
160
|
+
table = DataTable(['DURATION', 'DATE', 'OK', 'COMMENT'])
|
|
161
|
+
table.append([Quantity(value=1, unit=Unit(symbol='h', name='hour')), datetime.now(), True, 'FOO'])
|
|
162
|
+
table.append([ 1.1, datetime.now(), True, 'BAR'])
|
|
163
|
+
table.append([ 1.3, datetime.now(), False, 'BLUBB'])
|
|
164
|
+
#add the table to the trex
|
|
165
|
+
trex.update({'TABLE': table})
|
|
166
|
+
|
|
167
|
+
# Validation also works the same way for TREX
|
|
168
|
+
if trex.get_nested_validation_messages():
|
|
169
|
+
trex.print_validation_messages()
|
|
170
|
+
|
|
171
|
+
# Side Note: The TREX can be turned back into a dict
|
|
172
|
+
d = trex.dict()
|
|
173
|
+
```
|
|
174
|
+
#### Combine PAC-ID and TREX and serialize
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
from labfreed.parse_pac import PACID_With_Extensions
|
|
178
|
+
|
|
179
|
+
pac_with_trex = PACID_With_Extensions(pac_id=pac_id, extensions=[trex])
|
|
180
|
+
pac_str = pac_with_trex.serialize()
|
|
181
|
+
print(pac_str)
|
|
182
|
+
```
|
|
183
|
+
```text
|
|
184
|
+
>> HTTPS://PAC.METTORIUS:COM/21:1234*DEMO$TREX/STOP$T.D:20240505T1306+TEMP$KEL:10.15+OK$T.B:F+COMMENT$T.A:FOO+COMMENT2$T.T:12G3+TABLE$$DURATION$HUR:DATE$T.D:OK$T.B:COMMENT$T.A::1:20250408T204437.738:T:FOO::1.1:20250408T204437.739:T:BAR::1.3:20250408T204437.739:F:BLUBB
|
|
185
|
+
```
|
|
186
|
+
<!-- END EXAMPLES -->
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
## Change Log
|
|
191
|
+
|
|
192
|
+
### v0.0.16
|
|
193
|
+
- supports PAC-ID, PAC-CAT, TREX and DisplayName
|
|
194
|
+
- ok-ish test coverage
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
labfreed/__init__.py,sha256=
|
|
2
|
-
labfreed/parse_pac.py,sha256=
|
|
1
|
+
labfreed/__init__.py,sha256=Bx3Ykihdaac7BJzcEOfffIQE93gFlCOZ5gbFfrusCx8,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
|
|
6
|
-
labfreed/PAC_CAT/data_model
|
|
7
|
-
labfreed/PAC_CAT/data_model.py,sha256=pcib1lEQuqejWP7dfmPUtLakz-y-zeDb9CIe94Jmz0A,13677
|
|
6
|
+
labfreed/PAC_CAT/data_model.py,sha256=dGwcQGLy1Dk6SFbs9utxKQKm_4ROZrXdv618APlQg7M,14308
|
|
8
7
|
labfreed/PAC_ID/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
8
|
labfreed/PAC_ID/data_model.py,sha256=g09qgC-TV6fjJw9VyDF6mTJ6co2i2RKZc0Z-BmiiUIQ,7483
|
|
10
9
|
labfreed/PAC_ID/extensions.py,sha256=bvuZnlNKUdwsDLrPm8fyifqPn_PR4wCVkkScFnvRiuM,1158
|
|
11
10
|
labfreed/TREX/UneceUnits.json,sha256=kwfQSp_nTuWbADfBBgqTWrvPl6XtM5SedEVLbMJrM7M,898953
|
|
12
|
-
labfreed/TREX/data_model.py,sha256=
|
|
11
|
+
labfreed/TREX/data_model.py,sha256=neKYBc5_S4t-v86DSaWLq81VJF4oS6eFUch3ChPTYJA,29705
|
|
13
12
|
labfreed/TREX/parse.py,sha256=86962VEJpkrTcT436iFIB5dNed5WHABzpjxRjkA3PXo,2043
|
|
14
13
|
labfreed/TREX/unece_units.py,sha256=scPKdsPzY1neAdFOhA08_tRZaR-yplM8mBhIzzDqZBk,3006
|
|
15
14
|
labfreed/utilities/base36.py,sha256=_yX8aQ1OwrK5tnJU1NUEzQSFGr9xAVnNvPObpNzCPYs,2895
|
|
16
15
|
labfreed/utilities/extension_intertpreters.py,sha256=B3IFJLfVMJQuPfBBtX6ywlDUZEi7_x6tY4g8V7SpWSs,124
|
|
17
16
|
labfreed/utilities/utility_types.py,sha256=Zhk8Mu4hHjkn1gs8oh7vOxxaT7L7wLMVG40ZOWCKGK4,2865
|
|
18
17
|
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.
|
|
18
|
+
labfreed-0.0.16.dist-info/licenses/LICENSE,sha256=gHFOv9FRKHxO8cInP3YXyPoJnuNeqrvcHjaE_wPSsQ8,1100
|
|
19
|
+
labfreed-0.0.16.dist-info/WHEEL,sha256=BXjIu84EnBiZ4HkNUBN93Hamt5EPQMQ6VkF7-VZ_Pu0,100
|
|
20
|
+
labfreed-0.0.16.dist-info/METADATA,sha256=XNosyku7BkYyTkg7p1gFADu7xRdp7yWQ1VOucTdODck,5883
|
|
21
|
+
labfreed-0.0.16.dist-info/RECORD,,
|
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
# import re
|
|
2
|
-
# from typing import Optional
|
|
3
|
-
# from typing_extensions import Self
|
|
4
|
-
# from pydantic import Field, ValidationInfo, computed_field, conlist, model_validator, field_validator
|
|
5
|
-
|
|
6
|
-
# from abc import ABC, abstractproperty, abstractstaticmethod
|
|
7
|
-
|
|
8
|
-
# from labfreed.PAC_ID.data_model import PACID
|
|
9
|
-
|
|
10
|
-
# from ..utilities.well_known_keys import WellKnownKeys
|
|
11
|
-
# from labfreed.validation import BaseModelWithValidationMessages, ValidationMessage, hsegment_pattern, domain_name_pattern
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
# # class IDSegment(BaseModelWithValidationMessages):
|
|
15
|
-
# # key:str|None = None
|
|
16
|
-
# # value:str
|
|
17
|
-
|
|
18
|
-
# # @model_validator(mode="after")
|
|
19
|
-
# # def validate_segment(self):
|
|
20
|
-
# # key = self.key or ""
|
|
21
|
-
# # value = self.value
|
|
22
|
-
|
|
23
|
-
# # # MUST be a valid hsegment according to RFC 1738, but without * (see PAC-ID Extension)
|
|
24
|
-
# # # This means it must be true for both, key and value
|
|
25
|
-
# # if not_allowed_chars := set(re.sub(hsegment_pattern, '', key)):
|
|
26
|
-
# # self.add_validation_message(
|
|
27
|
-
# # source=f"id segment key {key}",
|
|
28
|
-
# # type="Error",
|
|
29
|
-
# # msg=f"{' '.join(not_allowed_chars)} must not be used.",
|
|
30
|
-
# # recommendation = "The segment key must be a valid hsegment",
|
|
31
|
-
# # highlight_pattern = key,
|
|
32
|
-
# # highlight_sub = not_allowed_chars
|
|
33
|
-
# # )
|
|
34
|
-
|
|
35
|
-
# # if not_allowed_chars := set(re.sub(hsegment_pattern, '', value)):
|
|
36
|
-
# # self.add_validation_message(
|
|
37
|
-
# # source=f"id segment key {value}",
|
|
38
|
-
# # type="Error",
|
|
39
|
-
# # msg=f"{' '.join(not_allowed_chars)} must not be used.",
|
|
40
|
-
# # recommendation = "The segment key must be a valid hsegment",
|
|
41
|
-
# # highlight_pattern = value,
|
|
42
|
-
# # highlight_sub = not_allowed_chars
|
|
43
|
-
# # )
|
|
44
|
-
|
|
45
|
-
# # # Segment key SHOULD be limited to A-Z, 0-9, and -+..
|
|
46
|
-
# # if not_recommended_chars := set(re.sub(r'[A-Z0-9-:+]', '', key)):
|
|
47
|
-
# # self.add_validation_message(
|
|
48
|
-
# # source=f"id segment key {key}",
|
|
49
|
-
# # type="Recommendation",
|
|
50
|
-
# # msg=f"{' '.join(not_recommended_chars)} should not be used.",
|
|
51
|
-
# # recommendation = "SHOULD be limited to A-Z, 0-9, and -+",
|
|
52
|
-
# # highlight_pattern = key,
|
|
53
|
-
# # highlight_sub = not_recommended_chars
|
|
54
|
-
# # )
|
|
55
|
-
|
|
56
|
-
# # # Segment key should be in Well know keys
|
|
57
|
-
# # if key and key not in [k.value for k in WellKnownKeys]:
|
|
58
|
-
# # self.add_validation_message(
|
|
59
|
-
# # source=f"id segment key {key}",
|
|
60
|
-
# # type="Recommendation",
|
|
61
|
-
# # msg=f"{key} is not a well known segment key.",
|
|
62
|
-
# # recommendation = "RECOMMENDED to be a well-known id segment key.",
|
|
63
|
-
# # highlight_pattern = key
|
|
64
|
-
# # )
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
# # # Segment value SHOULD be limited to A-Z, 0-9, and -+..
|
|
68
|
-
# # if not_recommended_chars := set(re.sub(r'[A-Z0-9-:+]', '', value)):
|
|
69
|
-
# # self.add_validation_message(
|
|
70
|
-
# # source=f"id segment value {value}",
|
|
71
|
-
# # type="Recommendation",
|
|
72
|
-
# # msg=f"Characters {' '.join(not_recommended_chars)} should not be used.",
|
|
73
|
-
# # recommendation = "SHOULD be limited to A-Z, 0-9, and -+",
|
|
74
|
-
# # highlight_pattern = value,
|
|
75
|
-
# # highlight_sub = not_recommended_chars
|
|
76
|
-
# # )
|
|
77
|
-
|
|
78
|
-
# # # Segment value SHOULD be limited to A-Z, 0-9, and :-+ for new designs.
|
|
79
|
-
# # # this means that ":" in key or value is problematic
|
|
80
|
-
# # if ':' in key:
|
|
81
|
-
# # self.add_validation_message(
|
|
82
|
-
# # source=f"id segment key {key}",
|
|
83
|
-
# # type="Recommendation",
|
|
84
|
-
# # msg=f"Character ':' should not be used in segment key, since this character is used to separate key and value this can lead to undefined behaviour.",
|
|
85
|
-
# # highlight_pattern = key
|
|
86
|
-
# # )
|
|
87
|
-
# # if ':' in value:
|
|
88
|
-
# # self.add_validation_message(
|
|
89
|
-
# # source=f"id segment value {value}",
|
|
90
|
-
# # type="Recommendation",
|
|
91
|
-
# # msg=f"Character ':' should not be used in segment value, since this character is used to separate key and value this can lead to undefined behaviour.",
|
|
92
|
-
# # highlight_pattern = value
|
|
93
|
-
# # )
|
|
94
|
-
|
|
95
|
-
# # return self
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
# class PAC_CAT(PACID):
|
|
104
|
-
|
|
105
|
-
# @computed_field
|
|
106
|
-
# @property
|
|
107
|
-
# def categories(self) -> list[Category]:
|
|
108
|
-
# categories = list()
|
|
109
|
-
# c = Category(segments=[])
|
|
110
|
-
# categories.append(c)
|
|
111
|
-
# for s in self.segments:
|
|
112
|
-
# # new category starts with "-"
|
|
113
|
-
# if s.value[0] == '-':
|
|
114
|
-
# cat_key = s.value
|
|
115
|
-
# c = Category(key=cat_key, segments=[])
|
|
116
|
-
# categories.append(c)
|
|
117
|
-
# else:
|
|
118
|
-
# c.segments.append(s)
|
|
119
|
-
|
|
120
|
-
# # the first category might have no segments. remove categories without segments
|
|
121
|
-
# if not categories[0].segments:
|
|
122
|
-
# categories = categories[1:]
|
|
123
|
-
|
|
124
|
-
# return categories
|
|
125
|
-
|
|
126
|
-
# @model_validator(mode='after')
|
|
127
|
-
# def check_keys_are_unique_in_each_category(self) -> Self:
|
|
128
|
-
# for c in self.categories:
|
|
129
|
-
# keys = [s.key for s in c.segments if s.key]
|
|
130
|
-
# duplicate_keys = [k for k in set(keys) if keys.count(k) > 1]
|
|
131
|
-
# if duplicate_keys:
|
|
132
|
-
# for k in duplicate_keys:
|
|
133
|
-
# self.add_validation_message(
|
|
134
|
-
# source=f"identifier {k}",
|
|
135
|
-
# type="Error",
|
|
136
|
-
# msg=f"Duplicate key {k} in category {c.key}",
|
|
137
|
-
# highlight_pattern = k
|
|
138
|
-
# )
|
|
139
|
-
# return self
|
|
140
|
-
|
|
141
|
-
# # @model_validator(mode='after')
|
|
142
|
-
# # def check_length(self) -> Self:
|
|
143
|
-
# # l = 0
|
|
144
|
-
# # for s in self.segments:
|
|
145
|
-
# # if s.key:
|
|
146
|
-
# # l += len(s.key)
|
|
147
|
-
# # l += 1 # for ":"
|
|
148
|
-
# # l += len(s.value)
|
|
149
|
-
# # l += len(self.segments) - 1 # account for "/" separating the segments
|
|
150
|
-
|
|
151
|
-
# # if l > 256:
|
|
152
|
-
# # self.add_validation_message(
|
|
153
|
-
# # source=f"identifier",
|
|
154
|
-
# # type="Error",
|
|
155
|
-
# # msg=f'Identifier is {l} characters long, Identifier must not exceed 256 characters.',
|
|
156
|
-
# # highlight_pattern = ""
|
|
157
|
-
# # )
|
|
158
|
-
# # return self
|
|
159
|
-
|
|
160
|
-
# @staticmethod
|
|
161
|
-
# def from_categories(categories:list[Category]) :
|
|
162
|
-
# segments = list()
|
|
163
|
-
# for c in categories:
|
|
164
|
-
# if c.key:
|
|
165
|
-
# segments.append(IDSegment(value=c.key))
|
|
166
|
-
# segments.extend(c.segments)
|
|
167
|
-
# return Identifier(segments=segments)
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
# # class PACID(BaseModelWithValidationMessages):
|
|
174
|
-
# # issuer:str
|
|
175
|
-
# # identifier: Identifier
|
|
176
|
-
|
|
177
|
-
# # @model_validator(mode="after")
|
|
178
|
-
# # def validate_issuer(self):
|
|
179
|
-
# # if not re.fullmatch(domain_name_pattern, self.issuer):
|
|
180
|
-
# # self.add_validation_message(
|
|
181
|
-
# # source="PAC-ID",
|
|
182
|
-
# # type="Error",
|
|
183
|
-
# # highlight_pattern=self.issuer,
|
|
184
|
-
# # msg=f"Issuer must be a valid domain name. "
|
|
185
|
-
# # )
|
|
186
|
-
|
|
187
|
-
# # # recommendation that A-Z, 0-9, -, and . should be used
|
|
188
|
-
# # if not_recommended_chars := set(re.sub(r'[A-Z0-9\.-]', '', self.issuer)):
|
|
189
|
-
# # self.add_validation_message(
|
|
190
|
-
# # source="PAC-ID",
|
|
191
|
-
# # type="Recommendation",
|
|
192
|
-
# # highlight_pattern=self.issuer,
|
|
193
|
-
# # highlight_sub=not_recommended_chars,
|
|
194
|
-
# # msg=f"Characters {' '.join(not_recommended_chars)} should not be used. Issuer SHOULD contain only the characters A-Z, 0-9, -, and . "
|
|
195
|
-
# # )
|
|
196
|
-
# # return self
|
|
197
|
-
|
|
198
|
-
# # def __str__(self):
|
|
199
|
-
# # id_segments = ''
|
|
200
|
-
# # for s in self.identifier.segments:
|
|
201
|
-
# # if s.key:
|
|
202
|
-
# # id_segments += f'/{s.key}:{s.value}'
|
|
203
|
-
# # else:
|
|
204
|
-
# # id_segments += f'/{s.value}'
|
|
205
|
-
|
|
206
|
-
# # out = f"HTTPS://PAC.{self.issuer}{id_segments}"
|
|
207
|
-
# # return out
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
# # class PACID_With_Extensions(BaseModelWithValidationMessages):
|
|
213
|
-
# # pac_id: PACID
|
|
214
|
-
# # extensions: list[Extension] = Field(default_factory=list)
|
|
215
|
-
|
|
216
|
-
# # def __str__(self):
|
|
217
|
-
# # out = str(self.pac_id)
|
|
218
|
-
# # out += '*'.join(str(e) for e in self.extensions)
|
|
219
|
-
|
|
220
|
-
# # def get_extension_of_type(self, type:str) -> list[Extension]:
|
|
221
|
-
# # return [e for e in self.extensions if e.type == type]
|
|
222
|
-
|
|
223
|
-
# # def get_extension(self, name:str) -> Extension|None:
|
|
224
|
-
# # out = [e for e in self.extensions if e.name == name]
|
|
225
|
-
# # if not out:
|
|
226
|
-
# # return None
|
|
227
|
-
# # return out[0]
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: labfreed
|
|
3
|
-
Version: 0.0.14
|
|
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
|
-
from datetime import datetime
|
|
38
|
-
from typing import Annotated
|
|
39
|
-
|
|
40
|
-
# Parse a PAC ID
|
|
41
|
-
from labfreed.PAC_ID.data_model import PACID, IDSegment
|
|
42
|
-
from labfreed.parse_pac import PAC_Parser, PACID_With_Extensions
|
|
43
|
-
from utility_types import Quantity
|
|
44
|
-
pac_str = 'HTTPS://PAC.METTORIUS.COM/-MD/BAL500/1234'
|
|
45
|
-
pac = PAC_Parser().parse_pac_id(pac_str)
|
|
46
|
-
|
|
47
|
-
## Check validity
|
|
48
|
-
pac_str = 'HTTPS://PAC.METTORIUS.COM/-MD/bal500/@1234'
|
|
49
|
-
pac = PAC_Parser().parse_pac_id(pac_str)
|
|
50
|
-
is_valid = pac.is_valid()
|
|
51
|
-
print('PAC-ID is valid: {is_valid}')
|
|
52
|
-
|
|
53
|
-
# Show recommendations
|
|
54
|
-
pac.print_validation_messages()
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
## Parse a PAC-ID with extensions
|
|
60
|
-
pac_str = 'HTTPS://PAC.METTORIUS.COM/-MD/BAL500/1234*N$N/WM633OV3E5DGJW2BEG0PDM1EA7*SUM$TREX/WEIGHT$GRM:67.89'
|
|
61
|
-
pac = PAC_Parser().parse_pac_with_extensions(pac_str)
|
|
62
|
-
|
|
63
|
-
# Display Name
|
|
64
|
-
display_names = pac.get_extension('N')
|
|
65
|
-
print(f'\nDisplay names: {display_names}')
|
|
66
|
-
|
|
67
|
-
# TREX
|
|
68
|
-
from labfreed.TREX.data_model import TREX, ColumnHeader, TREX_Table, TableRow
|
|
69
|
-
trexes = pac.get_extension_of_type('TREX')
|
|
70
|
-
trex:TREX = trexes[0]
|
|
71
|
-
v = trex.get_segment('WEIGHT').to_python_type()
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
## Create a PAC-ID
|
|
77
|
-
from labfreed.utilities.well_known_keys import WellKnownKeys
|
|
78
|
-
pac = PACID(issuer='METTORIUS:COM', identifier=[IDSegment(key=WellKnownKeys.SERIAL, value='1234')])
|
|
79
|
-
pac_str = pac.serialize()
|
|
80
|
-
pac_str = pac.serialize()
|
|
81
|
-
print(pac_str)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
# create a TREX
|
|
87
|
-
from labfreed.TREX.data_model import TREX, DateSegment, NumericSegment, BoolSegment, AlphanumericSegment, TextSegment, BinarySegment
|
|
88
|
-
|
|
89
|
-
trex = TREX(name_='DEMO-TREX')
|
|
90
|
-
|
|
91
|
-
trex.segments.append(DateSegment(key='START',value='20240505T1204'))
|
|
92
|
-
trex.segments.append(DateSegment(key='STOP', value=datetime(year=2024,month=5,day=5,hour=13,minute=6)) )
|
|
93
|
-
|
|
94
|
-
trex.segments.append(NumericSegment(key='TEMP',type='KEL', value=10.15) )
|
|
95
|
-
trex.segments.append(BoolSegment(key='OK', value=False) )
|
|
96
|
-
trex.segments.append(AlphanumericSegment(key='COMMENT', value='FOO') )
|
|
97
|
-
trex.segments.append(TextSegment(key='COMMENT2', value='£') )
|
|
98
|
-
trex.segments.append(TextSegment(key='COMMENT2', value='BAR') )
|
|
99
|
-
|
|
100
|
-
# if the sting is already in base36 you have to be explicit
|
|
101
|
-
from labfreed.utilities.base36 import base36
|
|
102
|
-
trex.segments.append(TextSegment(key='COMMENT3', value=base36('1URIOQ7')) )
|
|
103
|
-
|
|
104
|
-
# table
|
|
105
|
-
table = TREX_Table(key='TABLE',
|
|
106
|
-
column_headers=[
|
|
107
|
-
ColumnHeader(key='COL1', type='HUR'),
|
|
108
|
-
ColumnHeader(key='COL2', type='T.A'),
|
|
109
|
-
ColumnHeader(key='COL3', type='T.D'),
|
|
110
|
-
ColumnHeader(key='COL4', type='T.B')
|
|
111
|
-
],
|
|
112
|
-
data=[
|
|
113
|
-
TableRow()
|
|
114
|
-
])
|
|
115
|
-
trex.segments.append(table)
|
|
116
|
-
|
|
117
|
-
if trex.is_valid():
|
|
118
|
-
print(trex.data)
|
|
119
|
-
else:
|
|
120
|
-
trex.print_validation_messages()
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
p = PACID_With_Extensions(pac_id=pac, extensions=[trex])
|
|
124
|
-
print(p.serialize())
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
# for convenience a TREX can be created from a dict
|
|
131
|
-
trex2 = TREX(name_='DEMO-TREX2')
|
|
132
|
-
trex2.update(
|
|
133
|
-
{
|
|
134
|
-
'STOP': datetime(year=2024,month=5,day=5,hour=13,minute=6),
|
|
135
|
-
'TEMP': Quantity(value=10.15, unit_name='meter', unit_symbol='m'),
|
|
136
|
-
'OK':False,
|
|
137
|
-
'COMMENT': 'FOO',
|
|
138
|
-
'COMMENT2':'£'
|
|
139
|
-
}
|
|
140
|
-
)
|
|
141
|
-
|
|
142
|
-
d = trex2.dict()
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
```
|
|
153
|
-
<!-- END EXAMPLES -->
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
## Change Log
|
|
158
|
-
|
|
159
|
-
### v0.0.9
|
|
160
|
-
- supports PAC-ID, PAC-CAT, TREX and DisplayName
|
|
161
|
-
- ok-ish test coverage
|
|
File without changes
|
|
File without changes
|