commonlib-reader 1.1.0__tar.gz → 1.1.2__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
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: commonlib-reader
3
- Version: 1.1.0
3
+ Version: 1.1.2
4
4
  Summary: Reader for Equinor commonlib api.
5
5
  License: MIT
6
6
  Author: Åsmund Våge Fannemel
@@ -12,6 +12,7 @@ Classifier: Programming Language :: Python :: 3.10
12
12
  Classifier: Programming Language :: Python :: 3.11
13
13
  Classifier: Programming Language :: Python :: 3.12
14
14
  Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
15
16
  Requires-Dist: eq-api-connector (>=1.0.0,<2.0.0)
16
17
  Requires-Dist: pandas (>=2.1.4)
17
18
  Requires-Dist: requests (>=2.32.4)
@@ -1,17 +1,18 @@
1
1
  from commonlib_reader.utils import (
2
2
  get_code,
3
3
  get_code_param,
4
- get_disciplines,
5
4
  get_library_names,
6
5
  )
7
6
 
8
7
 
8
+ from .discipline import Discipline
9
9
  from .tag import TagType, TagCategory, TagFormat
10
10
  from .ims import IMS
11
11
  from .facility import Facility
12
12
  from .unit import Unit
13
13
 
14
14
  __all__ = [
15
+ "Discipline",
15
16
  "Facility",
16
17
  "IMS",
17
18
  "TagType",
@@ -20,6 +21,5 @@ __all__ = [
20
21
  "Unit",
21
22
  "get_code",
22
23
  "get_code_param",
23
- "get_disciplines",
24
24
  "get_library_names",
25
25
  ]
@@ -0,0 +1,64 @@
1
+ from typing import List
2
+
3
+ from commonlib_reader.utils import get_code
4
+
5
+
6
+ class Discipline:
7
+ def __init__(self, data: dict):
8
+ if not isinstance(data, dict):
9
+ raise ValueError("Input data shall be dictionary.")
10
+
11
+ self._data = data
12
+
13
+ def __eq__(self, other):
14
+ if isinstance(other, Discipline):
15
+ return self._data == other._data
16
+
17
+ return False
18
+
19
+ def __str__(self):
20
+ return f"Discipline: {self.name}-{self.description}"
21
+
22
+ @property
23
+ def name(self) -> str:
24
+ return self._data.get("name", "")
25
+
26
+ @property
27
+ def description(self) -> str:
28
+ return self._data.get("description", "")
29
+
30
+ @property
31
+ def identity(self) -> str:
32
+ return self._data.get("identity", "")
33
+
34
+ @property
35
+ def is_valid(self) -> bool:
36
+ return self._data.get("isValid", False)
37
+
38
+ @classmethod
39
+ def get_all(cls, scope: str, only_valid: bool = True) -> List["Discipline"]:
40
+ """Get all disciplines for
41
+
42
+ Raises:
43
+ ValueError: _description_
44
+
45
+ Returns:
46
+ List["Discipline"]: List of discipline objects
47
+ """
48
+ dis_data = get_code("Discipline", scope=scope)
49
+
50
+ if not isinstance(dis_data, list) or not all(
51
+ isinstance(x, dict) for x in dis_data
52
+ ):
53
+ raise ValueError("Invalid discipline data from api")
54
+
55
+ if len(dis_data) == 0:
56
+ raise ValueError(
57
+ f"No discipline data found for scope {scope}. Verify that scope is correct."
58
+ )
59
+
60
+ dis = [Discipline(x) for x in dis_data] # type: ignore
61
+ if only_valid:
62
+ dis = [x for x in dis if x.is_valid]
63
+
64
+ return sorted(dis, key=lambda d: d.identity)
@@ -85,7 +85,7 @@ class Facility:
85
85
  return self._attributes.get("ParentFacility", "")
86
86
 
87
87
  @property
88
- def npd_id(self):
88
+ def npd_id(self) -> str:
89
89
  return self._attributes.get("NPDID", "")
90
90
 
91
91
  @property
@@ -218,6 +218,38 @@ class Facility:
218
218
  f = Facility._get_all_facility_data()
219
219
  return [Facility(x["identity"]) for x in f]
220
220
 
221
+ @classmethod
222
+ def get_stid_facilities(cls) -> List["Facility"]:
223
+ fac = cls.get_all_facilities()
224
+ return [f for f in fac if f.is_stid]
225
+
226
+ @classmethod
227
+ def get_sap_facilities(cls) -> List["Facility"]:
228
+ fac = cls.get_all_facilities()
229
+ return [f for f in fac if len(f.sap) > 0]
230
+
231
+ @classmethod
232
+ def get_ioc_facilities(cls) -> List["Facility"]:
233
+ fac = cls.get_all_facilities()
234
+ return [f for f in fac if len(f.ioc_plant) > 0]
235
+
236
+ @classmethod
237
+ def get_gov_facilities(cls) -> List["Facility"]:
238
+ fac = cls.get_all_facilities()
239
+ return [f for f in fac if len(f.governmental_name) > 0]
240
+
241
+ @classmethod
242
+ def get_ioc_plant_names(cls) -> List[str]:
243
+ fac = cls.get_all_facilities()
244
+ return list(set([f.ioc_plant for f in fac if len(f.ioc_plant) > 0]))
245
+
246
+ @classmethod
247
+ def get_gov_fcty_names(cls) -> List[str]:
248
+ fac = cls.get_all_facilities()
249
+ return list(
250
+ set([f.governmental_name for f in fac if len(f.governmental_name) > 0])
251
+ )
252
+
221
253
  @classmethod
222
254
  def _get_all_facility_data(cls) -> List[dict]:
223
255
  """
@@ -69,7 +69,7 @@ class TagFormatElement:
69
69
 
70
70
  @staticmethod
71
71
  def get_TagFormatElements(
72
- tag_format: Union["TagFormat", str]
72
+ tag_format: Union["TagFormat", str],
73
73
  ) -> List["TagFormatElement"]:
74
74
  if isinstance(tag_format, TagFormat):
75
75
  tag_format_id = tag_format.get_id()
@@ -140,7 +140,7 @@ class TagFormat:
140
140
  def __str__(self):
141
141
  return f"{self.description} - {self.tag_category}"
142
142
 
143
- def is_valid(self, tagNo: str):
143
+ def is_valid(self, tagNo: str) -> bool:
144
144
  """Check if input tag number matches this tag format.
145
145
  Args:
146
146
  tagNo (str): Tag number to check.
@@ -148,7 +148,7 @@ class TagFormat:
148
148
  bool: True if tag number matches this tag format, else False.
149
149
  """
150
150
 
151
- return re.fullmatch(self.regex, tagNo)
151
+ return bool(re.fullmatch(self.regex, tagNo))
152
152
 
153
153
  def get_id(self) -> int:
154
154
  """Get tagformat identity.
@@ -7,15 +7,15 @@ import requests
7
7
  from commonlib_reader.connector import get_connector
8
8
 
9
9
 
10
- def get_library_names():
10
+ def get_library_names() -> list[str]:
11
11
  library_names = get_connector().get_json(url="/api/Library/NameList")
12
- if isinstance(library_names, list):
13
- library_names.sort()
14
- return library_names
12
+ if isinstance(library_names, list) and all(
13
+ [isinstance(x, str) for x in library_names]
14
+ ):
15
+ library_names.sort() # type: ignore
16
+ return library_names # type: ignore
15
17
 
16
-
17
- def get_disciplines():
18
- return get_code("Discipline")
18
+ raise ValueError("Wrong data from API when getting library names.")
19
19
 
20
20
 
21
21
  def get_code(code: str, scope: Optional[str] = None, name: Optional[str] = None):
@@ -29,6 +29,15 @@ def get_code(code: str, scope: Optional[str] = None, name: Optional[str] = None)
29
29
 
30
30
 
31
31
  def get_code_param(code, params=None):
32
+ """_summary_
33
+
34
+ Args:
35
+ code (_type_): _description_
36
+ params (_type_, optional): _description_. Defaults to None.
37
+
38
+ Returns:
39
+ _type_: _description_
40
+ """
32
41
  if params is None:
33
42
  params = {}
34
43
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "commonlib-reader"
3
- version = "1.1.0"
3
+ version = "1.1.2"
4
4
  description = "Reader for Equinor commonlib api."
5
5
  authors = [
6
6
  { name = "Åsmund Våge Fannemel", email = "asmf@equinor.com" }