labfreed 0.2.6a6__py3-none-any.whl → 0.2.8__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.

Files changed (44) hide show
  1. labfreed/__init__.py +11 -11
  2. labfreed/labfreed_infrastructure.py +258 -258
  3. labfreed/pac_cat/__init__.py +19 -19
  4. labfreed/pac_cat/category_base.py +51 -51
  5. labfreed/pac_cat/pac_cat.py +150 -150
  6. labfreed/pac_cat/predefined_categories.py +200 -200
  7. labfreed/pac_id/__init__.py +19 -19
  8. labfreed/pac_id/extension.py +48 -48
  9. labfreed/pac_id/id_segment.py +89 -89
  10. labfreed/pac_id/pac_id.py +140 -140
  11. labfreed/pac_id/url_parser.py +155 -155
  12. labfreed/pac_id/url_serializer.py +84 -80
  13. labfreed/pac_id_resolver/__init__.py +2 -2
  14. labfreed/pac_id_resolver/cit_common.py +81 -81
  15. labfreed/pac_id_resolver/cit_v1.py +244 -247
  16. labfreed/pac_id_resolver/cit_v2.py +313 -313
  17. labfreed/pac_id_resolver/resolver.py +97 -98
  18. labfreed/pac_id_resolver/services.py +82 -79
  19. labfreed/qr/__init__.py +1 -1
  20. labfreed/qr/generate_qr.py +422 -422
  21. labfreed/trex/__init__.py +16 -16
  22. labfreed/trex/python_convenience/__init__.py +3 -3
  23. labfreed/trex/python_convenience/data_table.py +87 -87
  24. labfreed/trex/python_convenience/pyTREX.py +248 -248
  25. labfreed/trex/python_convenience/quantity.py +66 -66
  26. labfreed/trex/table_segment.py +245 -245
  27. labfreed/trex/trex.py +69 -69
  28. labfreed/trex/trex_base_models.py +209 -209
  29. labfreed/trex/value_segments.py +99 -99
  30. labfreed/utilities/base36.py +82 -82
  31. labfreed/well_known_extensions/__init__.py +4 -4
  32. labfreed/well_known_extensions/default_extension_interpreters.py +6 -6
  33. labfreed/well_known_extensions/display_name_extension.py +40 -40
  34. labfreed/well_known_extensions/trex_extension.py +30 -30
  35. labfreed/well_known_keys/gs1/__init__.py +5 -5
  36. labfreed/well_known_keys/gs1/gs1.py +3 -3
  37. labfreed/well_known_keys/labfreed/well_known_keys.py +15 -15
  38. labfreed/well_known_keys/unece/__init__.py +3 -3
  39. labfreed/well_known_keys/unece/unece_units.py +67 -67
  40. {labfreed-0.2.6a6.dist-info → labfreed-0.2.8.dist-info}/METADATA +36 -21
  41. labfreed-0.2.8.dist-info/RECORD +45 -0
  42. {labfreed-0.2.6a6.dist-info → labfreed-0.2.8.dist-info}/licenses/LICENSE +21 -21
  43. labfreed-0.2.6a6.dist-info/RECORD +0 -45
  44. {labfreed-0.2.6a6.dist-info → labfreed-0.2.8.dist-info}/WHEEL +0 -0
