cmsdials 1.4.0__tar.gz → 1.6.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.
Files changed (52) hide show
  1. {cmsdials-1.4.0 → cmsdials-1.6.0}/PKG-INFO +51 -2
  2. {cmsdials-1.4.0 → cmsdials-1.6.0}/README.md +50 -1
  3. cmsdials-1.6.0/cmsdials/__init__.py +5 -0
  4. cmsdials-1.6.0/cmsdials/_version.py +1 -0
  5. {cmsdials-1.4.0 → cmsdials-1.6.0}/cmsdials/auth/client.py +3 -0
  6. cmsdials-1.6.0/cmsdials/clients/dataset_index/client.py +13 -0
  7. cmsdials-1.6.0/cmsdials/clients/dataset_index/models.py +30 -0
  8. {cmsdials-1.4.0 → cmsdials-1.6.0}/cmsdials/clients/file_index/models.py +1 -0
  9. {cmsdials-1.4.0 → cmsdials-1.6.0}/cmsdials/clients/h1d/models.py +1 -0
  10. {cmsdials-1.4.0 → cmsdials-1.6.0}/cmsdials/clients/h2d/models.py +1 -0
  11. {cmsdials-1.4.0 → cmsdials-1.6.0}/cmsdials/clients/lumisection/models.py +1 -0
  12. cmsdials-1.6.0/cmsdials/clients/ml_bad_lumisection/client.py +29 -0
  13. cmsdials-1.6.0/cmsdials/clients/ml_bad_lumisection/models.py +38 -0
  14. cmsdials-1.6.0/cmsdials/clients/ml_models_index/client.py +13 -0
  15. cmsdials-1.6.0/cmsdials/clients/ml_models_index/models.py +30 -0
  16. cmsdials-1.6.0/cmsdials/clients/oms_proxy/__init__.py +0 -0
  17. {cmsdials-1.4.0 → cmsdials-1.6.0}/cmsdials/clients/oms_proxy/client.py +4 -1
  18. cmsdials-1.6.0/cmsdials/clients/run/__init__.py +0 -0
  19. {cmsdials-1.4.0 → cmsdials-1.6.0}/cmsdials/clients/run/models.py +1 -0
  20. {cmsdials-1.4.0 → cmsdials-1.6.0}/cmsdials/cmsdials.py +6 -0
  21. {cmsdials-1.4.0 → cmsdials-1.6.0}/cmsdials/filters.py +6 -0
  22. cmsdials-1.6.0/cmsdials/utils/__init__.py +0 -0
  23. {cmsdials-1.4.0 → cmsdials-1.6.0}/cmsdials/utils/api_client.py +17 -2
  24. {cmsdials-1.4.0 → cmsdials-1.6.0}/cmsdials/utils/base_model.py +5 -1
  25. {cmsdials-1.4.0 → cmsdials-1.6.0}/pyproject.toml +6 -3
  26. cmsdials-1.4.0/cmsdials/__init__.py +0 -4
  27. {cmsdials-1.4.0 → cmsdials-1.6.0}/LICENSE +0 -0
  28. {cmsdials-1.4.0 → cmsdials-1.6.0}/cmsdials/auth/__init__.py +0 -0
  29. {cmsdials-1.4.0 → cmsdials-1.6.0}/cmsdials/auth/_base.py +0 -0
  30. {cmsdials-1.4.0 → cmsdials-1.6.0}/cmsdials/auth/bearer.py +0 -0
  31. {cmsdials-1.4.0 → cmsdials-1.6.0}/cmsdials/auth/exceptions.py +0 -0
  32. {cmsdials-1.4.0 → cmsdials-1.6.0}/cmsdials/auth/models.py +0 -0
  33. {cmsdials-1.4.0 → cmsdials-1.6.0}/cmsdials/auth/secret_key.py +0 -0
  34. {cmsdials-1.4.0 → cmsdials-1.6.0}/cmsdials/clients/__init__.py +0 -0
  35. {cmsdials-1.4.0/cmsdials/clients/file_index → cmsdials-1.6.0/cmsdials/clients/dataset_index}/__init__.py +0 -0
  36. {cmsdials-1.4.0/cmsdials/clients/h1d → cmsdials-1.6.0/cmsdials/clients/file_index}/__init__.py +0 -0
  37. {cmsdials-1.4.0 → cmsdials-1.6.0}/cmsdials/clients/file_index/client.py +0 -0
  38. {cmsdials-1.4.0/cmsdials/clients/h2d → cmsdials-1.6.0/cmsdials/clients/h1d}/__init__.py +0 -0
  39. {cmsdials-1.4.0 → cmsdials-1.6.0}/cmsdials/clients/h1d/client.py +0 -0
  40. {cmsdials-1.4.0/cmsdials/clients/lumisection → cmsdials-1.6.0/cmsdials/clients/h2d}/__init__.py +0 -0
  41. {cmsdials-1.4.0 → cmsdials-1.6.0}/cmsdials/clients/h2d/client.py +0 -0
  42. {cmsdials-1.4.0/cmsdials/clients/mes → cmsdials-1.6.0/cmsdials/clients/lumisection}/__init__.py +0 -0
  43. {cmsdials-1.4.0 → cmsdials-1.6.0}/cmsdials/clients/lumisection/client.py +0 -0
  44. {cmsdials-1.4.0/cmsdials/clients/oms_proxy → cmsdials-1.6.0/cmsdials/clients/mes}/__init__.py +0 -0
  45. {cmsdials-1.4.0 → cmsdials-1.6.0}/cmsdials/clients/mes/client.py +0 -0
  46. {cmsdials-1.4.0 → cmsdials-1.6.0}/cmsdials/clients/mes/models.py +0 -0
  47. {cmsdials-1.4.0/cmsdials/clients/run → cmsdials-1.6.0/cmsdials/clients/ml_bad_lumisection}/__init__.py +0 -0
  48. {cmsdials-1.4.0/cmsdials/utils → cmsdials-1.6.0/cmsdials/clients/ml_models_index}/__init__.py +0 -0
  49. {cmsdials-1.4.0 → cmsdials-1.6.0}/cmsdials/clients/oms_proxy/models.py +0 -0
  50. {cmsdials-1.4.0 → cmsdials-1.6.0}/cmsdials/clients/run/client.py +0 -0
  51. {cmsdials-1.4.0 → cmsdials-1.6.0}/cmsdials/utils/_json.py +0 -0
  52. {cmsdials-1.4.0 → cmsdials-1.6.0}/cmsdials/utils/logger.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cmsdials
