labfreed 0.0.20__py2.py3-none-any.whl → 0.1.1__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/IO/parse_pac.py +5 -4
- labfreed/PAC_CAT/data_model.py +41 -21
- labfreed/PAC_ID/data_model.py +21 -26
- labfreed/PAC_ID_Resolver/cit.yaml +92 -0
- labfreed/PAC_ID_Resolver/data_types.py +85 -0
- labfreed/PAC_ID_Resolver/resolver.py +221 -0
- labfreed/TREX/data_model.py +14 -14
- labfreed/__init__.py +1 -1
- labfreed/validation.py +126 -38
- labfreed-0.1.1.dist-info/METADATA +279 -0
- labfreed-0.1.1.dist-info/RECORD +24 -0
- labfreed-0.0.20.dist-info/METADATA +0 -230
- labfreed-0.0.20.dist-info/RECORD +0 -21
- {labfreed-0.0.20.dist-info → labfreed-0.1.1.dist-info}/WHEEL +0 -0
- {labfreed-0.0.20.dist-info → labfreed-0.1.1.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: labfreed
|
|
3
|
+
Version: 0.1.1
|
|
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
|
+
Requires-Dist: numpy>=2.2.4
|
|
10
|
+
Requires-Dist: pydantic>=2.11.3
|
|
11
|
+
Requires-Dist: segno>=1.6.6
|
|
12
|
+
Requires-Dist: typer>=0.15.2
|
|
13
|
+
|
|
14
|
+
# LabFREED for Python
|
|
15
|
+
|
|
16
|
+
[](LICENSE) [](https://pypi.org/project/labfreed/) 
|
|
17
|
+
|
|
18
|
+
<!--
|
|
19
|
+
[](https://github.com/retothuerer/LabFREED/actions/workflows/ci.yml)
|
|
20
|
+
-->
|
|
21
|
+
|
|
22
|
+
This is a Python implementation of [LabFREED](https://labfreed.wega-it.com) building blocks.
|
|
23
|
+
|
|
24
|
+
## Supported Building Blocks
|
|
25
|
+
- PAC-ID
|
|
26
|
+
- PAC-CAT
|
|
27
|
+
- TREX
|
|
28
|
+
- Display Extension
|
|
29
|
+
- PAC-ID Resolver
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
You can install LabFREED from [PyPI](https://pypi.org/project/labfreed/) using pip:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install labfreed
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
## Usage Examples
|
|
40
|
+
> ⚠️ **Note:** These examples are building on each other. Imports and parsing are not repeated in each example.
|
|
41
|
+
<!-- BEGIN EXAMPLES -->
|
|
42
|
+
```python
|
|
43
|
+
# import built ins
|
|
44
|
+
import os
|
|
45
|
+
```
|
|
46
|
+
### Parse a simple PAC-ID
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from labfreed.IO.parse_pac import PAC_Parser
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
# Parse the PAC-ID
|
|
53
|
+
pac_str = 'HTTPS://PAC.METTORIUS.COM/-MD/bal500/@1234'
|
|
54
|
+
pac_id = PAC_Parser().parse(pac_str).pac_id
|
|
55
|
+
|
|
56
|
+
# Check validity of this PAC-ID
|
|
57
|
+
is_valid = pac_id.is_valid()
|
|
58
|
+
print(f'PAC-ID is valid: {is_valid}')
|
|
59
|
+
```
|
|
60
|
+
```text
|
|
61
|
+
>> PAC-ID is valid: True
|
|
62
|
+
```
|
|
63
|
+
### Show recommendations:
|
|
64
|
+
Note that the PAC-ID -- while valid -- uses characters which are not recommended (results in larger QR code).
|
|
65
|
+
There is a nice function to highlight problems
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
pac_id.print_validation_messages(target='markdown')
|
|
69
|
+
```
|
|
70
|
+
```text
|
|
71
|
+
>> Validation Results
|
|
72
|
+
>> ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
|
|
73
|
+
>> │ RECOMMENDATION │
|
|
74
|
+
>> │ Characters l a b should not be used., Characters SHOULD be limited to upper case letters (A-Z), numbers (0-9), '-' and '+' │
|
|
75
|
+
>> │ HTTPS://PAC.METTORIUS.COM/-MD/🔸b🔸🔸a🔸🔸l🔸500/@1234 │
|
|
76
|
+
>> ├─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
|
|
77
|
+
>> │ RECOMMENDATION │
|
|
78
|
+
>> │ Characters @ should not be used., Characters SHOULD be limited to upper case letters (A-Z), numbers (0-9), '-' and '+' │
|
|
79
|
+
>> │ HTTPS://PAC.METTORIUS.COM/-MD/bal500/🔸@🔸1234 │
|
|
80
|
+
>> └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
|
|
81
|
+
```
|
|
82
|
+
### Save as QR Code
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from labfreed.IO.generate_qr import save_qr_with_markers
|
|
86
|
+
|
|
87
|
+
save_qr_with_markers(pac_str, fmt='png')
|
|
88
|
+
```
|
|
89
|
+
```text
|
|
90
|
+
>> Large QR: Provided URL is not alphanumeric!
|
|
91
|
+
>> Size: 29
|
|
92
|
+
>> Version: 3
|
|
93
|
+
>> Error Level: M
|
|
94
|
+
```
|
|
95
|
+
### PAC-CAT
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
from labfreed.PAC_CAT.data_model import PAC_CAT
|
|
99
|
+
pac_str = 'HTTPS://PAC.METTORIUS.COM/-DR/XQ908756/-MD/bal500/@1234'
|
|
100
|
+
pac_id = PAC_Parser().parse(pac_str).pac_id
|
|
101
|
+
if isinstance(pac_id, PAC_CAT):
|
|
102
|
+
pac_id.print_categories()
|
|
103
|
+
```
|
|
104
|
+
```text
|
|
105
|
+
>> Categories in
|
|
106
|
+
>> HTTPS://PAC.METTORIUS.COM/-DR/XQ90
|
|
107
|
+
>> 8756/-MD/bal500/@1234
|
|
108
|
+
>> ┌────────────────────┬───────────┐
|
|
109
|
+
>> │ Main Category │ │
|
|
110
|
+
>> │ key () │ -DR │
|
|
111
|
+
>> │ id (21) │ XQ908756 │
|
|
112
|
+
>> ├────────────────────┼───────────┤
|
|
113
|
+
>> │ Category │ │
|
|
114
|
+
>> │ key () │ -MD │
|
|
115
|
+
>> │ model_number (240) │ bal500 │
|
|
116
|
+
>> │ serial_number (21) │ @1234 │
|
|
117
|
+
>> └────────────────────┴───────────┘
|
|
118
|
+
```
|
|
119
|
+
### Parse a PAC-ID with extensions
|
|
120
|
+
PAC-ID can have extensions. Here we parse a PAC-ID with attached display names and summary.
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
pac_str = 'HTTPS://PAC.METTORIUS.COM/-MD/BAL500/1234*N$N/WM633OV3E5DGJW2BEG0PDM1EA7*SUM$TREX/WEIGHT$GRM:67.89'
|
|
124
|
+
pac_id = PAC_Parser().parse(pac_str)
|
|
125
|
+
|
|
126
|
+
# Display Name
|
|
127
|
+
display_names = pac_id.get_extension('N') # display name has name 'N'
|
|
128
|
+
print(display_names)
|
|
129
|
+
```
|
|
130
|
+
```text
|
|
131
|
+
>> Display names: My Balance ❤️
|
|
132
|
+
```
|
|
133
|
+
```python
|
|
134
|
+
# TREX
|
|
135
|
+
trexes = pac_id.get_extension_of_type('TREX')
|
|
136
|
+
trex = trexes[0] # there could be multiple trexes. In this example there is only one, though
|
|
137
|
+
v = trex.get_segment('WEIGHT').to_python_type()
|
|
138
|
+
print(f'WEIGHT = {v}')
|
|
139
|
+
```
|
|
140
|
+
```text
|
|
141
|
+
>> WEIGHT = 67.89 g
|
|
142
|
+
```
|
|
143
|
+
### Create a PAC-ID with Extensions
|
|
144
|
+
|
|
145
|
+
#### Create PAC-ID
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
from labfreed.PAC_ID.data_model import PACID, IDSegment
|
|
149
|
+
from labfreed.utilities.well_known_keys import WellKnownKeys
|
|
150
|
+
|
|
151
|
+
pac_id = PACID(issuer='METTORIUS.COM', identifier=[IDSegment(key=WellKnownKeys.SERIAL, value='1234')])
|
|
152
|
+
pac_str = pac_id.serialize()
|
|
153
|
+
print(pac_str)
|
|
154
|
+
```
|
|
155
|
+
```text
|
|
156
|
+
>> HTTPS://PAC.METTORIUS.COM/21:1234
|
|
157
|
+
```
|
|
158
|
+
#### Create a TREX
|
|
159
|
+
TREX can conveniently be created from a python dictionary.
|
|
160
|
+
Note that utility types for Quantity (number with unit) and table are needed
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
from datetime import datetime
|
|
164
|
+
from labfreed.TREX.data_model import TREX
|
|
165
|
+
from labfreed.utilities.utility_types import Quantity, DataTable, Unit
|
|
166
|
+
|
|
167
|
+
# Create TREX
|
|
168
|
+
trex = TREX(name_='DEMO')
|
|
169
|
+
# Add value segments of different type
|
|
170
|
+
trex.update(
|
|
171
|
+
{
|
|
172
|
+
'STOP': datetime(year=2024,month=5,day=5,hour=13,minute=6),
|
|
173
|
+
'TEMP': Quantity(value=10.15, unit=Unit(name='kelvin', symbol='K')),
|
|
174
|
+
'OK':False,
|
|
175
|
+
'COMMENT': 'FOO',
|
|
176
|
+
'COMMENT2':'£'
|
|
177
|
+
}
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
# Create a table
|
|
181
|
+
table = DataTable(['DURATION', 'Date', 'OK', 'COMMENT'])
|
|
182
|
+
table.append([Quantity(value=1, unit=Unit(symbol='h', name='hour')), datetime.now(), True, 'FOO'])
|
|
183
|
+
table.append([ 1.1, datetime.now(), True, 'BAR'])
|
|
184
|
+
table.append([ 1.3, datetime.now(), False, 'BLUBB'])
|
|
185
|
+
#add the table to the trex
|
|
186
|
+
trex.update({'TABLE': table})
|
|
187
|
+
|
|
188
|
+
# Validation also works the same way for TREX
|
|
189
|
+
trex.print_validation_messages(target='markdown')
|
|
190
|
+
```
|
|
191
|
+
```text
|
|
192
|
+
>> Validation Results
|
|
193
|
+
>> ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
|
|
194
|
+
>> │ ERROR │
|
|
195
|
+
>> │ Column header key contains invalid characters: e,a,t │
|
|
196
|
+
>> │ 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:D🔸a🔸🔸t🔸🔸e🔸$T.D:OK$T.B:COMMENT$T.A::1:20250411T090300.103:T:FOO::1… │
|
|
197
|
+
>> └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
|
|
198
|
+
```
|
|
199
|
+
```python
|
|
200
|
+
# there is an error. 'Date' uses lower case. Lets fix it
|
|
201
|
+
d = trex.dict()
|
|
202
|
+
d['TABLE'].col_names[1] = 'DATE'
|
|
203
|
+
trex = TREX(name_='DEMO')
|
|
204
|
+
trex.update(d)
|
|
205
|
+
```
|
|
206
|
+
#### Combine PAC-ID and TREX and serialize
|
|
207
|
+
|
|
208
|
+
```python
|
|
209
|
+
from labfreed.IO.parse_pac import PACID_With_Extensions
|
|
210
|
+
|
|
211
|
+
pac_with_trex = PACID_With_Extensions(pac_id=pac_id, extensions=[trex])
|
|
212
|
+
pac_str = pac_with_trex.serialize()
|
|
213
|
+
print(pac_str)
|
|
214
|
+
```
|
|
215
|
+
```text
|
|
216
|
+
>> 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:20250411T090300.103:T:FOO::1.1:20250411T090300.103:T:BAR::1.3:20250411T090300.103:F:BLUBB
|
|
217
|
+
```
|
|
218
|
+
## PAC-ID Resolver
|
|
219
|
+
|
|
220
|
+
```python
|
|
221
|
+
from labfreed.PAC_ID_Resolver.resolver import PAC_ID_Resolver, load_cit
|
|
222
|
+
# Get a CIT
|
|
223
|
+
dir = os.path.dirname(__file__)
|
|
224
|
+
p = os.path.join(dir, 'cit_mine.yaml')
|
|
225
|
+
cit = load_cit(p)
|
|
226
|
+
|
|
227
|
+
# validate the CIT
|
|
228
|
+
cit.is_valid()
|
|
229
|
+
cit.print_validation_messages()
|
|
230
|
+
```
|
|
231
|
+
```python
|
|
232
|
+
# resolve a pac id
|
|
233
|
+
service_groups = PAC_ID_Resolver(cits=[cit]).resolve(pac_with_trex)
|
|
234
|
+
for sg in service_groups:
|
|
235
|
+
sg.update_states()
|
|
236
|
+
sg.print()
|
|
237
|
+
|
|
238
|
+
5
|
|
239
|
+
```
|
|
240
|
+
```text
|
|
241
|
+
>> Request failed: HTTPSConnectionPool(host='aaaaaaaaaaaa.mettorius.com.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError(1, '[SSL:
|
|
242
|
+
>> SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:1028)')))
|
|
243
|
+
>> Services from origin 'MINE
|
|
244
|
+
>> ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┓
|
|
245
|
+
>> ┃ Service Name ┃ URL ┃ Reachable ┃
|
|
246
|
+
>> ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━┩
|
|
247
|
+
>> │ AAAAAAAAAAAAAAAAAAhhhhhh │ https://AAAAAAAAAAAA.METTORIUS.COM.com/ │ INACTIVE │
|
|
248
|
+
>> └──────────────────────────┴─────────────────────────────────────────┴───────────┘
|
|
249
|
+
>> Services from origin 'PAC.METTORIUS.COM
|
|
250
|
+
>> ┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┓
|
|
251
|
+
>> ┃ Service Name ┃ URL ┃ Reachable ┃
|
|
252
|
+
>> ┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━┩
|
|
253
|
+
>> │ Shop │ https://mettorius.com/shop/an= │ INACTIVE │
|
|
254
|
+
>> │ Manual │ https://mettorius.com/om/an= │ INACTIVE │
|
|
255
|
+
>> │ _3 │ https://mettorius.com/ │ ACTIVE │
|
|
256
|
+
>> └──────────────┴────────────────────────────────┴───────────┘
|
|
257
|
+
```
|
|
258
|
+
<!-- END EXAMPLES -->
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
## Change Log
|
|
263
|
+
|
|
264
|
+
### v0.1.1
|
|
265
|
+
- minor internal improvements and bugfixes
|
|
266
|
+
|
|
267
|
+
### v0.1.0
|
|
268
|
+
- DRAFT Support for PAC-ID Resolver
|
|
269
|
+
|
|
270
|
+
### v0.0.20
|
|
271
|
+
- bugfix in TREX table to dict conversion
|
|
272
|
+
- markdown compatible validation printing
|
|
273
|
+
|
|
274
|
+
### v0.0.19
|
|
275
|
+
- supports PAC-ID, PAC-CAT, TREX and DisplayName
|
|
276
|
+
- QR generation
|
|
277
|
+
- ok-ish test coverage
|
|
278
|
+
|
|
279
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
labfreed/__init__.py,sha256=TzQ186YXdEkFSNsduP7q0XO3d8HEiNMNkHMZ6t6Zg-Y,87
|
|
2
|
+
labfreed/validation.py,sha256=29Ys6qrCQ4T689juc19aiNJfHEgggI-hO7gfwrrNKWI,9554
|
|
3
|
+
labfreed/DisplayNameExtension/DisplayNameExtension.py,sha256=l9JZY2eRS0V-H5h3-WXIHiiBJuljns-_e_t9Bp84_CU,1155
|
|
4
|
+
labfreed/IO/generate_qr.py,sha256=wdZSf51Id03xSY8liK2RfB7WyGAw9O4s0VhZzrkAa-g,16680
|
|
5
|
+
labfreed/IO/parse_pac.py,sha256=1rV-pJ4kUgxQMDl8DJ14SUmHV37ruKYZYBqiJjPtCUw,6381
|
|
6
|
+
labfreed/PAC_CAT/__init__.py,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
|
|
7
|
+
labfreed/PAC_CAT/data_model.py,sha256=9cjLA7u4APtiFbZyYp9iuYhl5mOGUPS30gXwYl0G_24,15153
|
|
8
|
+
labfreed/PAC_ID/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
labfreed/PAC_ID/data_model.py,sha256=IZB6F2p3E90mEalnYdGjPvMGcuvNWOrqqlKXGuDyJQ4,7601
|
|
10
|
+
labfreed/PAC_ID/extensions.py,sha256=YKIE-aFf1jdL4sqCqUe3txjnP8-dA2zCJrT5lBSjvuE,1092
|
|
11
|
+
labfreed/PAC_ID_Resolver/cit.yaml,sha256=G_cH1f0Z7MUGgu7YR1cVhTrETaSBHvTVC7sbTbUJ-Rc,1992
|
|
12
|
+
labfreed/PAC_ID_Resolver/data_types.py,sha256=XFUmlw-sGLbYNdHdyb-8SZMK6BwMMQWKuLfIGO-yR3g,2650
|
|
13
|
+
labfreed/PAC_ID_Resolver/resolver.py,sha256=2EKpDEzOM8Ri-Gy5cKVE6aoHsVFRqZE9fd_llG4wrFI,8178
|
|
14
|
+
labfreed/TREX/UneceUnits.json,sha256=kwfQSp_nTuWbADfBBgqTWrvPl6XtM5SedEVLbMJrM7M,898953
|
|
15
|
+
labfreed/TREX/data_model.py,sha256=etb4dd2kNFGDU5upQkH1YhlutRsvblMst4FdHQyuDu0,29972
|
|
16
|
+
labfreed/TREX/parse.py,sha256=86962VEJpkrTcT436iFIB5dNed5WHABzpjxRjkA3PXo,2043
|
|
17
|
+
labfreed/TREX/unece_units.py,sha256=scPKdsPzY1neAdFOhA08_tRZaR-yplM8mBhIzzDqZBk,3006
|
|
18
|
+
labfreed/utilities/base36.py,sha256=_yX8aQ1OwrK5tnJU1NUEzQSFGr9xAVnNvPObpNzCPYs,2895
|
|
19
|
+
labfreed/utilities/utility_types.py,sha256=dM0qZgshF3cHJThVzia7UIAOdkNLKukAaaduLqKSaMY,2195
|
|
20
|
+
labfreed/utilities/well_known_keys.py,sha256=nqk66kHdSwJTJfMKlP-xQbBglS8F_NoWsGkfOVITFN0,331
|
|
21
|
+
labfreed-0.1.1.dist-info/licenses/LICENSE,sha256=gHFOv9FRKHxO8cInP3YXyPoJnuNeqrvcHjaE_wPSsQ8,1100
|
|
22
|
+
labfreed-0.1.1.dist-info/WHEEL,sha256=Dyt6SBfaasWElUrURkknVFAZDHSTwxg3PaTza7RSbkY,100
|
|
23
|
+
labfreed-0.1.1.dist-info/METADATA,sha256=uxdO6fEUnZPsWnW_sTZD34ptdj9xBPIXlUPk0mJQI6c,13103
|
|
24
|
+
labfreed-0.1.1.dist-info/RECORD,,
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: labfreed
|
|
3
|
-
Version: 0.0.20
|
|
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
|
-
Requires-Dist: numpy>=2.2.4
|
|
10
|
-
Requires-Dist: pydantic>=2.11.3
|
|
11
|
-
Requires-Dist: segno>=1.6.6
|
|
12
|
-
Requires-Dist: typer>=0.15.2
|
|
13
|
-
|
|
14
|
-
# LabFREED for Python
|
|
15
|
-
|
|
16
|
-
[](LICENSE) [](https://pypi.org/project/labfreed/) 
|
|
17
|
-
|
|
18
|
-
<!--
|
|
19
|
-
[](https://github.com/retothuerer/LabFREED/actions/workflows/ci.yml)
|
|
20
|
-
-->
|
|
21
|
-
|
|
22
|
-
This is a Python implementation of [LabFREED](https://labfreed.wega-it.com) building blocks.
|
|
23
|
-
|
|
24
|
-
## Supported Building Blocks
|
|
25
|
-
- PAC-ID
|
|
26
|
-
- PAC-CAT
|
|
27
|
-
- TREX
|
|
28
|
-
- Display Extension
|
|
29
|
-
|
|
30
|
-
## Installation
|
|
31
|
-
You can install LabFREED from [PyPI](https://pypi.org/project/labfreed/) using pip:
|
|
32
|
-
|
|
33
|
-
```bash
|
|
34
|
-
pip install labfreed
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
## Usage Examples
|
|
39
|
-
> ⚠️ **Note:** These examples are building on each other. Imports and parsing are not repeated in each example.
|
|
40
|
-
<!-- BEGIN EXAMPLES -->
|
|
41
|
-
### Parse a simple PAC-ID
|
|
42
|
-
|
|
43
|
-
```python
|
|
44
|
-
from labfreed.IO.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(f'PAC-ID is valid: {is_valid}')
|
|
54
|
-
```
|
|
55
|
-
```text
|
|
56
|
-
>> PAC-ID is valid: True
|
|
57
|
-
```
|
|
58
|
-
### Show recommendations:
|
|
59
|
-
Note that the PAC-ID -- while valid -- uses characters which are not recommended (results in larger QR code).
|
|
60
|
-
There is a nice function to highlight problems
|
|
61
|
-
|
|
62
|
-
```python
|
|
63
|
-
pac_id.print_validation_messages(target='markdown')
|
|
64
|
-
```
|
|
65
|
-
```text
|
|
66
|
-
>> =======================================
|
|
67
|
-
>> Validation Results
|
|
68
|
-
>> ---------------------------------------
|
|
69
|
-
>>
|
|
70
|
-
>> Recommendation in id segment value bal500
|
|
71
|
-
>> HTTPS://PAC.METTORIUS.COM/-MD/🔸b🔸🔸a🔸🔸l🔸500/@1234
|
|
72
|
-
>> Characters b l a should not be used.
|
|
73
|
-
>>
|
|
74
|
-
>> Recommendation in id segment value @1234
|
|
75
|
-
>> HTTPS://PAC.METTORIUS.COM/-MD/bal500/🔸@🔸1234
|
|
76
|
-
>> Characters @ should not be used.
|
|
77
|
-
>>
|
|
78
|
-
>> Warning in Category -MD
|
|
79
|
-
>> HTTPS://PAC.METTORIUS.COM/🔸-MD🔸/bal500/@1234
|
|
80
|
-
>> Category key -MD is not a well known key. It is recommended to use well known keys only
|
|
81
|
-
```
|
|
82
|
-
### Save as QR Code
|
|
83
|
-
|
|
84
|
-
```python
|
|
85
|
-
from labfreed.IO.generate_qr import save_qr_with_markers
|
|
86
|
-
|
|
87
|
-
save_qr_with_markers(pac_str, fmt='png')
|
|
88
|
-
```
|
|
89
|
-
```text
|
|
90
|
-
>> Large QR: Provided URL is not alphanumeric!
|
|
91
|
-
>> Size: 29
|
|
92
|
-
>> Version: 3
|
|
93
|
-
>> Error Level: M
|
|
94
|
-
```
|
|
95
|
-
### PAC-CAT
|
|
96
|
-
|
|
97
|
-
```python
|
|
98
|
-
from labfreed.PAC_CAT.data_model import PAC_CAT
|
|
99
|
-
pac_str = 'HTTPS://PAC.METTORIUS.COM/-DR/XQ908756/-MD/bal500/@1234'
|
|
100
|
-
pac_id = PAC_Parser().parse(pac_str).pac_id
|
|
101
|
-
if isinstance(pac_id, PAC_CAT):
|
|
102
|
-
pac_id.print_categories()
|
|
103
|
-
```
|
|
104
|
-
```text
|
|
105
|
-
>> Main Category
|
|
106
|
-
>> ----------
|
|
107
|
-
>> key (): -DR
|
|
108
|
-
>> id (21): XQ908756
|
|
109
|
-
>> Category
|
|
110
|
-
>> ------
|
|
111
|
-
>> key (): -MD
|
|
112
|
-
>> model_number (240): bal500
|
|
113
|
-
>> serial_number (21): @1234
|
|
114
|
-
```
|
|
115
|
-
### Parse a PAC-ID with extensions
|
|
116
|
-
PAC-ID can have extensions. Here we parse a PAC-ID with attached display names and summary.
|
|
117
|
-
|
|
118
|
-
```python
|
|
119
|
-
pac_str = 'HTTPS://PAC.METTORIUS.COM/-MD/BAL500/1234*N$N/WM633OV3E5DGJW2BEG0PDM1EA7*SUM$TREX/WEIGHT$GRM:67.89'
|
|
120
|
-
pac_id = PAC_Parser().parse(pac_str)
|
|
121
|
-
|
|
122
|
-
# Display Name
|
|
123
|
-
display_names = pac_id.get_extension('N') # display name has name 'N'
|
|
124
|
-
print(display_names)
|
|
125
|
-
```
|
|
126
|
-
```text
|
|
127
|
-
>> Display names: My Balance ❤️
|
|
128
|
-
```
|
|
129
|
-
```python
|
|
130
|
-
# TREX
|
|
131
|
-
trexes = pac_id.get_extension_of_type('TREX')
|
|
132
|
-
trex = trexes[0] # there could be multiple trexes. In this example there is only one, though
|
|
133
|
-
v = trex.get_segment('WEIGHT').to_python_type()
|
|
134
|
-
print(f'WEIGHT = {v}')
|
|
135
|
-
```
|
|
136
|
-
```text
|
|
137
|
-
>> WEIGHT = 67.89 g
|
|
138
|
-
```
|
|
139
|
-
### Create a PAC-ID with Extensions
|
|
140
|
-
|
|
141
|
-
#### Create PAC-ID
|
|
142
|
-
|
|
143
|
-
```python
|
|
144
|
-
from labfreed.PAC_ID.data_model import PACID, IDSegment
|
|
145
|
-
from labfreed.utilities.well_known_keys import WellKnownKeys
|
|
146
|
-
|
|
147
|
-
pac_id = PACID(issuer='METTORIUS.COM', identifier=[IDSegment(key=WellKnownKeys.SERIAL, value='1234')])
|
|
148
|
-
pac_str = pac_id.serialize()
|
|
149
|
-
print(pac_str)
|
|
150
|
-
```
|
|
151
|
-
```text
|
|
152
|
-
>> HTTPS://PAC.METTORIUS.COM/21:1234
|
|
153
|
-
```
|
|
154
|
-
#### Create a TREX
|
|
155
|
-
TREX can conveniently be created from a python dictionary.
|
|
156
|
-
Note that utility types for Quantity (number with unit) and table are needed
|
|
157
|
-
|
|
158
|
-
```python
|
|
159
|
-
from datetime import datetime
|
|
160
|
-
from labfreed.TREX.data_model import TREX
|
|
161
|
-
from labfreed.utilities.utility_types import Quantity, DataTable, Unit
|
|
162
|
-
|
|
163
|
-
# Create TREX
|
|
164
|
-
trex = TREX(name_='DEMO')
|
|
165
|
-
# Add value segments of different type
|
|
166
|
-
trex.update(
|
|
167
|
-
{
|
|
168
|
-
'STOP': datetime(year=2024,month=5,day=5,hour=13,minute=6),
|
|
169
|
-
'TEMP': Quantity(value=10.15, unit=Unit(name='kelvin', symbol='K')),
|
|
170
|
-
'OK':False,
|
|
171
|
-
'COMMENT': 'FOO',
|
|
172
|
-
'COMMENT2':'£'
|
|
173
|
-
}
|
|
174
|
-
)
|
|
175
|
-
|
|
176
|
-
# Create a table
|
|
177
|
-
table = DataTable(['DURATION', 'Date', 'OK', 'COMMENT'])
|
|
178
|
-
table.append([Quantity(value=1, unit=Unit(symbol='h', name='hour')), datetime.now(), True, 'FOO'])
|
|
179
|
-
table.append([ 1.1, datetime.now(), True, 'BAR'])
|
|
180
|
-
table.append([ 1.3, datetime.now(), False, 'BLUBB'])
|
|
181
|
-
#add the table to the trex
|
|
182
|
-
trex.update({'TABLE': table})
|
|
183
|
-
|
|
184
|
-
# Validation also works the same way for TREX
|
|
185
|
-
trex.print_validation_messages(target='markdown')
|
|
186
|
-
```
|
|
187
|
-
```text
|
|
188
|
-
>> =======================================
|
|
189
|
-
>> Validation Results
|
|
190
|
-
>> ---------------------------------------
|
|
191
|
-
>>
|
|
192
|
-
>> Error in TREX table column Date
|
|
193
|
-
>> 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:D🔸a🔸🔸t🔸🔸e🔸$T.D:OK$T.B:COMMENT$T.A::1:20250409T094048.268:T:FOO::1.1:20250409T094048.268:T:BAR::1.3:20250409T094048.268:F:BLUBB
|
|
194
|
-
>> Column header key contains invalid characters: e,t,a
|
|
195
|
-
```
|
|
196
|
-
```python
|
|
197
|
-
# there is an error. 'Date' uses lower case. Lets fix it
|
|
198
|
-
d = trex.dict()
|
|
199
|
-
d['TABLE'].col_names[1] = 'DATE'
|
|
200
|
-
trex = TREX(name_='DEMO')
|
|
201
|
-
trex.update(d)
|
|
202
|
-
```
|
|
203
|
-
#### Combine PAC-ID and TREX and serialize
|
|
204
|
-
|
|
205
|
-
```python
|
|
206
|
-
from labfreed.IO.parse_pac import PACID_With_Extensions
|
|
207
|
-
|
|
208
|
-
pac_with_trex = PACID_With_Extensions(pac_id=pac_id, extensions=[trex])
|
|
209
|
-
pac_str = pac_with_trex.serialize()
|
|
210
|
-
print(pac_str)
|
|
211
|
-
```
|
|
212
|
-
```text
|
|
213
|
-
>> 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:20250409T094048.268:T:FOO::1.1:20250409T094048.268:T:BAR::1.3:20250409T094048.268:F:BLUBB
|
|
214
|
-
```
|
|
215
|
-
<!-- END EXAMPLES -->
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
## Change Log
|
|
220
|
-
|
|
221
|
-
### v0.0.20
|
|
222
|
-
- bugfix in TREX table to dict conversion
|
|
223
|
-
- markdown compatible validation printing
|
|
224
|
-
|
|
225
|
-
### v0.0.19
|
|
226
|
-
- supports PAC-ID, PAC-CAT, TREX and DisplayName
|
|
227
|
-
- QR generation
|
|
228
|
-
- ok-ish test coverage
|
|
229
|
-
|
|
230
|
-
|
labfreed-0.0.20.dist-info/RECORD
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
labfreed/__init__.py,sha256=JJg9mHM5goSWphrIerAaoiUjcOEZ7AXqGJIlmFog-pA,88
|
|
2
|
-
labfreed/validation.py,sha256=he9utRxQwks4ro94AVi8t5rU4jgRcA-6uz1XEmqoAnM,6359
|
|
3
|
-
labfreed/DisplayNameExtension/DisplayNameExtension.py,sha256=l9JZY2eRS0V-H5h3-WXIHiiBJuljns-_e_t9Bp84_CU,1155
|
|
4
|
-
labfreed/IO/generate_qr.py,sha256=wdZSf51Id03xSY8liK2RfB7WyGAw9O4s0VhZzrkAa-g,16680
|
|
5
|
-
labfreed/IO/parse_pac.py,sha256=2c-HXkiQdUrGTL8zGb5CmO9l6ZrCb07rrTMMKdMi3_o,6253
|
|
6
|
-
labfreed/PAC_CAT/__init__.py,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
|
|
7
|
-
labfreed/PAC_CAT/data_model.py,sha256=dGwcQGLy1Dk6SFbs9utxKQKm_4ROZrXdv618APlQg7M,14308
|
|
8
|
-
labfreed/PAC_ID/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
-
labfreed/PAC_ID/data_model.py,sha256=g09qgC-TV6fjJw9VyDF6mTJ6co2i2RKZc0Z-BmiiUIQ,7483
|
|
10
|
-
labfreed/PAC_ID/extensions.py,sha256=YKIE-aFf1jdL4sqCqUe3txjnP8-dA2zCJrT5lBSjvuE,1092
|
|
11
|
-
labfreed/TREX/UneceUnits.json,sha256=kwfQSp_nTuWbADfBBgqTWrvPl6XtM5SedEVLbMJrM7M,898953
|
|
12
|
-
labfreed/TREX/data_model.py,sha256=tGgjp76wbS1MSS1Ep842CZyintsbecTZrlapj8WwGH8,29704
|
|
13
|
-
labfreed/TREX/parse.py,sha256=86962VEJpkrTcT436iFIB5dNed5WHABzpjxRjkA3PXo,2043
|
|
14
|
-
labfreed/TREX/unece_units.py,sha256=scPKdsPzY1neAdFOhA08_tRZaR-yplM8mBhIzzDqZBk,3006
|
|
15
|
-
labfreed/utilities/base36.py,sha256=_yX8aQ1OwrK5tnJU1NUEzQSFGr9xAVnNvPObpNzCPYs,2895
|
|
16
|
-
labfreed/utilities/utility_types.py,sha256=dM0qZgshF3cHJThVzia7UIAOdkNLKukAaaduLqKSaMY,2195
|
|
17
|
-
labfreed/utilities/well_known_keys.py,sha256=nqk66kHdSwJTJfMKlP-xQbBglS8F_NoWsGkfOVITFN0,331
|
|
18
|
-
labfreed-0.0.20.dist-info/licenses/LICENSE,sha256=gHFOv9FRKHxO8cInP3YXyPoJnuNeqrvcHjaE_wPSsQ8,1100
|
|
19
|
-
labfreed-0.0.20.dist-info/WHEEL,sha256=Dyt6SBfaasWElUrURkknVFAZDHSTwxg3PaTza7RSbkY,100
|
|
20
|
-
labfreed-0.0.20.dist-info/METADATA,sha256=phvfg_T1RGixhz1rN27aqGk7xRlxLNs_yjj-Ts2Pc-k,6961
|
|
21
|
-
labfreed-0.0.20.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|