@@ -1,82 +1,82 @@
1
- import re
2
- import string
3
-
4
- from pydantic import field_validator, RootModel
5
-
6
- class base36(RootModel[str]):
7
- @field_validator('root')
8
- @classmethod
9
- def validate_format(cls, v: str) -> str:
10
- if not re.fullmatch(r'[A-Z0-9]*', v):
11
- raise ValueError("Value must only contain uppercase letters and digits (A-Z, 0-9)")
12
- return v
13
-
14
-
15
- def to_base36(s:str) -> base36:
16
- """Takes a string, encodes it in UTF-8 and then as base36 string."""
17
- utf8_encoded = s.encode('utf-8')
18
- num = int.from_bytes(utf8_encoded, byteorder='big', signed=False)
19
-
20
- # note: this cannot be arbitrarily chosen. The choice here corresponds to what pythons int(s:str, base:int=10) function used.
21
- base36_chars = _alphabet(base=36)
22
- if num == 0:
23
- return base36_chars[0]
24
- base_36 = []
25
- _num = num
26
- while _num:
27
- _num, i = divmod(_num, 36)
28
- base_36.append(base36_chars[i])
29
- b36_str = ''.join(reversed(base_36))
30
- b36_str = base36(b36_str)
31
- return b36_str
32
-
33
-
34
- def from_base36(s36:base36) -> str:
35
- """inverse of to_base36"""
36
- # this built in function interprets each character as number in a base represented by the standartd alphabet [0-9 (A-Z|a-z)][0:base] it is case INsensitive.
37
- num = int(s36, 36)
38
- num_bytes = (num.bit_length() + 7) // 8
39
- _bytes = num.to_bytes(num_bytes, byteorder='big')
40
- s = _bytes.decode('utf-8')
41
- return s
42
-
43
-
44
- def _alphabet(base):
45
- """ returns an alphabet, which corresponds to what pythons int(s:str, base:int=10) function used.
46
- """
47
- if base < 2 or base > 36:
48
- ValueError('base can only be between 2 and 36')
49
- alphabet = (string.digits + string.ascii_uppercase)[0:base]
50
- return alphabet
51
-
52
-
53
- if __name__ == "__main__":
54
- ss = ["A",
55
- "B-500 B",
56
- "B-500 Ba",
57
- "B-500 Bal",
58
- "B-500 Bala",
59
- "B-500 Balanc",
60
- "B-500 Balance",
61
- "B-500 D",
62
- "Mini Spray Dryer S-300",
63
- "w3ApashAt!!£NAGDSAF*ç%&/()",
64
- "HELLOWORLD",
65
- "Helloworld",
66
- "$£äö!'?^{]<@#¦&¬|¢)&§°😀你好🌍🏯😇🎵🔥你👻🐉😀你好🌍🏯😇🎵🔥你👻🐉😀你好🌍🏯😇🎵🔥你👻🐉😀你好🌍🏯😇🎵🔥你👻🐉😀你好🌍🏯😇🎵🔥你👻🐉😀你好🌍🏯😇🎵🔥你👻🐉😀你好🌍🏯😇🎵🔥你👻🐉",
67
- "往跟住!師立甲錯什正再圓身升因月室",
68
- "Balance BAL500 @☣️Lab",
69
- "BAL500 @☣️Lab",
70
- "BAL-CLEAN",
71
- "Smørrebrød µ-Nutrients",
72
- "Demo Result from R-300",
73
- "Rotavapor R-300",
74
- "Rotavapor R-250",
75
- "Rotavapor R-220",
76
- "SyncorePlus"
77
- ]
78
- for s in ss:
79
- s36 = to_base36(s)
80
- s_back = from_base36(s36)
81
- identical = (s == s_back)
82
- print(f'{s} >> {s36} >> {s_back}: match:{identical}')
1
+ import re
2
+ import string
3
+
4
+ from pydantic import field_validator, RootModel
5
+
6
+ class base36(RootModel[str]):
7
+ @field_validator('root')
8
+ @classmethod
9
+ def validate_format(cls, v: str) -> str:
10
+ if not re.fullmatch(r'[A-Z0-9]*', v):
11
+ raise ValueError("Value must only contain uppercase letters and digits (A-Z, 0-9)")
12
+ return v
13
+
14
+
15
+ def to_base36(s:str) -> base36:
16
+ """Takes a string, encodes it in UTF-8 and then as base36 string."""
17
+ utf8_encoded = s.encode('utf-8')
18
+ num = int.from_bytes(utf8_encoded, byteorder='big', signed=False)
19
+
20
+ # note: this cannot be arbitrarily chosen. The choice here corresponds to what pythons int(s:str, base:int=10) function used.
21
+ base36_chars = _alphabet(base=36)
22
+ if num == 0:
23
+ return base36_chars[0]
24
+ base_36 = []
25
+ _num = num
26
+ while _num:
27
+ _num, i = divmod(_num, 36)
28
+ base_36.append(base36_chars[i])
29
+ b36_str = ''.join(reversed(base_36))
30
+ b36_str = base36(b36_str)
31
+ return b36_str
32
+
33
+
34
+ def from_base36(s36:base36) -> str:
35
+ """inverse of to_base36"""
36
+ # this built in function interprets each character as number in a base represented by the standartd alphabet [0-9 (A-Z|a-z)][0:base] it is case INsensitive.
37
+ num = int(s36, 36)
38
+ num_bytes = (num.bit_length() + 7) // 8
39
+ _bytes = num.to_bytes(num_bytes, byteorder='big')
40
+ s = _bytes.decode('utf-8')
41
+ return s
42
+
43
+
44
+ def _alphabet(base):
45
+ """ returns an alphabet, which corresponds to what pythons int(s:str, base:int=10) function used.
46
+ """
47
+ if base < 2 or base > 36:
48
+ ValueError('base can only be between 2 and 36')
49
+ alphabet = (string.digits + string.ascii_uppercase)[0:base]
50
+ return alphabet
51
+
52
+
53
+ if __name__ == "__main__":
54
+ ss = ["A",
55
+ "B-500 B",
56
+ "B-500 Ba",
57
+ "B-500 Bal",
58
+ "B-500 Bala",
59
+ "B-500 Balanc",
60
+ "B-500 Balance",
61
+ "B-500 D",
62
+ "Mini Spray Dryer S-300",
63
+ "w3ApashAt!!£NAGDSAF*ç%&/()",
64
+ "HELLOWORLD",
65
+ "Helloworld",
66
+ "$£äö!'?^{]<@#¦&¬|¢)&§°😀你好🌍🏯😇🎵🔥你👻🐉😀你好🌍🏯😇🎵🔥你👻🐉😀你好🌍🏯😇🎵🔥你👻🐉😀你好🌍🏯😇🎵🔥你👻🐉😀你好🌍🏯😇🎵🔥你👻🐉😀你好🌍🏯😇🎵🔥你👻🐉😀你好🌍🏯😇🎵🔥你👻🐉",
67
+ "往跟住!師立甲錯什正再圓身升因月室",
68
+ "Balance BAL500 @☣️Lab",
69
+ "BAL500 @☣️Lab",
70
+ "BAL-CLEAN",
71
+ "Smørrebrød µ-Nutrients",
72
+ "Demo Result from R-300",
73
+ "Rotavapor R-300",
74
+ "Rotavapor R-250",
75
+ "Rotavapor R-220",
76
+ "SyncorePlus"
77
+ ]
78
+ for s in ss:
79
+ s36 = to_base36(s)
80
+ s_back = from_base36(s36)
81
+ identical = (s == s_back)
82
+ print(f'{s} >> {s36} >> {s_back}: match:{identical}')
@@ -1,5 +1,5 @@
1
- from .display_name_extension import DisplayNameExtension
2
- from .trex_extension import TREX_Extension
3
- from .default_extension_interpreters import default_extension_interpreters # noqa: F401
4
-
1
+ from .display_name_extension import DisplayNameExtension
2
+ from .trex_extension import TREX_Extension
3
+ from .default_extension_interpreters import default_extension_interpreters # noqa: F401
4
+
5
5
  __all__ = ["DisplayNameExtension", "TREX_Extension"]