3
- Version: 1.4.0
3
+ Version: 1.6.0
4
4
  Summary: The Python api client interface to DIALS service
5
5
  Home-page: https://github.com/cms-DQM/dials-py
6
6
  Author: Gabriel Moreira
@@ -108,11 +108,16 @@ This package interacts with DIALS api endpoints using underlying classes in `Dia
108
108
  ### Retrieving a specific object using `get`
109
109
 
110
110
  ```python
111
+ dials.dataset_index.get(dataset_id=14677060)
111
112
  dials.file_index.get(dataset_id=14677060, file_id=3393809397)
112
113
  dials.h1d.get(dataset_id=14677060, run_number=367112, ls_number=10, me_id=1)
113
114
  dials.h1d.get(dataset_id=14677060, run_number=367112, ls_number=10, me_id=96)
114
115
  dials.lumi.get(dataset_id=14677060, run_number=367112, ls_number=10)
115
116
  dials.run.get(dataset_id=14677060, run_number=367112)
117
+
118
+ # jetmet worskpace
119
+ dials.ml_models_index(model_id=1)
120
+ dials.ml_bad_lumisection(model_id=19, dataset_id=15102369, run_number=386951, ls_number=36)
116
121
  ```
117
122
 
118
123
  ### Retrieving a list of objects per page using `list`
@@ -120,11 +125,14 @@ dials.run.get(dataset_id=14677060, run_number=367112)
120
125
  It is possible to get a list of entries from those endpoint using the `list` and `list_all` methods, the `list` method will fetch only one page and the `list_all` will fetch all available pages:
121
126
 
122
127
  ```python
128
+ dials.dataset_index.list()
123
129
  dials.file_index.list()
124
130
  dials.h1d.list()
125
131
  dials.h2d.list()
126
132
  dials.lumi.list()
127
133
  dials.run.list()
134
+ dials.ml_models_index.list()
135
+ dials.ml_bad_lumisection.list()
128
136
  ```
129
137
 
130
138
  ### Retrieving all available pages of a list of objects using `list_all`
@@ -132,11 +140,14 @@ dials.run.list()
132
140
  Note: Keep in mind that running `list_all` without any filter can take too much time, since you will be retrieving all rows in the database.
133
141
 
134
142
  ```python
143
+ dials.dataset_index.list_all()
135
144
  dials.file_index.list_all()
136
145
  dials.h1d.list_all()
137
146
  dials.h2d.list_all()
138
147
  dials.lumi.list_all()
139
148
  dials.run.list_all()
