commonlib-reader 1.0.2__tar.gz → 1.0.3__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: commonlib-reader
3
- Version: 1.0.2
3
+ Version: 1.0.3
4
4
  Summary: Reader for Equinor commonlibapi.
5
5
  Home-page: https://github.com/equinor/commonlib-reader.git
6
6
  Author: Åsmund Våge Fannemel
@@ -22,7 +22,7 @@ class TagFormatElement:
22
22
 
23
23
  """
24
24
 
25
- def __init__(self, data):
25
+ def __init__(self, data: dict):
26
26
  """
27
27
  Initializes a TagFormatElement object.
28
28
 
@@ -134,14 +134,26 @@ class TagFormat:
134
134
 
135
135
  return self._tfe
136
136
 
137
- def split_tag(self, tagNo: str) -> dict:
138
- # Change naming pattern for groups to match python re format
139
- py_pattern = re.sub(r"\(\?<(\w+)>", r"(?P<\1>", self.regex_grouped)
137
+ def get_regex_grouped_named(self) -> str:
138
+ """Substitute codes with descriptions in grouped regex
140
139
 
141
- # Change group number with group description
140
+ Returns:
141
+ str: Regex grouped string where generic regex group names are replaced with tag format element description.
142
+ """
143
+ regex_group_named = self.regex_grouped
144
+ for e in self.get_tagformat_elements():
145
+ regex_group_named = regex_group_named.replace(
146
+ f"?<e{e.name}>", f"?<{e.description}>"
147
+ )
148
+
149
+ return regex_group_named
142
150
 
151
+ def split_tag(self, tagNo: str) -> dict:
152
+ # Change naming pattern for groups in commonlib-regex to match python re format
153
+ py_pattern = re.sub(r"\(\?<(\w+)>", r"(?P<\1>", self.regex_grouped)
143
154
  matches = re.match(py_pattern, tagNo)
144
155
 
156
+ # Tag format element descriptions may contain space and can not be used as group name in regex. Instead create dict where description is key.
145
157
  d = {}
146
158
  for e in self.get_tagformat_elements():
147
159
  group_name = f"e{e.name}"
@@ -458,7 +470,7 @@ class TagCategory:
458
470
  return f"{self.TagCategoryId}:{self.name} - {self.description}"
459
471
 
460
472
  @staticmethod
461
- def get_category(inst_code, name="") -> List["TagCategory"]:
473
+ def get_category(inst_code: str, name="") -> List["TagCategory"]:
462
474
  categories = _get_category_data(inst_code=inst_code)
463
475
  tc = [TagCategory(x, inst_code=inst_code) for x in categories]
464
476
  tc.sort(key=lambda x: x.TagCategoryId)
@@ -470,7 +482,7 @@ class TagCategory:
470
482
  return tc
471
483
 
472
484
 
473
- def _get_category_data(inst_code) -> List[dict]:
485
+ def _get_category_data(inst_code: str) -> List[dict]:
474
486
  """Get code table of tag categories for a facility from commonlibapi.
475
487
 
476
488
  Args:
@@ -6,7 +6,7 @@ from commonlib_reader.utils import get_code
6
6
  class Unit:
7
7
  _units = []
8
8
 
9
- def __init__(self, data):
9
+ def __init__(self, data: dict):
10
10
  self.name = ""
11
11
  self.description = ""
12
12
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "commonlib-reader"
3
- version = "1.0.2"
3
+ version = "1.0.3"
4
4
  description = "Reader for Equinor commonlibapi."
5
5
  authors = ["Åsmund Våge Fannemel <asmf@equinor.com>"]
6
6
  readme = "README.md"