@@ -1,7 +1,7 @@
1
- from .display_name_extension import DisplayNameExtension
2
- from .trex_extension import TREX_Extension
3
-
4
- default_extension_interpreters = {
5
- 'TREX': TREX_Extension,
6
- 'N': DisplayNameExtension
1
+ from .display_name_extension import DisplayNameExtension
2
+ from .trex_extension import TREX_Extension
3
+
4
+ default_extension_interpreters = {
5
+ 'TREX': TREX_Extension,
6
+ 'N': DisplayNameExtension
7
7
  }
@@ -1,40 +1,40 @@
1
- import logging
2
- from typing import Literal, Self
3
- from pydantic import computed_field
4
- from labfreed.labfreed_infrastructure import LabFREED_BaseModel
5
- from labfreed.pac_id.extension import ExtensionBase
6
- from labfreed.utilities.base36 import from_base36, to_base36
7
-
8
-
9
- class DisplayNameExtension(ExtensionBase, LabFREED_BaseModel):
10
- name:Literal['N'] = 'N'
11
- type:Literal['N'] = 'N'
12
- display_name: str
13
-
14
- @computed_field
15
- @property
16
- def data(self)->str:
17
- # return '/'.join([to_base36(dn) for dn in self.display_name])
18
- return to_base36(self.display_name).root
19
-
20
- @staticmethod
21
- def from_extension(ext:ExtensionBase) -> Self:
22
- return DisplayNameExtension.create(name=ext.name,
23
- type=ext.type,
24
- data=ext.data)
25
-
26
- @staticmethod
27
- def create(*, name, type, data):
28
- if name != 'N':
29
- logging.warning(f'Name {name} was given, but this extension should only be used with name "N". Will ignore input')
30
-
31
- if type != 'N':
32
- logging.warning(f'Type {name} was given, but this extension should only be used with type "N". Will try to parse data as display names')
33
-
34
- display_name = from_base36(data)
35
-
36
- return DisplayNameExtension(display_name=display_name)
37
-
38
- def __str__(self):
39
- return 'Display name: '+ self.display_name
40
-
1
+ import logging
2
+ from typing import Literal, Self
3
+ from pydantic import computed_field
4
+ from labfreed.labfreed_infrastructure import LabFREED_BaseModel
5
+ from labfreed.pac_id.extension import ExtensionBase
6
+ from labfreed.utilities.base36 import from_base36, to_base36
7
+
8
+
9
+ class DisplayNameExtension(ExtensionBase, LabFREED_BaseModel):
10
+ name:Literal['N'] = 'N'
11
+ type:Literal['N'] = 'N'
12
+ display_name: str
13
+
14
+ @computed_field
15
+ @property
16
+ def data(self)->str:
17
+ # return '/'.join([to_base36(dn) for dn in self.display_name])
18
+ return to_base36(self.display_name).root
19
+
20
+ @staticmethod
21
+ def from_extension(ext:ExtensionBase) -> Self:
22
+ return DisplayNameExtension.create(name=ext.name,
23
+ type=ext.type,
24
+ data=ext.data)
25
+
26
+ @staticmethod
27
+ def create(*, name, type, data):
28
+ if name != 'N':
29
+ logging.warning(f'Name {name} was given, but this extension should only be used with name "N". Will ignore input')
30
+
31
+ if type != 'N':
32
+ logging.warning(f'Type {name} was given, but this extension should only be used with type "N". Will try to parse data as display names')
33
+
34
+ display_name = from_base36(data)
35
+
36
+ return DisplayNameExtension(display_name=display_name)
37
+
38
+ def __str__(self):
39
+ return 'Display name: '+ self.display_name
40
+
@@ -1,31 +1,31 @@
1
- from typing import Literal, Self
2
-
3
- from pydantic import computed_field
4
- from labfreed.labfreed_infrastructure import LabFREED_BaseModel
5
- from labfreed.pac_id.extension import ExtensionBase
6
- from labfreed.trex.trex import TREX
7
-
8
-
9
- class TREX_Extension(ExtensionBase, LabFREED_BaseModel):
10
- name:str
11
- type:Literal['TREX'] = 'TREX'
12
- trex:TREX
13
-
14
- @computed_field
15
- @property
16
- def data(self)->str:
17
- trex_str = self.trex.serialize()
18
- return trex_str
19
-
20
- @staticmethod
21
- def from_extension(ext:ExtensionBase) -> Self:
22
- return TREX_Extension.create(name=ext.name,
23
- type=ext.type,
24
- data=ext.data)
25
-
26
- @staticmethod
27
- def create(*, name, data, type='TREX'):
28
- trex_extension = TREX_Extension(name= name, trex = TREX.deserialize(data))
29
- return trex_extension
30
-
1
+ from typing import Literal, Self
2
+
3
+ from pydantic import computed_field
4
+ from labfreed.labfreed_infrastructure import LabFREED_BaseModel
5
+ from labfreed.pac_id.extension import ExtensionBase
6
+ from labfreed.trex.trex import TREX
7
+
8
+
9
+ class TREX_Extension(ExtensionBase, LabFREED_BaseModel):
10
+ name:str
11
+ type:Literal['TREX'] = 'TREX'
12
+ trex:TREX
13
+
14
+ @computed_field
15
+ @property
16
+ def data(self)->str:
17
+ trex_str = self.trex.serialize()
18
+ return trex_str
19
+
20
+ @staticmethod
21
+ def from_extension(ext:ExtensionBase) -> Self:
22
+ return TREX_Extension.create(name=ext.name,
23
+ type=ext.type,
24
+ data=ext.data)
25
+
26
+ @staticmethod
27
+ def create(*, name, data, type='TREX'):
28
+ trex_extension = TREX_Extension(name= name, trex = TREX.deserialize(data))
29
+ return trex_extension
30
+
31
31
 
@@ -1,6 +1,6 @@
1
- '''
2
- Data from
3
- https://ref.gs1.org/ai/GS1_Application_Identifiers.jsonld
4
-
5
- processes by ChatGPT
1
+ '''
2
+ Data from
3
+ https://ref.gs1.org/ai/GS1_Application_Identifiers.jsonld
4
+
5
+ processes by ChatGPT
6
6
  '''
@@ -1,4 +1,4 @@
1
- '''
2
- Data from
3
- https://ref.gs1.org/ai/GS1_Application_Identifiers.jsonld
1
+ '''
2
+ Data from
3
+ https://ref.gs1.org/ai/GS1_Application_Identifiers.jsonld
4
4
  '''
@@ -1,16 +1,16 @@
1
- from enum import Enum
2
-
3
-
4
- class WellKnownKeys(Enum):
5
- GTIN = '01'
6
- BATCH = '10'
7
- SERIAL = '21'
8
- ADDITIONAL_IDINTIFIER = '240'
9
- RUN_ID_ABSOLUTE = 'RNR'
10
- SAMPLE_ID = 'SMP'
11
- EXPERIMENT_ID = 'EXP'
12
- RESULT_ID = 'RST'
13
- METHOD_ID = 'MTD'
14
- REPORT_ID = 'RPT'
15
- TIMESTAMP = 'TS'
1
+ from enum import Enum
2
+
3
+
4
+ class WellKnownKeys(Enum):
5
+ GTIN = '01'
6
+ BATCH = '10'
7
+ SERIAL = '21'
8
+ ADDITIONAL_IDINTIFIER = '240'
9
+ RUN_ID_ABSOLUTE = 'RNR'
10
+ SAMPLE_ID = 'SMP'
11
+ EXPERIMENT_ID = 'EXP'
12
+ RESULT_ID = 'RST'
13
+ METHOD_ID = 'MTD'
14
+ REPORT_ID = 'RPT'
15
+ TIMESTAMP = 'TS'
16
16
  VERSION = 'V'
@@ -1,4 +1,4 @@
1
- '''
2
- Data from
3
- https://github.com/quadient/unece-units/blob/main/python/src/unece_excel_parser/parsedUneceUnits.json
1
+ '''
2
+ Data from
3
+ https://github.com/quadient/unece-units/blob/main/python/src/unece_excel_parser/parsedUneceUnits.json
4
4
  '''
@@ -1,68 +1,68 @@
1
- from functools import cache
2
- import json
3
- from pathlib import Path
4
-
5
-
6
-
7
-
8
- @cache
9
- def unece_units() -> list[dict]:
10
- p = Path(__file__).parent / 'UneceUnits.json'
11
- with open(p) as f:
12
- l = json.load(f) # noqa: E741
13
- return l
14
-
15
- @cache
16
- def unece_unit_codes():
17
- codes= [u.get('commonCode') for u in unece_units() if u.get('state') == 'ACTIVE']
18
- return codes
19
-
20
-
21
- def unece_unit(unit_code):
22
- unit = [u for u in unece_units() if u['commonCode'] == unit_code]
23
- if len(unit) == 0:
24
- return None
25
- else:
26
- return unit[0]
27
-
28
- def unit_symbol(unit:dict) ->str:
29
- return unit.get('symbol')
30
-
31
- def unit_name(unit:dict) ->str:
32
- return unit.get('name')
33
-
34
-
35
-
36
- # def check_compatibility_unece_quantities():
37
- # unece = unece_units()
38
- # print(f'Number of units in file: {len(unece)}')
39
-
40
- # failed = list()
41
- # success = list()
42
- # for u in unece:
43
- # if u.get('state') == 'ACTIVE':
44
- # try:
45
- # if not u.get('symbol'):
46
- # assert False
47
- # u.get('name')
48
- # validate_unit(u.get('symbol'))
49
- # success.append(u)
50
- # except AssertionError:
51
- # failed.append(u)
52
- # else:
53
- # pass
54
-
55
-
56
-
57
- # print('[blue] FAILED [/blue]')
58
- # for u in failed:
59
- # print(f'{u.get('commonCode')}: {u.get('name')}')
60
-
61
- # print('[yellow] SUCCESSFUL [/yellow]')
62
- # for u in success:
63
- # print(u)
64
-
65
- # print(f'{len(failed)} / {len(unece)} failed to convert')
66
-
67
-
1
+ from functools import cache
2
+ import json
3
+ from pathlib import Path
4
+
5
+
6
+
7
+
8
+ @cache
9
+ def unece_units() -> list[dict]:
10
+ p = Path(__file__).parent / 'UneceUnits.json'
11
+ with open(p) as f:
12
+ l = json.load(f) # noqa: E741
13
+ return l
14
+
15
+ @cache
16
+ def unece_unit_codes():
17
+ codes= [u.get('commonCode') for u in unece_units() if u.get('state') == 'ACTIVE']
18
+ return codes
19
+
20
+
21
+ def unece_unit(unit_code):
22
+ unit = [u for u in unece_units() if u['commonCode'] == unit_code]
23
+ if len(unit) == 0:
24
+ return None
25
+ else:
26
+ return unit[0]
27
+
28
+ def unit_symbol(unit:dict) ->str:
29
+ return unit.get('symbol')
30
+
31
+ def unit_name(unit:dict) ->str:
32
+ return unit.get('name')
33
+
34
+
35
+
36
+ # def check_compatibility_unece_quantities():
37
+ # unece = unece_units()
38
+ # print(f'Number of units in file: {len(unece)}')
39
+
40
+ # failed = list()
41
+ # success = list()
42
+ # for u in unece:
43
+ # if u.get('state') == 'ACTIVE':
44
+ # try:
45
+ # if not u.get('symbol'):
46
+ # assert False
47
+ # u.get('name')
48
+ # validate_unit(u.get('symbol'))
49
+ # success.append(u)
50
+ # except AssertionError:
51
+ # failed.append(u)
52
+ # else:
53
+ # pass
54
+
55
+
56
+
57
+ # print('[blue] FAILED [/blue]')
58
+ # for u in failed:
59
+ # print(f'{u.get('commonCode')}: {u.get('name')}')
60
+
61
+ # print('[yellow] SUCCESSFUL [/yellow]')
62
+ # for u in success:
63
+ # print(u)
64
+
65
+ # print(f'{len(failed)} / {len(unece)} failed to convert')
66
+
67
+
68
68