149
+ dials.ml_models_index.list_all()
150
+ dials.ml_bad_lumisection.list_all()
140
151
  ```
141
152
 
142
153
  If you don't need all available pages but just a subset of then, it is possible to specify a `max_pages` integer parameter:
@@ -155,9 +166,12 @@ from cmsdials.filters import (
155
166
  LumisectionHistogram1DFilters,
156
167
  LumisectionHistogram2DFilters,
157
168
  LumisectionFilters,
158
- RunFilters
169
+ RunFilters,
170
+ MLBadLumisectionFilters
159
171
  )
160
172
 
173
+ dials.dataset_index.list_all(DatasetIndexFilters(page_size=500))
174
+
161
175
  dials.file_index.list(FileIndexFilters(dataset__regex="2024B"))
162
176
 
163
177
  dials.h1d.list(LumisectionHistogram1DFilters(me="PixelPhase1/Tracks/PXBarrel/charge_PXLayer_2"))
@@ -167,6 +181,19 @@ dials.h2d.list_all(LumisectionHistogram2DFilters(me__regex="PXBarrel", ls_number
167
181
  dials.lumi.list_all(LumisectionFilters(run_number=360392), max_pages=5)
168
182
 
169
183
  dials.run.list_all(RunFilters(run_number__gte=360392, run_number__lte=365000), max_pages=5)
184
+
185
+ # jetmet workspace
186
+ dials.ml_models_index.list_all(MLModelsIndexFilters(active=True))
187
+
188
+ # jetmet workspace
189
+ dials.ml_bad_lumis.list_all(
190
+ MLBadLumisectionFilters(
191
+ page_size=500,
192
+ model_id__in=[20,19],
193
+ dataset_id__in=[15042670],
194
+ run_number__in=[385801,385799,385764]
195
+ )
196
+ )
170
197
  ```
171
198
 
172
199
  ### Dials MEs
