rapidata 2.35.1__py3-none-any.whl → 2.35.3__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 rapidata might be problematic. Click here for more details.
- rapidata/__init__.py +2 -1
- rapidata/api_client/api/leaderboard_api.py +3 -3
- rapidata/api_client_README.md +1 -1
- rapidata/rapidata_client/__init__.py +5 -13
- rapidata/rapidata_client/api/rapidata_exception.py +61 -32
- rapidata/rapidata_client/benchmark/participant/_participant.py +45 -26
- rapidata/rapidata_client/benchmark/rapidata_benchmark_manager.py +73 -30
- rapidata/rapidata_client/config/__init__.py +1 -0
- rapidata/rapidata_client/config/config.py +33 -0
- rapidata/rapidata_client/datapoints/assets/_multi_asset.py +7 -7
- rapidata/rapidata_client/datapoints/assets/_sessions.py +13 -8
- rapidata/rapidata_client/order/_rapidata_dataset.py +166 -115
- rapidata/rapidata_client/order/_rapidata_order_builder.py +54 -22
- rapidata/rapidata_client/order/rapidata_order.py +109 -48
- rapidata/rapidata_client/rapidata_client.py +19 -14
- rapidata/rapidata_client/validation/rapidata_validation_set.py +13 -7
- rapidata/rapidata_client/validation/validation_set_manager.py +167 -98
- rapidata/service/credential_manager.py +13 -13
- rapidata/service/openapi_service.py +22 -13
- {rapidata-2.35.1.dist-info → rapidata-2.35.3.dist-info}/METADATA +1 -1
- {rapidata-2.35.1.dist-info → rapidata-2.35.3.dist-info}/RECORD +23 -21
- {rapidata-2.35.1.dist-info → rapidata-2.35.3.dist-info}/LICENSE +0 -0
- {rapidata-2.35.1.dist-info → rapidata-2.35.3.dist-info}/WHEEL +0 -0
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
from typing import Literal
|
|
2
2
|
from rapidata.api_client import QueryModel
|
|
3
|
-
from rapidata.rapidata_client.validation.rapidata_validation_set import
|
|
4
|
-
|
|
3
|
+
from rapidata.rapidata_client.validation.rapidata_validation_set import (
|
|
4
|
+
RapidataValidationSet,
|
|
5
|
+
)
|
|
6
|
+
from rapidata.api_client.models.create_validation_set_model import (
|
|
7
|
+
CreateValidationSetModel,
|
|
8
|
+
)
|
|
5
9
|
from rapidata.service.openapi_service import OpenAPIService
|
|
6
10
|
from rapidata.rapidata_client.validation.rapids.rapids_manager import RapidsManager
|
|
7
11
|
from rapidata.rapidata_client.validation.rapids.rapids import Rapid
|
|
8
|
-
from rapidata.rapidata_client.datapoints.metadata import
|
|
12
|
+
from rapidata.rapidata_client.datapoints.metadata import (
|
|
13
|
+
PromptMetadata,
|
|
14
|
+
MediaAssetMetadata,
|
|
15
|
+
)
|
|
9
16
|
|
|
10
17
|
from rapidata.api_client.models.page_info import PageInfo
|
|
11
18
|
from rapidata.api_client.models.root_filter import RootFilter
|
|
@@ -14,7 +21,11 @@ from rapidata.api_client.models.sort_criterion import SortCriterion
|
|
|
14
21
|
|
|
15
22
|
from rapidata.rapidata_client.validation.rapids.box import Box
|
|
16
23
|
|
|
17
|
-
from rapidata.rapidata_client.logging import
|
|
24
|
+
from rapidata.rapidata_client.logging import (
|
|
25
|
+
logger,
|
|
26
|
+
managed_print,
|
|
27
|
+
RapidataOutputManager,
|
|
28
|
+
)
|
|
18
29
|
from tqdm import tqdm
|
|
19
30
|
|
|
20
31
|
|
|
@@ -25,12 +36,14 @@ class ValidationSetManager:
|
|
|
25
36
|
Attributes:
|
|
26
37
|
rapid (RapidsManager): The RapidsManager instance.
|
|
27
38
|
"""
|
|
39
|
+
|
|
28
40
|
def __init__(self, openapi_service: OpenAPIService) -> None:
|
|
29
41
|
self.__openapi_service = openapi_service
|
|
30
42
|
self.rapid = RapidsManager()
|
|
31
43
|
logger.debug("ValidationSetManager initialized")
|
|
32
44
|
|
|
33
|
-
def create_classification_set(
|
|
45
|
+
def create_classification_set(
|
|
46
|
+
self,
|
|
34
47
|
name: str,
|
|
35
48
|
instruction: str,
|
|
36
49
|
answer_options: list[str],
|
|
@@ -43,7 +56,7 @@ class ValidationSetManager:
|
|
|
43
56
|
dimensions: list[str] = [],
|
|
44
57
|
) -> RapidataValidationSet:
|
|
45
58
|
"""Create a classification validation set.
|
|
46
|
-
|
|
59
|
+
|
|
47
60
|
Args:
|
|
48
61
|
name (str): The name of the validation set. (will not be shown to the labeler)
|
|
49
62
|
instruction (str): The instruction by which the labeler will answer.
|
|
@@ -74,23 +87,26 @@ class ValidationSetManager:
|
|
|
74
87
|
"""
|
|
75
88
|
if not datapoints:
|
|
76
89
|
raise ValueError("Datapoints cannot be empty")
|
|
77
|
-
|
|
90
|
+
|
|
78
91
|
if len(datapoints) != len(truths):
|
|
79
92
|
raise ValueError("The number of datapoints and truths must be equal")
|
|
80
|
-
|
|
93
|
+
|
|
81
94
|
if not all([isinstance(truth, (list, tuple)) for truth in truths]):
|
|
82
95
|
raise ValueError("Truths must be a list of lists or tuples")
|
|
83
|
-
|
|
96
|
+
|
|
84
97
|
if contexts and len(contexts) != len(datapoints):
|
|
85
98
|
raise ValueError("The number of contexts and datapoints must be equal")
|
|
86
99
|
|
|
87
100
|
if media_contexts and len(media_contexts) != len(datapoints):
|
|
88
|
-
raise ValueError(
|
|
101
|
+
raise ValueError(
|
|
102
|
+
"The number of media contexts and datapoints must be equal"
|
|
103
|
+
)
|
|
89
104
|
|
|
90
|
-
if
|
|
91
|
-
raise ValueError(
|
|
105
|
+
if explanations and len(explanations) != len(datapoints):
|
|
106
|
+
raise ValueError(
|
|
107
|
+
"The number of explanations and datapoints must be equal, the index must align, but can be padded with None"
|
|
108
|
+
)
|
|
92
109
|
|
|
93
|
-
|
|
94
110
|
logger.debug("Creating classification rapids")
|
|
95
111
|
rapids: list[Rapid] = []
|
|
96
112
|
for i in range(len(datapoints)):
|
|
@@ -107,14 +123,15 @@ class ValidationSetManager:
|
|
|
107
123
|
truths=truths[i],
|
|
108
124
|
data_type=data_type,
|
|
109
125
|
metadata=rapid_metadata,
|
|
110
|
-
explanation=explanations[i] if explanations != None else None
|
|
126
|
+
explanation=explanations[i] if explanations != None else None,
|
|
111
127
|
)
|
|
112
128
|
)
|
|
113
129
|
|
|
114
130
|
logger.debug("Submitting classification rapids")
|
|
115
131
|
return self._submit(name=name, rapids=rapids, dimensions=dimensions)
|
|
116
132
|
|
|
117
|
-
def create_compare_set(
|
|
133
|
+
def create_compare_set(
|
|
134
|
+
self,
|
|
118
135
|
name: str,
|
|
119
136
|
instruction: str,
|
|
120
137
|
datapoints: list[list[str]],
|
|
@@ -135,7 +152,7 @@ class ValidationSetManager:
|
|
|
135
152
|
instruction: "Which image has a cat?"
|
|
136
153
|
datapoints = [["image1.jpg", "image2.jpg"], ["image3.jpg", "image4.jpg"]]
|
|
137
154
|
truths: ["image1.jpg", "image4.jpg"] -> first comparison image1.jpg has a cat, second comparison image4.jpg has a cat
|
|
138
|
-
datapoints (list[list[str]]): The compare datapoints to create the validation set with.
|
|
155
|
+
datapoints (list[list[str]]): The compare datapoints to create the validation set with.
|
|
139
156
|
Outer list is for each comparison, inner list the two images/texts that will be compared.
|
|
140
157
|
data_type (str, optional): The type of data. Defaults to "media" (any form of image, video or audio). Other option: "text".
|
|
141
158
|
contexts (list[str], optional): The contexts for each datapoint. Defaults to None.\n
|
|
@@ -157,10 +174,10 @@ class ValidationSetManager:
|
|
|
157
174
|
"""
|
|
158
175
|
if not datapoints:
|
|
159
176
|
raise ValueError("Datapoints cannot be empty")
|
|
160
|
-
|
|
177
|
+
|
|
161
178
|
if len(datapoints) != len(truths):
|
|
162
179
|
raise ValueError("The number of datapoints and truths must be equal")
|
|
163
|
-
|
|
180
|
+
|
|
164
181
|
if not all([isinstance(truth, str) for truth in truths]):
|
|
165
182
|
raise ValueError("Truths must be a list of strings")
|
|
166
183
|
|
|
@@ -168,11 +185,15 @@ class ValidationSetManager:
|
|
|
168
185
|
raise ValueError("The number of contexts and datapoints must be equal")
|
|
169
186
|
|
|
170
187
|
if media_contexts and len(media_contexts) != len(datapoints):
|
|
171
|
-
raise ValueError(
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
188
|
+
raise ValueError(
|
|
189
|
+
"The number of media contexts and datapoints must be equal"
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
if explanation and len(explanation) != len(datapoints):
|
|
193
|
+
raise ValueError(
|
|
194
|
+
"The number of explanations and datapoints must be equal, the index must align, but can be padded with None"
|
|
195
|
+
)
|
|
196
|
+
|
|
176
197
|
logger.debug("Creating comparison rapids")
|
|
177
198
|
rapids: list[Rapid] = []
|
|
178
199
|
for i in range(len(datapoints)):
|
|
@@ -188,14 +209,15 @@ class ValidationSetManager:
|
|
|
188
209
|
datapoint=datapoints[i],
|
|
189
210
|
data_type=data_type,
|
|
190
211
|
metadata=rapid_metadata,
|
|
191
|
-
explanation=explanation[i] if explanation != None else None
|
|
212
|
+
explanation=explanation[i] if explanation != None else None,
|
|
192
213
|
)
|
|
193
214
|
)
|
|
194
|
-
|
|
215
|
+
|
|
195
216
|
logger.debug("Submitting comparison rapids")
|
|
196
217
|
return self._submit(name=name, rapids=rapids, dimensions=dimensions)
|
|
197
|
-
|
|
198
|
-
def create_select_words_set(
|
|
218
|
+
|
|
219
|
+
def create_select_words_set(
|
|
220
|
+
self,
|
|
199
221
|
name: str,
|
|
200
222
|
instruction: str,
|
|
201
223
|
truths: list[list[int]],
|
|
@@ -231,18 +253,22 @@ class ValidationSetManager:
|
|
|
231
253
|
truths: [[0, 1], [2]]
|
|
232
254
|
```
|
|
233
255
|
This would mean: first datapoint the correct words are "this" and "example", second datapoint is "with"
|
|
234
|
-
|
|
256
|
+
"""
|
|
235
257
|
if not datapoints:
|
|
236
258
|
raise ValueError("Datapoints cannot be empty")
|
|
237
|
-
|
|
259
|
+
|
|
238
260
|
if not all([isinstance(truth, (list, tuple)) for truth in truths]):
|
|
239
261
|
raise ValueError("Truths must be a list of lists or tuples")
|
|
240
262
|
|
|
241
263
|
if len(datapoints) != len(truths) or len(datapoints) != len(sentences):
|
|
242
|
-
raise ValueError(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
264
|
+
raise ValueError(
|
|
265
|
+
"The number of datapoints, truths, and sentences must be equal"
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
if explanation and len(explanation) != len(datapoints):
|
|
269
|
+
raise ValueError(
|
|
270
|
+
"The number of explanations and datapoints must be equal, the index must align, but can be padded with None"
|
|
271
|
+
)
|
|
246
272
|
|
|
247
273
|
logger.debug("Creating select words rapids")
|
|
248
274
|
rapids: list[Rapid] = []
|
|
@@ -255,14 +281,15 @@ class ValidationSetManager:
|
|
|
255
281
|
sentence=sentences[i],
|
|
256
282
|
required_precision=required_precision,
|
|
257
283
|
required_completeness=required_completeness,
|
|
258
|
-
explanation=explanation[i] if explanation != None else None
|
|
284
|
+
explanation=explanation[i] if explanation != None else None,
|
|
259
285
|
)
|
|
260
286
|
)
|
|
261
287
|
|
|
262
288
|
logger.debug("Submitting select words rapids")
|
|
263
289
|
return self._submit(name=name, rapids=rapids, dimensions=dimensions)
|
|
264
290
|
|
|
265
|
-
def create_locate_set(
|
|
291
|
+
def create_locate_set(
|
|
292
|
+
self,
|
|
266
293
|
name: str,
|
|
267
294
|
instruction: str,
|
|
268
295
|
truths: list[list[Box]],
|
|
@@ -298,22 +325,26 @@ class ValidationSetManager:
|
|
|
298
325
|
"""
|
|
299
326
|
if not datapoints:
|
|
300
327
|
raise ValueError("Datapoints cannot be empty")
|
|
301
|
-
|
|
328
|
+
|
|
302
329
|
if len(datapoints) != len(truths):
|
|
303
330
|
raise ValueError("The number of datapoints and truths must be equal")
|
|
304
|
-
|
|
331
|
+
|
|
305
332
|
if not all([isinstance(truth, (list, tuple)) for truth in truths]):
|
|
306
333
|
raise ValueError("Truths must be a list of lists or tuples")
|
|
307
|
-
|
|
334
|
+
|
|
308
335
|
if contexts and len(contexts) != len(datapoints):
|
|
309
336
|
raise ValueError("The number of contexts and datapoints must be equal")
|
|
310
|
-
|
|
337
|
+
|
|
311
338
|
if media_contexts and len(media_contexts) != len(datapoints):
|
|
312
|
-
raise ValueError(
|
|
339
|
+
raise ValueError(
|
|
340
|
+
"The number of media contexts and datapoints must be equal"
|
|
341
|
+
)
|
|
342
|
+
|
|
343
|
+
if explanation and len(explanation) != len(datapoints):
|
|
344
|
+
raise ValueError(
|
|
345
|
+
"The number of explanations and datapoints must be equal, the index must align, but can be padded with None"
|
|
346
|
+
)
|
|
313
347
|
|
|
314
|
-
if(explanation and len(explanation) != len(datapoints)):
|
|
315
|
-
raise ValueError("The number of explanations and datapoints must be equal, the index must align, but can be padded with None")
|
|
316
|
-
|
|
317
348
|
logger.debug("Creating locate rapids")
|
|
318
349
|
rapids = []
|
|
319
350
|
rapids: list[Rapid] = []
|
|
@@ -329,15 +360,15 @@ class ValidationSetManager:
|
|
|
329
360
|
truths=truths[i],
|
|
330
361
|
datapoint=datapoints[i],
|
|
331
362
|
metadata=rapid_metadata,
|
|
332
|
-
explanation=explanation[i] if explanation != None else None
|
|
333
|
-
|
|
363
|
+
explanation=explanation[i] if explanation != None else None,
|
|
334
364
|
)
|
|
335
365
|
)
|
|
336
|
-
|
|
366
|
+
|
|
337
367
|
logger.debug("Submitting locate rapids")
|
|
338
368
|
return self._submit(name=name, rapids=rapids, dimensions=dimensions)
|
|
339
|
-
|
|
340
|
-
def create_draw_set(
|
|
369
|
+
|
|
370
|
+
def create_draw_set(
|
|
371
|
+
self,
|
|
341
372
|
name: str,
|
|
342
373
|
instruction: str,
|
|
343
374
|
truths: list[list[Box]],
|
|
@@ -373,21 +404,25 @@ class ValidationSetManager:
|
|
|
373
404
|
"""
|
|
374
405
|
if not datapoints:
|
|
375
406
|
raise ValueError("Datapoints cannot be empty")
|
|
376
|
-
|
|
407
|
+
|
|
377
408
|
if len(datapoints) != len(truths):
|
|
378
409
|
raise ValueError("The number of datapoints and truths must be equal")
|
|
379
|
-
|
|
410
|
+
|
|
380
411
|
if not all([isinstance(truth, (list, tuple)) for truth in truths]):
|
|
381
412
|
raise ValueError("Truths must be a list of lists or tuples")
|
|
382
|
-
|
|
413
|
+
|
|
383
414
|
if contexts and len(contexts) != len(datapoints):
|
|
384
415
|
raise ValueError("The number of contexts and datapoints must be equal")
|
|
385
|
-
|
|
416
|
+
|
|
386
417
|
if media_contexts and len(media_contexts) != len(datapoints):
|
|
387
|
-
raise ValueError(
|
|
418
|
+
raise ValueError(
|
|
419
|
+
"The number of media contexts and datapoints must be equal"
|
|
420
|
+
)
|
|
388
421
|
|
|
389
|
-
if
|
|
390
|
-
raise ValueError(
|
|
422
|
+
if explanation and len(explanation) != len(datapoints):
|
|
423
|
+
raise ValueError(
|
|
424
|
+
"The number of explanations and datapoints must be equal, the index must align, but can be padded with None"
|
|
425
|
+
)
|
|
391
426
|
|
|
392
427
|
logger.debug("Creating draw rapids")
|
|
393
428
|
rapids: list[Rapid] = []
|
|
@@ -403,15 +438,15 @@ class ValidationSetManager:
|
|
|
403
438
|
truths=truths[i],
|
|
404
439
|
datapoint=datapoints[i],
|
|
405
440
|
metadata=rapid_metadata,
|
|
406
|
-
explanation=explanation[i] if explanation != None else None
|
|
407
|
-
|
|
441
|
+
explanation=explanation[i] if explanation != None else None,
|
|
408
442
|
)
|
|
409
443
|
)
|
|
410
444
|
|
|
411
445
|
logger.debug("Submitting draw rapids")
|
|
412
446
|
return self._submit(name=name, rapids=rapids, dimensions=dimensions)
|
|
413
447
|
|
|
414
|
-
def create_timestamp_set(
|
|
448
|
+
def create_timestamp_set(
|
|
449
|
+
self,
|
|
415
450
|
name: str,
|
|
416
451
|
instruction: str,
|
|
417
452
|
truths: list[list[tuple[int, int]]],
|
|
@@ -426,7 +461,7 @@ class ValidationSetManager:
|
|
|
426
461
|
Args:
|
|
427
462
|
name (str): The name of the validation set. (will not be shown to the labeler)
|
|
428
463
|
instruction (str): The instruction to show to the labeler.
|
|
429
|
-
truths (list[list[tuple[int, int]]]): The truths for each datapoint defined as start and endpoint based on miliseconds.
|
|
464
|
+
truths (list[list[tuple[int, int]]]): The truths for each datapoint defined as start and endpoint based on miliseconds.
|
|
430
465
|
Outer list is for each datapoint, inner list is for each truth.\n
|
|
431
466
|
example:
|
|
432
467
|
datapoints: ["datapoint1", "datapoint2"]
|
|
@@ -448,22 +483,26 @@ class ValidationSetManager:
|
|
|
448
483
|
"""
|
|
449
484
|
if not datapoints:
|
|
450
485
|
raise ValueError("Datapoints cannot be empty")
|
|
451
|
-
|
|
486
|
+
|
|
452
487
|
if len(datapoints) != len(truths):
|
|
453
488
|
raise ValueError("The number of datapoints and truths must be equal")
|
|
454
|
-
|
|
489
|
+
|
|
455
490
|
if not all([isinstance(truth, (list, tuple)) for truth in truths]):
|
|
456
491
|
raise ValueError("Truths must be a list of lists or tuples")
|
|
457
|
-
|
|
492
|
+
|
|
458
493
|
if contexts and len(contexts) != len(datapoints):
|
|
459
494
|
raise ValueError("The number of contexts and datapoints must be equal")
|
|
460
|
-
|
|
495
|
+
|
|
461
496
|
if media_contexts and len(media_contexts) != len(datapoints):
|
|
462
|
-
raise ValueError(
|
|
497
|
+
raise ValueError(
|
|
498
|
+
"The number of media contexts and datapoints must be equal"
|
|
499
|
+
)
|
|
500
|
+
|
|
501
|
+
if explanation and len(explanation) != len(datapoints):
|
|
502
|
+
raise ValueError(
|
|
503
|
+
"The number of explanations and datapoints must be equal, the index must align, but can be padded with None"
|
|
504
|
+
)
|
|
463
505
|
|
|
464
|
-
if(explanation and len(explanation) != len(datapoints)):
|
|
465
|
-
raise ValueError("The number of explanations and datapoints must be equal, the index must align, but can be padded with None")
|
|
466
|
-
|
|
467
506
|
logger.debug("Creating timestamp rapids")
|
|
468
507
|
rapids: list[Rapid] = []
|
|
469
508
|
for i in range(len(datapoints)):
|
|
@@ -478,14 +517,15 @@ class ValidationSetManager:
|
|
|
478
517
|
truths=truths[i],
|
|
479
518
|
datapoint=datapoints[i],
|
|
480
519
|
metadata=rapid_metadata,
|
|
481
|
-
explanation=explanation[i] if explanation != None else None
|
|
520
|
+
explanation=explanation[i] if explanation != None else None,
|
|
482
521
|
)
|
|
483
522
|
)
|
|
484
523
|
|
|
485
524
|
logger.debug("Submitting timestamp rapids")
|
|
486
525
|
return self._submit(name=name, rapids=rapids, dimensions=dimensions)
|
|
487
|
-
|
|
488
|
-
def create_mixed_set(
|
|
526
|
+
|
|
527
|
+
def create_mixed_set(
|
|
528
|
+
self,
|
|
489
529
|
name: str,
|
|
490
530
|
rapids: list[Rapid],
|
|
491
531
|
dimensions: list[str] = [],
|
|
@@ -502,17 +542,17 @@ class ValidationSetManager:
|
|
|
502
542
|
|
|
503
543
|
return self._submit(name=name, rapids=rapids, dimensions=dimensions)
|
|
504
544
|
|
|
505
|
-
def _submit(
|
|
545
|
+
def _submit(
|
|
546
|
+
self, name: str, rapids: list[Rapid], dimensions: list[str] | None
|
|
547
|
+
) -> RapidataValidationSet:
|
|
506
548
|
logger.debug("Creating validation set")
|
|
507
549
|
validation_set_id = (
|
|
508
550
|
self.__openapi_service.validation_api.validation_set_post(
|
|
509
|
-
create_validation_set_model=CreateValidationSetModel(
|
|
510
|
-
name=name
|
|
511
|
-
)
|
|
551
|
+
create_validation_set_model=CreateValidationSetModel(name=name)
|
|
512
552
|
)
|
|
513
553
|
).validation_set_id
|
|
514
554
|
|
|
515
|
-
logger.debug(
|
|
555
|
+
logger.debug("Validation set created with ID: %s", validation_set_id)
|
|
516
556
|
|
|
517
557
|
if validation_set_id is None:
|
|
518
558
|
raise ValueError("Failed to create validation set")
|
|
@@ -522,31 +562,43 @@ class ValidationSetManager:
|
|
|
522
562
|
validation_set = RapidataValidationSet(
|
|
523
563
|
name=name,
|
|
524
564
|
validation_set_id=validation_set_id,
|
|
525
|
-
openapi_service=self.__openapi_service
|
|
565
|
+
openapi_service=self.__openapi_service,
|
|
526
566
|
)
|
|
527
567
|
|
|
528
568
|
logger.debug("Adding rapids to validation set")
|
|
529
569
|
failed_rapids = []
|
|
530
|
-
for rapid in tqdm(
|
|
531
|
-
|
|
570
|
+
for rapid in tqdm(
|
|
571
|
+
rapids,
|
|
572
|
+
desc="Uploading validation tasks",
|
|
573
|
+
disable=RapidataOutputManager.silent_mode,
|
|
574
|
+
):
|
|
575
|
+
try:
|
|
532
576
|
validation_set.add_rapid(rapid)
|
|
533
577
|
except Exception:
|
|
534
578
|
failed_rapids.append(rapid.asset)
|
|
535
579
|
|
|
536
580
|
if failed_rapids:
|
|
537
|
-
logger.error(
|
|
538
|
-
|
|
581
|
+
logger.error(
|
|
582
|
+
"Failed to add %s datapoints to validation set: %s",
|
|
583
|
+
len(failed_rapids),
|
|
584
|
+
failed_rapids,
|
|
585
|
+
)
|
|
586
|
+
raise RuntimeError(
|
|
587
|
+
f"Failed to add {len(failed_rapids)} datapoints to validation set: {failed_rapids}"
|
|
588
|
+
)
|
|
539
589
|
|
|
540
590
|
managed_print()
|
|
541
|
-
managed_print(
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
591
|
+
managed_print(
|
|
592
|
+
f"Validation set '{name}' created with ID {validation_set_id}\n",
|
|
593
|
+
f"Now viewable under: https://app.{self.__openapi_service.environment}/validation-set/detail/{validation_set_id}",
|
|
594
|
+
sep="",
|
|
595
|
+
)
|
|
596
|
+
|
|
545
597
|
if dimensions:
|
|
546
598
|
validation_set.update_dimensions(dimensions)
|
|
547
|
-
|
|
599
|
+
|
|
548
600
|
return validation_set
|
|
549
|
-
|
|
601
|
+
|
|
550
602
|
def get_validation_set_by_id(self, validation_set_id: str) -> RapidataValidationSet:
|
|
551
603
|
"""Get a validation set by ID.
|
|
552
604
|
|
|
@@ -556,13 +608,20 @@ class ValidationSetManager:
|
|
|
556
608
|
Returns:
|
|
557
609
|
RapidataValidationSet: The ValidationSet instance.
|
|
558
610
|
"""
|
|
559
|
-
|
|
560
|
-
validation_set = self.__openapi_service.validation_api.validation_set_validation_set_id_get(validation_set_id=validation_set_id)
|
|
561
|
-
|
|
562
|
-
return RapidataValidationSet(validation_set_id, str(validation_set.name), self.__openapi_service)
|
|
563
611
|
|
|
612
|
+
validation_set = (
|
|
613
|
+
self.__openapi_service.validation_api.validation_set_validation_set_id_get(
|
|
614
|
+
validation_set_id=validation_set_id
|
|
615
|
+
)
|
|
616
|
+
)
|
|
617
|
+
|
|
618
|
+
return RapidataValidationSet(
|
|
619
|
+
validation_set_id, str(validation_set.name), self.__openapi_service
|
|
620
|
+
)
|
|
564
621
|
|
|
565
|
-
def find_validation_sets(
|
|
622
|
+
def find_validation_sets(
|
|
623
|
+
self, name: str = "", amount: int = 1
|
|
624
|
+
) -> list[RapidataValidationSet]:
|
|
566
625
|
"""Find validation sets by name.
|
|
567
626
|
|
|
568
627
|
Args:
|
|
@@ -573,12 +632,22 @@ class ValidationSetManager:
|
|
|
573
632
|
list[RapidataValidationSet]: The list of validation sets.
|
|
574
633
|
"""
|
|
575
634
|
|
|
576
|
-
validation_page_result =
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
635
|
+
validation_page_result = (
|
|
636
|
+
self.__openapi_service.validation_api.validation_sets_get(
|
|
637
|
+
QueryModel(
|
|
638
|
+
page=PageInfo(index=1, size=amount),
|
|
639
|
+
filter=RootFilter(
|
|
640
|
+
filters=[Filter(field="Name", operator="Contains", value=name)]
|
|
641
|
+
),
|
|
642
|
+
sortCriteria=[
|
|
643
|
+
SortCriterion(direction="Desc", propertyName="CreatedAt")
|
|
644
|
+
],
|
|
645
|
+
)
|
|
646
|
+
)
|
|
647
|
+
)
|
|
581
648
|
|
|
582
|
-
validation_sets = [
|
|
649
|
+
validation_sets = [
|
|
650
|
+
self.get_validation_set_by_id(str(validation_set.id))
|
|
651
|
+
for validation_set in validation_page_result.items
|
|
652
|
+
]
|
|
583
653
|
return validation_sets
|
|
584
|
-
|
|
@@ -52,7 +52,7 @@ class CredentialManager:
|
|
|
52
52
|
|
|
53
53
|
def _read_credentials(self) -> Dict[str, List[ClientCredential]]:
|
|
54
54
|
"""Read all stored credentials from the config file."""
|
|
55
|
-
logger.debug(
|
|
55
|
+
logger.debug("Reading credentials from %s", self.config_path)
|
|
56
56
|
if not self.config_path.exists():
|
|
57
57
|
return {}
|
|
58
58
|
|
|
@@ -77,12 +77,12 @@ class CredentialManager:
|
|
|
77
77
|
with open(self.config_path, "w") as f:
|
|
78
78
|
json.dump(data, f, indent=2)
|
|
79
79
|
|
|
80
|
-
logger.debug(
|
|
80
|
+
logger.debug("Credentials written to %s with data: %s", self.config_path, data)
|
|
81
81
|
|
|
82
82
|
# Ensure file is only readable by the user
|
|
83
83
|
os.chmod(self.config_path, 0o600)
|
|
84
84
|
logger.debug(
|
|
85
|
-
|
|
85
|
+
"Set permissions for %s to read/write for user only.", self.config_path
|
|
86
86
|
)
|
|
87
87
|
|
|
88
88
|
def _store_credential(self, credential: ClientCredential) -> None:
|
|
@@ -109,19 +109,19 @@ class CredentialManager:
|
|
|
109
109
|
def get_client_credentials(self) -> Optional[ClientCredential]:
|
|
110
110
|
"""Gets stored client credentials or create new ones via browser auth."""
|
|
111
111
|
credentials = self._read_credentials()
|
|
112
|
-
logger.debug(
|
|
112
|
+
logger.debug("Stored credentials: %s", credentials)
|
|
113
113
|
env_credentials = credentials.get(self.endpoint, [])
|
|
114
114
|
|
|
115
115
|
if env_credentials:
|
|
116
|
-
logger.debug(
|
|
116
|
+
logger.debug("Found credentials for %s: %s", self.endpoint, env_credentials)
|
|
117
117
|
credential = self._select_credential(env_credentials)
|
|
118
|
-
logger.debug(
|
|
118
|
+
logger.debug("Selected credential: %s", credential)
|
|
119
119
|
if credential:
|
|
120
120
|
credential.last_used = datetime.now(timezone.utc)
|
|
121
121
|
self._write_credentials(credentials)
|
|
122
122
|
return credential
|
|
123
123
|
|
|
124
|
-
logger.debug(
|
|
124
|
+
logger.debug("No credentials found for %s. Creating new ones.", self.endpoint)
|
|
125
125
|
return self._create_new_credentials()
|
|
126
126
|
|
|
127
127
|
def reset_credentials(self) -> None:
|
|
@@ -130,7 +130,7 @@ class CredentialManager:
|
|
|
130
130
|
if self.endpoint in credentials:
|
|
131
131
|
del credentials[self.endpoint]
|
|
132
132
|
self._write_credentials(credentials)
|
|
133
|
-
logger.info(
|
|
133
|
+
logger.info("Credentials for %s have been reset.", self.endpoint)
|
|
134
134
|
|
|
135
135
|
def _get_bridge_tokens(self) -> Optional[BridgeToken]:
|
|
136
136
|
"""Get bridge tokens from the identity endpoint."""
|
|
@@ -141,13 +141,13 @@ class CredentialManager:
|
|
|
141
141
|
)
|
|
142
142
|
response = requests.post(bridge_endpoint, verify=self.cert_path)
|
|
143
143
|
if not response.ok:
|
|
144
|
-
logger.error(
|
|
144
|
+
logger.error("Failed to get bridge tokens: %s", response.status_code)
|
|
145
145
|
return None
|
|
146
146
|
|
|
147
147
|
data = response.json()
|
|
148
148
|
return BridgeToken(read_key=data["readKey"], write_key=data["writeKey"])
|
|
149
149
|
except requests.RequestException as e:
|
|
150
|
-
logger.error(
|
|
150
|
+
logger.error("Failed to get bridge tokens: %s", e)
|
|
151
151
|
return None
|
|
152
152
|
|
|
153
153
|
def _poll_read_key(self, read_key: str) -> Optional[str]:
|
|
@@ -169,11 +169,11 @@ class CredentialManager:
|
|
|
169
169
|
continue
|
|
170
170
|
else:
|
|
171
171
|
# Error occurred
|
|
172
|
-
logger.error(
|
|
172
|
+
logger.error("Error polling read key: %s", response.status_code)
|
|
173
173
|
return None
|
|
174
174
|
|
|
175
175
|
except requests.RequestException as e:
|
|
176
|
-
logger.error(
|
|
176
|
+
logger.error("Error polling read key: %s", e)
|
|
177
177
|
return None
|
|
178
178
|
|
|
179
179
|
logger.error("Polling timed out")
|
|
@@ -198,7 +198,7 @@ class CredentialManager:
|
|
|
198
198
|
data = response.json()
|
|
199
199
|
return data.get("clientId"), data.get("clientSecret"), display_name
|
|
200
200
|
except requests.RequestException as e:
|
|
201
|
-
logger.error(
|
|
201
|
+
logger.error("Failed to create client: %s", e)
|
|
202
202
|
return None
|
|
203
203
|
|
|
204
204
|
def _create_new_credentials(self) -> Optional[ClientCredential]:
|