labfreed 0.0.19__py2.py3-none-any.whl → 0.0.20__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.

@@ -436,7 +436,7 @@ class TREX_Table(TREX_Segment):
436
436
  self.add_validation_message(
437
437
  source=f"Table {self.key}",
438
438
  type="Error",
439
- msg=f"Size mismatch: Table header contains {self.col_names} keys, while most rows have {most_common_len}",
439
+ msg=f"Size mismatch: Table header contains {self.column_names} keys, while most rows have {most_common_len}",
440
440
  highlight_pattern = self.key
441
441
  )
442
442
  expected_row_len = most_common_len
@@ -527,7 +527,7 @@ class TREX_Table(TREX_Segment):
527
527
  r.append(Quantity(value=e.value, unit=unit))
528
528
  else:
529
529
  r.append(e.value_to_python_type())
530
- table.append(r)
530
+ table.append(r)
531
531
  return table
532
532
 
533
533
 
labfreed/__init__.py CHANGED
@@ -2,4 +2,4 @@
2
2
  Python implementation of LabFREED building blocks
3
3
  '''
4
4
 
5
- __version__ = "0.0.19"
5
+ __version__ = "0.0.20"
labfreed/validation.py CHANGED
@@ -113,7 +113,7 @@ class BaseModelWithValidationMessages(BaseModel):
113
113
  return filter_warnings(self.get_nested_validation_messages())
114
114
 
115
115
 
116
- def print_validation_messages(self, str_to_highlight_in=None):
116
+ def print_validation_messages(self, str_to_highlight_in=None, target='console'):
117
117
  if not str_to_highlight_in:
118
118
  str_to_highlight_in = str(self)
119
119
  msgs = self.get_nested_validation_messages()
@@ -133,7 +133,13 @@ class BaseModelWithValidationMessages(BaseModel):
133
133
 
134
134
  text = Text.from_markup(f'\n [bold {color}]{m.type} [/bold {color}] in \t {m.source}' )
135
135
  print(text)
136
- formatted_highlight = m.emphazised_highlight.replace('emph', f'bold {color}')
136
+ match target:
137
+ case 'markdown':
138
+ formatted_highlight = m.emphazised_highlight.replace('emph', f'🔸').replace('[/', '').replace('[', '').replace(']', '')
139
+ case 'console':
140
+ formatted_highlight = m.emphazised_highlight.replace('emph', f'bold {color}')
141
+ case 'html':
142
+ formatted_highlight = m.emphazised_highlight.replace('emph', f'b').replace('[', '<').replace(']', '>')
137
143
  fmtd = str_to_highlight_in.replace(m.highlight, formatted_highlight)
138
144
  fmtd = Text.from_markup(fmtd)
139
145
  print(fmtd)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: labfreed
3
- Version: 0.0.19
3
+ Version: 0.0.20
4
4
  Summary: Python implementation of LabFREED building blocks
5
5
  Author-email: Reto Thürer <thuerer.r@buchi.com>
6
6
  Description-Content-Type: text/markdown
@@ -19,7 +19,7 @@ Requires-Dist: typer>=0.15.2
19
19
  [![Tests](https://github.com/retothuerer/LabFREED/actions/workflows/ci.yml/badge.svg)](https://github.com/retothuerer/LabFREED/actions/workflows/ci.yml)
20
20
  -->
21
21
 
22
- This is a Python implementation of [LabFREED](www.labfreed.wega-it.com) building blocks.
22
+ This is a Python implementation of [LabFREED](https://labfreed.wega-it.com) building blocks.
23
23
 
24
24
  ## Supported Building Blocks
25
25
  - PAC-ID
@@ -60,7 +60,7 @@ Note that the PAC-ID -- while valid -- uses characters which are not recommended
60
60
  There is a nice function to highlight problems
61
61
 
62
62
  ```python
63
- pac_id.print_validation_messages()
63
+ pac_id.print_validation_messages(target='markdown')
64
64
  ```
65
65
  ```text
66
66
  >> =======================================
@@ -68,15 +68,15 @@ pac_id.print_validation_messages()
68
68
  >> ---------------------------------------
69
69
  >>
70
70
  >> Recommendation in id segment value bal500
71
- >> HTTPS://PAC.METTORIUS.COM/-MD/bal500/@1234
72
- >> Characters l a b should not be used.
71
+ >> HTTPS://PAC.METTORIUS.COM/-MD/🔸b🔸🔸a🔸🔸l🔸500/@1234
72
+ >> Characters b l a should not be used.
73
73
  >>
74
74
  >> Recommendation in id segment value @1234
75
- >> HTTPS://PAC.METTORIUS.COM/-MD/bal500/@1234
75
+ >> HTTPS://PAC.METTORIUS.COM/-MD/bal500/🔸@🔸1234
76
76
  >> Characters @ should not be used.
77
77
  >>
78
78
  >> Warning in Category -MD
79
- >> HTTPS://PAC.METTORIUS.COM/-MD/bal500/@1234
79
+ >> HTTPS://PAC.METTORIUS.COM/🔸-MD🔸/bal500/@1234
80
80
  >> Category key -MD is not a well known key. It is recommended to use well known keys only
81
81
  ```
82
82
  ### Save as QR Code
@@ -144,12 +144,12 @@ print(f'WEIGHT = {v}')
144
144
  from labfreed.PAC_ID.data_model import PACID, IDSegment
145
145
  from labfreed.utilities.well_known_keys import WellKnownKeys
146
146
 
147
- pac_id = PACID(issuer='METTORIUS:COM', identifier=[IDSegment(key=WellKnownKeys.SERIAL, value='1234')])
147
+ pac_id = PACID(issuer='METTORIUS.COM', identifier=[IDSegment(key=WellKnownKeys.SERIAL, value='1234')])
148
148
  pac_str = pac_id.serialize()
149
149
  print(pac_str)
150
150
  ```
151
151
  ```text
152
- >> HTTPS://PAC.METTORIUS:COM/21:1234
152
+ >> HTTPS://PAC.METTORIUS.COM/21:1234
153
153
  ```
154
154
  #### Create a TREX
155
155
  TREX can conveniently be created from a python dictionary.
@@ -174,7 +174,7 @@ trex.update(
174
174
  )
175
175
 
176
176
  # Create a table
177
- table = DataTable(['DURATION', 'DATE', 'OK', 'COMMENT'])
177
+ table = DataTable(['DURATION', 'Date', 'OK', 'COMMENT'])
178
178
  table.append([Quantity(value=1, unit=Unit(symbol='h', name='hour')), datetime.now(), True, 'FOO'])
179
179
  table.append([ 1.1, datetime.now(), True, 'BAR'])
180
180
  table.append([ 1.3, datetime.now(), False, 'BLUBB'])
@@ -182,11 +182,23 @@ table.append([ 1.3, datetime.no
182
182
  trex.update({'TABLE': table})
183
183
 
184
184
  # Validation also works the same way for TREX
185
- if trex.get_nested_validation_messages():
186
- trex.print_validation_messages()
187
-
188
- # Side Note: The TREX can be turned back into a dict
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
189
198
  d = trex.dict()
199
+ d['TABLE'].col_names[1] = 'DATE'
200
+ trex = TREX(name_='DEMO')
201
+ trex.update(d)
190
202
  ```
191
203
  #### Combine PAC-ID and TREX and serialize
192
204
 
@@ -198,7 +210,7 @@ pac_str = pac_with_trex.serialize()
198
210
  print(pac_str)
199
211
  ```
200
212
  ```text
201
- >> 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:20250409T082814.766:T:FOO::1.1:20250409T082814.766:T:BAR::1.3:20250409T082814.766:F:BLUBB
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
202
214
  ```
203
215
  <!-- END EXAMPLES -->
204
216
 
@@ -206,7 +218,13 @@ print(pac_str)
206
218
 
207
219
  ## Change Log
208
220
 
221
+ ### v0.0.20
222
+ - bugfix in TREX table to dict conversion
223
+ - markdown compatible validation printing
224
+
209
225
  ### v0.0.19
210
226
  - supports PAC-ID, PAC-CAT, TREX and DisplayName
211
227
  - QR generation
212
228
  - ok-ish test coverage
229
+
230
+
@@ -1,7 +1,6 @@
1
- labfreed/__init__.py,sha256=6YWGHiMitcGiwwX9TPLO5MUlsimAgua8aP-e6yoW8-k,88
2
- labfreed/validation.py,sha256=QwkZWJhAjWbPUZtJJwjVYsw9TxeFhdbZaKjrPPIpuAA,5937
1
+ labfreed/__init__.py,sha256=JJg9mHM5goSWphrIerAaoiUjcOEZ7AXqGJIlmFog-pA,88
2
+ labfreed/validation.py,sha256=he9utRxQwks4ro94AVi8t5rU4jgRcA-6uz1XEmqoAnM,6359
3
3
  labfreed/DisplayNameExtension/DisplayNameExtension.py,sha256=l9JZY2eRS0V-H5h3-WXIHiiBJuljns-_e_t9Bp84_CU,1155
4
- labfreed/IO/generate_label.py,sha256=9ydpD68E7ztecEPXydw40eT7KV4FhAHvzmLidvYxHWI,2661
5
4
  labfreed/IO/generate_qr.py,sha256=wdZSf51Id03xSY8liK2RfB7WyGAw9O4s0VhZzrkAa-g,16680
6
5
  labfreed/IO/parse_pac.py,sha256=2c-HXkiQdUrGTL8zGb5CmO9l6ZrCb07rrTMMKdMi3_o,6253
7
6
  labfreed/PAC_CAT/__init__.py,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
@@ -10,13 +9,13 @@ labfreed/PAC_ID/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
9
  labfreed/PAC_ID/data_model.py,sha256=g09qgC-TV6fjJw9VyDF6mTJ6co2i2RKZc0Z-BmiiUIQ,7483
11
10
  labfreed/PAC_ID/extensions.py,sha256=YKIE-aFf1jdL4sqCqUe3txjnP8-dA2zCJrT5lBSjvuE,1092
12
11
  labfreed/TREX/UneceUnits.json,sha256=kwfQSp_nTuWbADfBBgqTWrvPl6XtM5SedEVLbMJrM7M,898953
13
- labfreed/TREX/data_model.py,sha256=neKYBc5_S4t-v86DSaWLq81VJF4oS6eFUch3ChPTYJA,29705
12
+ labfreed/TREX/data_model.py,sha256=tGgjp76wbS1MSS1Ep842CZyintsbecTZrlapj8WwGH8,29704
14
13
  labfreed/TREX/parse.py,sha256=86962VEJpkrTcT436iFIB5dNed5WHABzpjxRjkA3PXo,2043
15
14
  labfreed/TREX/unece_units.py,sha256=scPKdsPzY1neAdFOhA08_tRZaR-yplM8mBhIzzDqZBk,3006
16
15
  labfreed/utilities/base36.py,sha256=_yX8aQ1OwrK5tnJU1NUEzQSFGr9xAVnNvPObpNzCPYs,2895
17
16
  labfreed/utilities/utility_types.py,sha256=dM0qZgshF3cHJThVzia7UIAOdkNLKukAaaduLqKSaMY,2195
18
17
  labfreed/utilities/well_known_keys.py,sha256=nqk66kHdSwJTJfMKlP-xQbBglS8F_NoWsGkfOVITFN0,331
19
- labfreed-0.0.19.dist-info/licenses/LICENSE,sha256=gHFOv9FRKHxO8cInP3YXyPoJnuNeqrvcHjaE_wPSsQ8,1100
20
- labfreed-0.0.19.dist-info/WHEEL,sha256=Dyt6SBfaasWElUrURkknVFAZDHSTwxg3PaTza7RSbkY,100
21
- labfreed-0.0.19.dist-info/METADATA,sha256=hxfeVBwFlFMSA9-tGCnva---qoMx6KQvgmf6z9tyjP4,6255
22
- labfreed-0.0.19.dist-info/RECORD,,
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,,
@@ -1,81 +0,0 @@
1
- import os
2
-
3
- from .generate_qr import generate_qr_with_markers_svg
4
-
5
- from labfreed.PAC_ID.data_model import PACID
6
- from labfreed.DisplayNameExtension.DisplayNameExtension import DisplayNames
7
- from labfreed.IO.parse_pac import PACID_With_Extensions
8
-
9
-
10
-
11
-
12
-
13
- def generate_label_200_100(pac_url, pac:PACID_With_Extensions):
14
- title, infos = get_label_fields(pac)
15
- pac_svg = generate_qr_with_markers_svg(pac_url, height=60, width=100, border=0)
16
- label = _generate_label(pac_svg, 200, 100, title, infos)
17
- return label
18
-
19
- def generate_label_credit_card_size(pac_url, pac:PACID_With_Extensions):
20
- title, infos = get_label_fields(pac)
21
- pac_svg = generate_qr_with_markers_svg(pac_url, height=100, width=200, border=0)
22
- label = _generate_label(pac_svg, 240, 150, title, infos)
23
- return label
24
-
25
-
26
- def _generate_label(qr_svg, width, height, title=None, infos=[]):
27
- if not qr_svg:
28
- raise ValueError("no valid qr given")
29
- env = Environment(
30
- loader=FileSystemLoader(os.path.join(os.path.dirname(__file__), "templates")),
31
- autoescape=select_autoescape()
32
- )
33
- template = env.get_template("pac_label.jinja.svg")
34
- svg = template.render(width=width, height= height, pac_qr=qr_svg, title=title, info1=infos[0], info2=infos[1], info3=infos[2])
35
-
36
- return svg
37
-
38
-
39
-
40
- def get_label_fields(pac:PACID_With_Extensions) -> tuple[str, list[tuple[str, str]]]:
41
- '''
42
- returns a list of exactly length 3. Containing either info tuples (key value) or None
43
- '''
44
- if dn_extension := next((e for e in pac.extensions if isinstance(e, DisplayNames)), None): #find extension of type DisplayName
45
- title = dn_extension.display_names[0]
46
- else:
47
- title = ""
48
-
49
- infos = []
50
- cat = pac.pac_id.identifier.categories[0]
51
- for s in cat.segments:
52
- lbl = pretty_print_segment_label(cat.key, s.key)
53
- infos.append((lbl, s.value))
54
-
55
- while len(infos) < 3:
56
- infos.append(None)
57
-
58
- if len(infos) > 3:
59
- infos = infos[0:3]
60
-
61
- return title,infos
62
-
63
-
64
- def pretty_print_segment_label(category:str, segment_key:str):
65
- if not segment_key:
66
- return 'no key'
67
-
68
- cat = CAT_from_category_key(category)
69
- if cat:
70
- alias_to_field = {v.alias: k for k, v in cat.model_fields.items() if v.alias}
71
- segment_label = alias_to_field.get(segment_key, segment_key)
72
- segment_label = segment_label.replace('_', ' ').title()
73
-
74
- segment_label = segment_label.replace('Id', 'ID')
75
-
76
- else:
77
- segment_label = segment_key
78
-
79
- return segment_label
80
-
81
-