@@ -248,6 +275,28 @@ data = dials.h2d.list_all(LumisectionHistogram2DFilters(me__regex="PXBarrel", ls
248
275
  print(len(data.results)) # 200
249
276
  ```
250
277
 
278
+ ## Fetching ML certification json and ML golden-like json
279
+
280
+ The following examples are testable in the `jetmet` workspace:
281
+
282
+ ```python
283
+ dials.ml_bad_lumis.cert_json(
284
+ model_id__in=[20,19],
285
+ dataset_id__in=[15042670],
286
+ run_number__in=[385801,385799,385764]
287
+ )
288
+
289
+ dials.ml_bad_lumis.golden_json(
290
+ model_id__in=[20,19],
291
+ dataset_id__in=[15042670],
292
+ run_number__in=[385801,385799,385764]
293
+ )
294
+ ```
295
+
296
+ You may need to query the `ml_models_index` client to fetch the models ids you are interested and the `dataset-index` client to fetch the datasets ids. Take a look in the live documentation to check all possible filters.
297
+
298
+ Attention: Those endpoints doesn't return a Pydantic model, instead they are returning a plain json response. Consequently, the method `to_pandas` doesn't work on them.
299
+
251
300
  ## Usage with local DIALS
252
301
 
253
302
  All classes that interface the DIALS service inherits the class `BaseAPIClient` which propagate the `base_url`, `route` and `version` attributes with production values. In order to use dials-py with a local version of DIALS it is possible to overwrite those attributes when instantiating the `AuthClient` and the `Dials` client, for example:
@@ -80,11 +80,16 @@ This package interacts with DIALS api endpoints using underlying classes in `Dia
80
80
  ### Retrieving a specific object using `get`
81
81
 
82
82
  ```python
83
+ dials.dataset_index.get(dataset_id=14677060)
83
84
  dials.file_index.get(dataset_id=14677060, file_id=3393809397)
84
85
  dials.h1d.get(dataset_id=14677060, run_number=367112, ls_number=10, me_id=1)
85
86
  dials.h1d.get(dataset_id=14677060, run_number=367112, ls_number=10, me_id=96)
86
87
  dials.lumi.get(dataset_id=14677060, run_number=367112, ls_number=10)
87
88
  dials.run.get(dataset_id=14677060, run_number=367112)
89
+
90
+ # jetmet worskpace
91
+ dials.ml_models_index(model_id=1)
92
+ dials.ml_bad_lumisection(model_id=19, dataset_id=15102369, run_number=386951, ls_number=36)
88
93
  ```
89
94
 
90
95
  ### Retrieving a list of objects per page using `list`
@@ -92,11 +97,14 @@ dials.run.get(dataset_id=14677060, run_number=367112)
92
97
  It is possible to get a list of entries from those endpoint using the `list` and `list_all` methods, the `list` method will fetch only one page and the `list_all` will fetch all available pages:
93
98
 
94
99
  ```python
100
+ dials.dataset_index.list()
95
101
  dials.file_index.list()
96
102
  dials.h1d.list()
97
103
  dials.h2d.list()
98
104
  dials.lumi.list()
99
105
  dials.run.list()
106
+ dials.ml_models_index.list()
107
+ dials.ml_bad_lumisection.list()
100
108
  ```
101
109
 
102
110
  ### Retrieving all available pages of a list of objects using `list_all`
@@ -104,11 +112,14 @@ dials.run.list()
104
112
  Note: Keep in mind that running `list_all` without any filter can take too much time, since you will be retrieving all rows in the database.
105
113
 
106
114
  ```python
115
+ dials.dataset_index.list_all()
107
116
  dials.file_index.list_all()
108
117
  dials.h1d.list_all()
109
118
  dials.h2d.list_all()
110
119
  dials.lumi.list_all()
111
120
  dials.run.list_all()
121
+ dials.ml_models_index.list_all()
122
+ dials.ml_bad_lumisection.list_all()
112
123
  ```
113
124
 
114
125
  If you don't need all available pages but just a subset of then, it is possible to specify a `max_pages` integer parameter:
@@ -127,9 +138,12 @@ from cmsdials.filters import (
127
138
  LumisectionHistogram1DFilters,
128
139
  LumisectionHistogram2DFilters,
129
140
  LumisectionFilters,
130
- RunFilters
141
+ RunFilters,
142
+ MLBadLumisectionFilters
131
143
  )
132
144
 
145
+ dials.dataset_index.list_all(DatasetIndexFilters(page_size=500))
146
+
133
147
  dials.file_index.list(FileIndexFilters(dataset__regex="2024B"))
134
148
 
135
149
  dials.h1d.list(LumisectionHistogram1DFilters(me="PixelPhase1/Tracks/PXBarrel/charge_PXLayer_2"))
@@ -139,6 +153,19 @@ dials.h2d.list_all(LumisectionHistogram2DFilters(me__regex="PXBarrel", ls_number
139
153
  dials.lumi.list_all(LumisectionFilters(run_number=360392), max_pages=5)
140
154
 
141
155
  dials.run.list_all(RunFilters(run_number__gte=360392, run_number__lte=365000), max_pages=5)
156
+
157
+ # jetmet workspace
158
+ dials.ml_models_index.list_all(MLModelsIndexFilters(active=True))
159
+
160
+ # jetmet workspace
161
+ dials.ml_bad_lumis.list_all(
162
+ MLBadLumisectionFilters(
163
+ page_size=500,
164
+ model_id__in=[20,19],
165
+ dataset_id__in=[15042670],
166
+ run_number__in=[385801,385799,385764]
167
+ )
168
+ )
142
169
  ```
143
170
 
144
171
  ### Dials MEs
@@ -220,6 +247,28 @@ data = dials.h2d.list_all(LumisectionHistogram2DFilters(me__regex="PXBarrel", ls
220
247
  print(len(data.results)) # 200
221
248
  ```
222
249
 
250
+ ## Fetching ML certification json and ML golden-like json
251
+
252
+ The following examples are testable in the `jetmet` workspace:
253
+
254
+ ```python
255
+ dials.ml_bad_lumis.cert_json(
256
+ model_id__in=[20,19],
257
+ dataset_id__in=[15042670],
258
+ run_number__in=[385801,385799,385764]
259
+ )
260
+
261
+ dials.ml_bad_lumis.golden_json(
262
+ model_id__in=[20,19],
263
+ dataset_id__in=[15042670],
264
+ run_number__in=[385801,385799,385764]
265
+ )
266
+ ```
267
+
268
+ You may need to query the `ml_models_index` client to fetch the models ids you are interested and the `dataset-index` client to fetch the datasets ids. Take a look in the live documentation to check all possible filters.
269
+
270
+ Attention: Those endpoints doesn't return a Pydantic model, instead they are returning a plain json response. Consequently, the method `to_pandas` doesn't work on them.
271
+
223
272
  ## Usage with local DIALS
224
273
 
225
274
  All classes that interface the DIALS service inherits the class `BaseAPIClient` which propagate the `base_url`, `route` and `version` attributes with production values. In order to use dials-py with a local version of DIALS it is possible to overwrite those attributes when instantiating the `AuthClient` and the `Dials` client, for example:
@@ -0,0 +1,5 @@
1
+ from ._version import __version__
2
+ from .cmsdials import Dials
3
+
4
+
5
+ __all__ = ["__version__", "Dials"]
@@ -0,0 +1 @@
1
+ __version__ = "1.6.0"
@@ -25,6 +25,7 @@ class AuthClient(BaseAPIClient):
25
25
  url=endpoint_url,
26
26
  headers={
27
27
  "accept": "application/json",
28
+ "User-Agent": self._build_user_agent()
28
29
  },
29
30
  timeout=self.default_timeout,
30
31
  )
@@ -39,6 +40,7 @@ class AuthClient(BaseAPIClient):
39
40
  headers={
40
41
  "accept": "application/json",
41
42
  "Content-Type": "application/json",
43
+ "User-Agent": self._build_user_agent()
42
44
  },
43
45
  json={"device_code": device_code},
44
46
  timeout=self.default_timeout,
@@ -65,6 +67,7 @@ class AuthClient(BaseAPIClient):
65
67
  "accept": "application/json",
66
68
  "Content-Type": "application/json",
67
69
  "Authorization": f"{token_type} {access_token}",
70
+ "User-Agent": self._build_user_agent()
68
71
  },
69
72
  json={"refresh_token": refresh_token},
70
73
  timeout=self.default_timeout,
@@ -0,0 +1,13 @@
1
+ from ...utils.api_client import BaseAuthorizedAPIClient
2
+ from .models import DatasetIndex, DatasetIndexFilters, PaginatedDatasetIndexList
3
+
4
+
5
+ class DatasetIndexClient(BaseAuthorizedAPIClient):
6
+ data_model = DatasetIndex
7
+ pagination_model = PaginatedDatasetIndexList
8
+ filter_class = DatasetIndexFilters
9
+ lookup_url = "dataset-index/"
10
+
11
+ def get(self, dataset_id: int, file_id: int, **kwargs):
12
+ edp = f"{dataset_id}/{file_id}/"
13
+ return super().get(edp, **kwargs)
@@ -0,0 +1,30 @@
1
+ from datetime import datetime
2
+ from typing import Optional
3
+
4
+ from pydantic import AnyUrl, BaseModel, Field
5
+
6
+ from ...utils.base_model import OBaseModel, PaginatedBaseModel
7
+
8
+
9
+ class DatasetIndex(BaseModel):
10
+ dataset_id: int
11
+ dataset: str = Field(..., max_length=255)
12
+ era: str = Field(..., max_length=255)
13
+ data_tier: str = Field(..., max_length=255)
14
+ primary_ds_name: str = Field(..., max_length=255)
15
+ processed_ds_name: str = Field(..., max_length=255)
16
+ processing_version: int
17
+ last_modification_date: datetime
18
+
19
+
20
+ class PaginatedDatasetIndexList(PaginatedBaseModel):
21
+ next: Optional[AnyUrl]
22
+ previous: Optional[AnyUrl]
23
+ results: list[DatasetIndex]
24
+
25
+
26
+ class DatasetIndexFilters(OBaseModel):
27
+ next_token: Optional[str] = None
28
+ page_size: Optional[int] = None
29
+ dataset: Optional[str] = None
30
+ dataset__regex: Optional[str] = None
@@ -26,6 +26,7 @@ class PaginatedFileIndexList(PaginatedBaseModel):
26
26
 
27
27
  class FileIndexFilters(OBaseModel):
28
28
  next_token: Optional[str] = None
29
+ page_size: Optional[int] = None
29
30
  dataset_id: Optional[int] = None
30
31
  logical_file_name: Optional[str] = None
31
32
  logical_file_name__regex: Optional[str] = None
@@ -28,6 +28,7 @@ class PaginatedLumisectionHistogram1DList(PaginatedBaseModel):
28
28
 
29
29
  class LumisectionHistogram1DFilters(OBaseModel):
30
30
  next_token: Optional[str] = None
31
+ page_size: Optional[int] = None
31
32
  dataset_id: Optional[int] = None
32
33
  file_id: Optional[int] = None
33
34
  run_number: Optional[int] = None
@@ -31,6 +31,7 @@ class PaginatedLumisectionHistogram2DList(PaginatedBaseModel):
31
31
 
32
32
  class LumisectionHistogram2DFilters(OBaseModel):
33
33
  next_token: Optional[str] = None
34
+ page_size: Optional[int] = None
34
35
  dataset_id: Optional[int] = None
35
36
  file_id: Optional[int] = None
36
37
  run_number: Optional[int] = None
@@ -22,6 +22,7 @@ class PaginatedLumisectionList(PaginatedBaseModel):
22
22
 
23
23
  class LumisectionFilters(OBaseModel):
24
24
  next_token: Optional[str] = None
25
+ page_size: Optional[int] = None
25
26
  dataset_id: Optional[int] = None
26
27
  run_number: Optional[int] = None
27
28
  run_number__lte: Optional[int] = None
@@ -0,0 +1,29 @@
1
+ from ...utils.api_client import BaseAuthorizedAPIClient
2
+ from .models import MLBadLumisection, MLBadLumisectionFilters, PaginatedMLBadLumisectionList
3
+
4
+
5
+ class MLBadLumisectionClient(BaseAuthorizedAPIClient):
6
+ data_model = MLBadLumisection
7
+ pagination_model = PaginatedMLBadLumisectionList
8
+ filter_class = MLBadLumisectionFilters
9
+ lookup_url = "ml-bad-lumisection/"
10
+
11
+ def get(self, model_id: int, dataset_id: int, run_number: int, ls_number: int, me_id: int, **kwargs):
12
+ edp = f"{model_id}/{dataset_id}/{run_number}/{ls_number}/{me_id}/"
13
+ return super().get(edp, **kwargs)
14
+
15
+ def cert_json(self, model_id__in: list[int], dataset_id__in: list[int], run_number__in: list[int], **kwargs):
16
+ edp = "cert-json/"
17
+ midin = ",".join(str(v) for v in model_id__in)
18
+ didin = ",".join(str(v) for v in dataset_id__in)
19
+ ridin = ",".join(str(v) for v in run_number__in)
20
+ params = {"model_id__in": midin, "dataset_id__in": didin, "run_number__in": ridin}
21
+ return super().get(edp, params=params, return_raw_json=True, **kwargs)
22
+
23
+ def golden_json(self, model_id__in: list[int], dataset_id__in: list[int], run_number__in: list[int], **kwargs):
24
+ edp = "golden-json/"
25
+ midin = ",".join(str(v) for v in model_id__in)
26
+ didin = ",".join(str(v) for v in dataset_id__in)
27
+ ridin = ",".join(str(v) for v in run_number__in)
28
+ params = {"model_id__in": midin, "dataset_id__in": didin, "run_number__in": ridin}
29
+ return super().get(edp, params=params, return_raw_json=True, **kwargs)
@@ -0,0 +1,38 @@
1
+ from typing import Optional
2
+
3
+ from pydantic import AnyUrl, BaseModel
4
+
5
+ from ...utils.base_model import OBaseModel, PaginatedBaseModel
6
+
7
+
8
+ class MLBadLumisection(BaseModel):
9
+ model_id: int
10
+ dataset_id: int
11
+ file_id: int
12
+ run_number: int
13
+ ls_number: int
14
+ me_id: int
15
+ mse: float
16
+
17
+
18
+ class PaginatedMLBadLumisectionList(PaginatedBaseModel):
19
+ next: Optional[AnyUrl]
20
+ previous: Optional[AnyUrl]
21
+ results: list[MLBadLumisection]
22
+
23
+
24
+ class MLBadLumisectionFilters(OBaseModel):
25
+ next_token: Optional[str] = None
26
+ page_size: Optional[int] = None
27
+ model_id: Optional[int] = None
28
+ model_id__in: Optional[list[int]] = None
29
+ dataset_id: Optional[int] = None
30
+ dataset_id__in: Optional[list[int]] = None
31
+ dataset: Optional[str] = None
32
+ dataset__regex: Optional[str] = None
33
+ me_id: Optional[int] = None
34
+ me: Optional[str] = None
35
+ me__regex: Optional[str] = None
36
+ run_number: Optional[int] = None
37
+ run_number__in: Optional[list[int]] = None
38
+ ls_number: Optional[int] = None
@@ -0,0 +1,13 @@
1
+ from ...utils.api_client import BaseAuthorizedAPIClient
2
+ from .models import MLModelsIndex, MLModelsIndexFilters, PaginatedMLModelsIndexList
3
+
4
+
5
+ class MLModelsIndexClient(BaseAuthorizedAPIClient):
6
+ data_model = MLModelsIndex
7
+ pagination_model = PaginatedMLModelsIndexList
8
+ filter_class = MLModelsIndexFilters
9
+ lookup_url = "ml-models-index/"
10
+
11
+ def get(self, model_id: int, **kwargs):
12
+ edp = f"{model_id}/"
13
+ return super().get(edp, **kwargs)
@@ -0,0 +1,30 @@
1
+ from typing import Optional
2
+
3
+ from pydantic import AnyUrl, BaseModel
4
+
5
+ from ...utils.base_model import OBaseModel, PaginatedBaseModel
6
+
7
+
8
+ class MLModelsIndex(BaseModel):
9
+ model_id: int
10
+ filename: str
11
+ target_me: str
12
+ active: bool
13
+
14
+
15
+ class PaginatedMLModelsIndexList(PaginatedBaseModel):
16
+ next: Optional[AnyUrl]
17
+ previous: Optional[AnyUrl]
18
+ results: list[MLModelsIndex]
19
+
20
+
21
+ class MLModelsIndexFilters(OBaseModel):
22
+ next_token: Optional[str] = None
23
+ page_size: Optional[int] = None
24
+ model_id: Optional[int] = None
25
+ model_id__in: Optional[list[int]] = None
26
+ filename: Optional[str] = None
27
+ filename__regex: Optional[str] = None
28
+ target_me: Optional[str] = None
29
+ target_me__regex: Optional[str] = None
30
+ active: Optional[bool] = None
File without changes
@@ -23,7 +23,10 @@ class OMSProxyClient(BaseAPIClient):
23
23
  self.creds = creds
24
24
 
25
25
  def _build_headers(self) -> dict:
26
- base = {"accept": "application/json"}
26
+ base = {
27
+ "accept": "application/json",
28
+ "User-Agent": self._build_user_agent()
29
+ }
27
30
  self.creds.before_request(base)
28
31
  return base
29
32
 
File without changes
@@ -20,6 +20,7 @@ class PaginatedRunList(PaginatedBaseModel):
20
20
 
21
21
  class RunFilters(OBaseModel):
22
22
  next_token: Optional[str] = None
23
+ page_size: Optional[int] = None
23
24
  dataset_id: Optional[int] = None
24
25
  run_number: Optional[int] = None
25
26
  run_number__lte: Optional[int] = None
@@ -1,17 +1,21 @@
1
1
  from typing import Optional
2
2
 
3
3
  from .auth._base import BaseCredentials
4
+ from .clients.dataset_index.client import DatasetIndexClient
4
5
  from .clients.file_index.client import FileIndexClient
5
6
  from .clients.h1d.client import LumisectionHistogram1DClient
6
7
  from .clients.h2d.client import LumisectionHistogram2DClient
7
8
  from .clients.lumisection.client import LumisectionClient
8
9
  from .clients.mes.client import MonitoringElementClient
10
+ from .clients.ml_bad_lumisection.client import MLBadLumisectionClient
11
+ from .clients.ml_models_index.client import MLModelsIndexClient
9
12
  from .clients.oms_proxy.client import OMSProxyClient
10
13
  from .clients.run.client import RunClient
11
14
 
12
15
 
13
16
  class Dials:
14
17
  def __init__(self, creds: BaseCredentials, workspace: Optional[str] = None, *args, **kwargs) -> None:
18
+ self.dataset_index = DatasetIndexClient(creds, workspace, *args, **kwargs)
15
19
  self.file_index = FileIndexClient(creds, workspace, *args, **kwargs)
16
20
  self.h1d = LumisectionHistogram1DClient(creds, workspace, *args, **kwargs)
17
21
  self.h2d = LumisectionHistogram2DClient(creds, workspace, *args, **kwargs)
@@ -19,3 +23,5 @@ class Dials:
19
23
  self.run = RunClient(creds, workspace, *args, **kwargs)
20
24
  self.mes = MonitoringElementClient(creds, workspace, *args, **kwargs)
21
25
  self.oms = OMSProxyClient(creds, *args, **kwargs)
26
+ self.ml_bad_lumis = MLBadLumisectionClient(creds, workspace, *args, **kwargs)
27
+ self.ml_models_index = MLModelsIndexClient(creds, workspace, *args, **kwargs)
@@ -1,19 +1,25 @@
1
+ from .clients.dataset_index.models import DatasetIndexFilters
1
2
  from .clients.file_index.models import FileIndexFilters
2
3
  from .clients.h1d.models import LumisectionHistogram1DFilters
3
4
  from .clients.h2d.models import LumisectionHistogram2DFilters
4
5
  from .clients.lumisection.models import LumisectionFilters
5
6
  from .clients.mes.models import MEFilters
7
+ from .clients.ml_bad_lumisection.models import MLBadLumisectionFilters
8
+ from .clients.ml_models_index.models import MLModelsIndexFilters
6
9
  from .clients.oms_proxy.models import OMSFilter, OMSPage
7
10
  from .clients.run.models import RunFilters
8
11
 
9
12
 
10
13
  __all__ = [
14
+ "DatasetIndexFilters",
11
15
  "FileIndexFilters",
12
16
  "LumisectionHistogram1DFilters",
13
17
  "LumisectionHistogram2DFilters",
14
18
  "LumisectionFilters",
15
19
  "RunFilters",
16
20
  "MEFilters",
21
+ "MLBadLumisectionFilters",
22
+ "MLModelsIndexFilters",
17
23
  "OMSFilter",
18
24
  "OMSPage",
19
25
  ]
File without changes
@@ -1,13 +1,16 @@
1
+ import sys
1
2
  from importlib import util as importlib_util
2
3
  from traceback import format_exc
3
4
  from typing import Optional
4
5
  from urllib.parse import parse_qs, urlparse
5
6
  from warnings import warn
6
7
 
8
+ import requests
7
9
  from requests import Response, Session
8
10
  from requests.adapters import DEFAULT_RETRIES, HTTPAdapter
9
11
  from requests.exceptions import HTTPError
10
12
 
13
+ from .._version import __version__
11
14
  from ..auth._base import BaseCredentials
12
15
  from ..utils.logger import logger
13
16
 
@@ -51,6 +54,12 @@ class BaseAPIClient:
51
54
  ret = s.get(*args, **kwargs)
52
55
  return ret
53
56
 
57
+ @staticmethod
58
+ def _build_user_agent():
59
+ py_version = f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}"
60
+ req_version = requests.__version__
61
+ return f"dials-py/{__version__} (python/{py_version}, python-requests/{req_version})"
62
+
54
63
  @property
55
64
  def api_url(self):
56
65
  return self.base_url + self.route + self.version
@@ -75,18 +84,22 @@ class BaseAuthorizedAPIClient(BaseAPIClient):
75
84
  self.workspace = workspace
76
85
 
77
86
  def _build_headers(self) -> dict:
78
- base = {"accept": "application/json"}
87
+ base = {
88
+ "accept": "application/json",
89
+ "User-Agent": self._build_user_agent()
90
+ }
79
91
  if self.workspace is not None:
80
92
  base["Workspace"] = self.workspace
81
93
  self.creds.before_request(base)
82
94
  return base
83
95
 
84
- def get(self, edp: str, retries=DEFAULT_RETRIES): # noqa: A002
96
+ def get(self, edp: str, retries=DEFAULT_RETRIES, params: Optional[dict] = None, return_raw_json: bool = False):
85
97
  endpoint_url = self.api_url + self.lookup_url + edp
86
98
  headers = self._build_headers()
87
99
  response = self._requests_get_retriable(
88
100
  endpoint_url,
89
101
  headers=headers,
102
+ params=params,
90
103
  timeout=self.default_timeout,
91
104
  retries=retries,
92
105
  )
@@ -98,6 +111,8 @@ class BaseAuthorizedAPIClient(BaseAPIClient):
98
111
  raise err
99
112
 
100
113
  response = response.json()
114
+ if return_raw_json:
115
+ return response
101
116
  return self.data_model(**response)
102
117
 
103
118
  def list(self, filters=None, retries=DEFAULT_RETRIES):
@@ -14,7 +14,11 @@ else:
14
14
 
15
15
  class OBaseModel(BaseModel):
16
16
  def cleandict(self):
17
- return {key: value for key, value in self.dict().items() if value is not None}
17
+ return {
18
+ key: ",".join(str(v) for v in value) if isinstance(value, (list, tuple)) else value
19
+ for key, value in self.dict().items()
20
+ if value is not None
21
+ }
18
22
 
19
23
 
20
24
  class PaginatedBaseModel(BaseModel):
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "cmsdials"
3
- version = "1.4.0"
3
+ version = "1.6.0"
4
4
  description = "The Python api client interface to DIALS service"
5
5
  authors = ["Gabriel Moreira <gabrielmscampos@gmail.com>"]
6
6
  readme = "README.md"
@@ -130,6 +130,9 @@ lines-after-imports = 2
130
130
  "**/{tests,docs}/*" = ["E402", "F403", "F405", "S", "N802"]
131
131
  "**/*test*.py" = ["E402", "F403", "F405", "S", "N802"]
132
132
 
133
+ [tool.poetry-dynamic-versioning]
134
+ enable = false
135
+
133
136
  [build-system]
134
- requires = ["poetry-core"]
135
- build-backend = "poetry.core.masonry.api"
137
+ requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning>=1.0.0,<2.0.0"]
138
+ build-backend = "poetry_dynamic_versioning.backend"
@@ -1,4 +0,0 @@
1
- from .cmsdials import Dials
2
-
3
-
4
- __all__ = ["Dials"]
File without changes