tagreader 5.5.0__tar.gz → 6.0.0__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: tagreader
3
- Version: 5.5.0
3
+ Version: 6.0.0
4
4
  Summary: Tagreader is a Python package for reading trend data from the OSIsoft PI and Aspen Infoplus.21 IMS systems.
5
5
  Home-page: https://github.com/equinor/tagreader-python
6
6
  License: MIT
@@ -29,7 +29,7 @@ Provides-Extra: notebooks
29
29
  Requires-Dist: certifi (>=2024.7.4,<2025.0.0)
30
30
  Requires-Dist: diskcache (>=5.6.1,<6.0.0)
31
31
  Requires-Dist: matplotlib (>=3.7.0,<4.0.0) ; extra == "notebooks"
32
- Requires-Dist: msal-bearer (>=0.2.1,<1.1.0)
32
+ Requires-Dist: msal-bearer (>=0.2.1,<1.2.0)
33
33
  Requires-Dist: notebook (>=7.2.0,<8.0.0) ; extra == "notebooks"
34
34
  Requires-Dist: pandas (>=1)
35
35
  Requires-Dist: pycryptodome (>=3.20.0,<4.0.0)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "tagreader"
3
- version = "5.5.0"
3
+ version = "6.0.0"
4
4
  description = "Tagreader is a Python package for reading trend data from the OSIsoft PI and Aspen Infoplus.21 IMS systems."
5
5
  authors = ["Einar S. Idsø <eiids@equinor.com>", "Morten Dæhli Aslesen <masl@equinor.com"]
6
6
  license = "MIT"
@@ -33,7 +33,7 @@ pandas = ">=1"
33
33
  certifi = "^2024.7.4"
34
34
  requests = "^2"
35
35
  requests-kerberos = "^0"
36
- msal-bearer = ">=0.2.1,<1.1.0"
36
+ msal-bearer = ">=0.2.1,<1.2.0"
37
37
  notebook = { version = "^7.2.0", optional = true }
38
38
  matplotlib = { version = "^3.7.0", optional = true }
39
39
  diskcache = "^5.6.1"
@@ -19,7 +19,7 @@ from urllib3.exceptions import InsecureRequestWarning
19
19
 
20
20
  from tagreader.cache import BucketCache, SmartCache
21
21
  from tagreader.logger import logger
22
- from tagreader.utils import ReaderType, is_mac, is_windows, urljoin
22
+ from tagreader.utils import IMSType, ReaderType, is_mac, is_windows, urljoin
23
23
 
24
24
 
25
25
  class MD4:
@@ -144,6 +144,33 @@ def list_piwebapi_sources(
144
144
  logger.error(f"Could not decode JSON response: {e}")
145
145
 
146
146
 
147
+ def get_piwebapi_source_to_webid_dict(
148
+ url: Optional[str] = None,
149
+ auth: Optional[Any] = None,
150
+ verify_ssl: Optional[bool] = True,
151
+ ) -> List[str]:
152
+ if url is None:
153
+ url = get_url_pi()
154
+
155
+ if auth is None:
156
+ auth = get_auth_pi()
157
+
158
+ if verify_ssl is None:
159
+ verify_ssl = get_verify_ssl()
160
+
161
+ if verify_ssl is False:
162
+ urllib3.disable_warnings(InsecureRequestWarning)
163
+
164
+ url_ = urljoin(url, "dataservers")
165
+ res = requests.get(url_, auth=auth, verify=verify_ssl)
166
+
167
+ res.raise_for_status()
168
+ try:
169
+ return {item["Name"]: item["WebId"] for item in res.json()["Items"]}
170
+ except JSONDecodeError as e:
171
+ logger.error(f"Could not decode JSON response: {e}")
172
+
173
+
147
174
  class BaseHandlerWeb(ABC):
148
175
  def __init__(
149
176
  self,
@@ -741,11 +768,10 @@ class PIHandlerWeb(BaseHandlerWeb):
741
768
  )
742
769
 
743
770
  @staticmethod
744
- def generate_search_query(
771
+ def generate_search_params(
745
772
  tag: Optional[str],
746
773
  desc: Optional[str],
747
774
  datasource: Optional[str],
748
- max: Optional[int] = 100,
749
775
  ) -> Dict[str, str]:
750
776
  q = []
751
777
  if tag is not None:
@@ -753,10 +779,12 @@ class PIHandlerWeb(BaseHandlerWeb):
753
779
  if desc is not None:
754
780
  q.extend([f"description:{PIHandlerWeb.escape(desc)}"])
755
781
  query = " AND ".join(q)
756
- params = {"q": f"{query}"}
782
+ params = {"query": f"{query}"}
757
783
 
758
784
  if datasource is not None:
759
- params["scope"] = f"pi:{datasource}"
785
+ params["dataserverwebid"] = (
786
+ f"{get_piwebapi_source_to_webid_dict()[datasource]}"
787
+ )
760
788
 
761
789
  return params
762
790
 
@@ -866,23 +894,23 @@ class PIHandlerWeb(BaseHandlerWeb):
866
894
  timeout: Optional[int] = None,
867
895
  return_desc: bool = True,
868
896
  ) -> Union[List[Tuple[str, str]], List[str]]:
869
- params = self.generate_search_query(
897
+ params = self.generate_search_params(
870
898
  tag=tag, desc=desc, datasource=self.datasource
871
899
  )
872
- url = urljoin(self.base_url, "search", "query")
900
+ url = urljoin(self.base_url, "points", "search")
873
901
  done = False
874
902
  ret = []
875
903
  while not done:
876
904
  data = self.fetch(url, params=params, timeout=timeout)
877
905
 
878
906
  for item in data["Items"]:
879
- description = item["Description"] if "Description" in item else ""
907
+ description = item["Descriptor"] if "Descriptor" in item else ""
880
908
  ret.append((item["Name"], description))
881
- next_start = int(data["Links"]["Next"].split("=")[-1])
882
- if int(data["Links"]["Last"].split("=")[-1]) >= next_start:
883
- params["start"] = next_start # noqa
884
- else:
885
- done = True
909
+ # next_start = int(data["Links"]["Next"].split("=")[-1])
910
+ # if int(data["Links"]["Last"].split("=")[-1]) >= next_start:
911
+ # params["start"] = next_start # noqa
912
+ # else:
913
+ done = True
886
914
 
887
915
  if not return_desc:
888
916
  ret = [x[0] for x in ret]
@@ -922,17 +950,12 @@ class PIHandlerWeb(BaseHandlerWeb):
922
950
  if self.web_id_cache and tag in self.web_id_cache:
923
951
  return self.web_id_cache[tag]
924
952
 
925
- params = self.generate_search_query(
953
+ params = self.generate_search_params(
926
954
  tag=tag, datasource=self.datasource, desc=None
927
955
  )
928
- params["fields"] = "name;webid"
929
- url = urljoin(self.base_url, "search", "query")
956
+ url = urljoin(self.base_url, "points", "search")
930
957
  data = self.fetch(url, params=params)
931
958
 
932
- if len(data["Errors"]) > 0:
933
- msg = f"Received error from server when searching for WebId for {tag}: {data['Errors']}"
934
- raise ValueError(msg)
935
-
936
959
  if len(data["Items"]) > 1:
937
960
  # Compare elements and if same, return the first
938
961
  first = data["Items"][0]
File without changes
File without changes
File without changes
File without changes
File without changes