rapidata 2.37.0__py3-none-any.whl → 2.39.0__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 +3 -4
- rapidata/api_client/__init__.py +4 -5
- rapidata/api_client/api/benchmark_api.py +289 -3
- rapidata/api_client/api/leaderboard_api.py +35 -1
- rapidata/api_client/api/participant_api.py +289 -3
- rapidata/api_client/api/validation_set_api.py +119 -400
- rapidata/api_client/models/__init__.py +4 -5
- rapidata/api_client/models/ab_test_selection_a_inner.py +1 -1
- rapidata/api_client/models/compare_workflow_model1.py +1 -8
- rapidata/api_client/models/conditional_validation_selection.py +4 -9
- rapidata/api_client/models/confidence_interval.py +98 -0
- rapidata/api_client/models/create_simple_pipeline_model_pipeline_steps_inner.py +8 -22
- rapidata/api_client/models/get_standing_by_id_result.py +7 -2
- rapidata/api_client/models/get_validation_set_by_id_result.py +4 -2
- rapidata/api_client/models/simple_workflow_model1.py +1 -8
- rapidata/api_client/models/standing_by_leaderboard.py +10 -4
- rapidata/api_client/models/update_benchmark_model.py +87 -0
- rapidata/api_client/models/update_participant_model.py +87 -0
- rapidata/api_client/models/update_validation_set_model.py +93 -0
- rapidata/api_client/models/validation_chance.py +20 -3
- rapidata/api_client/models/validation_set_model.py +5 -42
- rapidata/api_client_README.md +7 -7
- rapidata/rapidata_client/__init__.py +1 -4
- rapidata/rapidata_client/api/{rapidata_exception.py → rapidata_api_client.py} +119 -2
- rapidata/rapidata_client/benchmark/leaderboard/rapidata_leaderboard.py +88 -46
- rapidata/rapidata_client/benchmark/participant/_participant.py +26 -9
- rapidata/rapidata_client/benchmark/rapidata_benchmark.py +310 -210
- rapidata/rapidata_client/benchmark/rapidata_benchmark_manager.py +134 -75
- rapidata/rapidata_client/config/__init__.py +3 -0
- rapidata/rapidata_client/config/logger.py +135 -0
- rapidata/rapidata_client/config/logging_config.py +58 -0
- rapidata/rapidata_client/config/managed_print.py +6 -0
- rapidata/rapidata_client/config/order_config.py +14 -0
- rapidata/rapidata_client/config/rapidata_config.py +15 -10
- rapidata/rapidata_client/config/tracer.py +130 -0
- rapidata/rapidata_client/config/upload_config.py +14 -0
- rapidata/rapidata_client/datapoints/_datapoint.py +1 -1
- rapidata/rapidata_client/datapoints/assets/__init__.py +1 -0
- rapidata/rapidata_client/datapoints/assets/_base_asset.py +2 -0
- rapidata/rapidata_client/datapoints/assets/_media_asset.py +1 -1
- rapidata/rapidata_client/datapoints/assets/_sessions.py +2 -2
- rapidata/rapidata_client/datapoints/assets/_text_asset.py +2 -2
- rapidata/rapidata_client/datapoints/assets/data_type_enum.py +1 -1
- rapidata/rapidata_client/datapoints/metadata/_media_asset_metadata.py +9 -8
- rapidata/rapidata_client/datapoints/metadata/_prompt_metadata.py +1 -2
- rapidata/rapidata_client/demographic/demographic_manager.py +16 -14
- rapidata/rapidata_client/filter/_base_filter.py +11 -5
- rapidata/rapidata_client/filter/age_filter.py +9 -3
- rapidata/rapidata_client/filter/and_filter.py +20 -5
- rapidata/rapidata_client/filter/campaign_filter.py +7 -1
- rapidata/rapidata_client/filter/country_filter.py +8 -2
- rapidata/rapidata_client/filter/custom_filter.py +9 -3
- rapidata/rapidata_client/filter/gender_filter.py +9 -3
- rapidata/rapidata_client/filter/language_filter.py +12 -5
- rapidata/rapidata_client/filter/models/age_group.py +4 -4
- rapidata/rapidata_client/filter/models/gender.py +4 -2
- rapidata/rapidata_client/filter/new_user_filter.py +3 -4
- rapidata/rapidata_client/filter/not_filter.py +17 -5
- rapidata/rapidata_client/filter/or_filter.py +20 -5
- rapidata/rapidata_client/filter/rapidata_filters.py +12 -9
- rapidata/rapidata_client/filter/response_count_filter.py +6 -0
- rapidata/rapidata_client/filter/user_score_filter.py +17 -5
- rapidata/rapidata_client/order/_rapidata_dataset.py +45 -17
- rapidata/rapidata_client/order/_rapidata_order_builder.py +19 -13
- rapidata/rapidata_client/order/rapidata_order.py +60 -48
- rapidata/rapidata_client/order/rapidata_order_manager.py +231 -197
- rapidata/rapidata_client/order/rapidata_results.py +71 -57
- rapidata/rapidata_client/rapidata_client.py +36 -23
- rapidata/rapidata_client/referee/__init__.py +1 -1
- rapidata/rapidata_client/referee/_base_referee.py +3 -1
- rapidata/rapidata_client/referee/_early_stopping_referee.py +2 -2
- rapidata/rapidata_client/selection/_base_selection.py +6 -0
- rapidata/rapidata_client/selection/ab_test_selection.py +7 -3
- rapidata/rapidata_client/selection/capped_selection.py +2 -2
- rapidata/rapidata_client/selection/conditional_validation_selection.py +12 -6
- rapidata/rapidata_client/selection/demographic_selection.py +9 -6
- rapidata/rapidata_client/selection/rapidata_selections.py +11 -8
- rapidata/rapidata_client/selection/shuffling_selection.py +5 -5
- rapidata/rapidata_client/selection/static_selection.py +5 -10
- rapidata/rapidata_client/selection/validation_selection.py +9 -5
- rapidata/rapidata_client/settings/_rapidata_setting.py +8 -0
- rapidata/rapidata_client/settings/alert_on_fast_response.py +8 -5
- rapidata/rapidata_client/settings/allow_neither_both.py +1 -0
- rapidata/rapidata_client/settings/custom_setting.py +3 -2
- rapidata/rapidata_client/settings/free_text_minimum_characters.py +9 -4
- rapidata/rapidata_client/settings/models/translation_behaviour_options.py +3 -2
- rapidata/rapidata_client/settings/no_shuffle.py +4 -2
- rapidata/rapidata_client/settings/play_video_until_the_end.py +7 -4
- rapidata/rapidata_client/settings/rapidata_settings.py +4 -3
- rapidata/rapidata_client/settings/translation_behaviour.py +7 -5
- rapidata/rapidata_client/validation/rapidata_validation_set.py +23 -17
- rapidata/rapidata_client/validation/rapids/box.py +3 -1
- rapidata/rapidata_client/validation/rapids/rapids.py +7 -1
- rapidata/rapidata_client/validation/rapids/rapids_manager.py +174 -141
- rapidata/rapidata_client/validation/validation_set_manager.py +285 -268
- rapidata/rapidata_client/workflow/__init__.py +1 -1
- rapidata/rapidata_client/workflow/_base_workflow.py +6 -1
- rapidata/rapidata_client/workflow/_classify_workflow.py +6 -0
- rapidata/rapidata_client/workflow/_compare_workflow.py +6 -0
- rapidata/rapidata_client/workflow/_draw_workflow.py +6 -0
- rapidata/rapidata_client/workflow/_evaluation_workflow.py +6 -0
- rapidata/rapidata_client/workflow/_free_text_workflow.py +6 -0
- rapidata/rapidata_client/workflow/_locate_workflow.py +6 -0
- rapidata/rapidata_client/workflow/_ranking_workflow.py +12 -0
- rapidata/rapidata_client/workflow/_select_words_workflow.py +6 -0
- rapidata/rapidata_client/workflow/_timestamp_workflow.py +6 -0
- rapidata/service/__init__.py +1 -1
- rapidata/service/credential_manager.py +1 -1
- rapidata/service/local_file_service.py +9 -8
- rapidata/service/openapi_service.py +2 -2
- {rapidata-2.37.0.dist-info → rapidata-2.39.0.dist-info}/METADATA +4 -1
- {rapidata-2.37.0.dist-info → rapidata-2.39.0.dist-info}/RECORD +114 -107
- rapidata/rapidata_client/logging/__init__.py +0 -2
- rapidata/rapidata_client/logging/logger.py +0 -122
- rapidata/rapidata_client/logging/output_manager.py +0 -20
- {rapidata-2.37.0.dist-info → rapidata-2.39.0.dist-info}/LICENSE +0 -0
- {rapidata-2.37.0.dist-info → rapidata-2.39.0.dist-info}/WHEEL +0 -0
|
@@ -7,28 +7,34 @@ from rapidata.api_client.models.user_score_user_filter_model import (
|
|
|
7
7
|
|
|
8
8
|
class UserScoreFilter(RapidataFilter):
|
|
9
9
|
"""UserScoreFilter Class
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
Can be used to filter who to target based on their user score.
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
Args:
|
|
14
14
|
lower_bound (float): The lower bound of the user score.
|
|
15
15
|
upper_bound (float): The upper bound of the user score.
|
|
16
16
|
dimension (str): The dimension of the userScore to be considerd for the filter.
|
|
17
17
|
|
|
18
|
-
Example:
|
|
18
|
+
Example:
|
|
19
19
|
```python
|
|
20
20
|
UserScoreFilter(0.5, 0.9)
|
|
21
21
|
```
|
|
22
22
|
This will only show the order to users that have a UserScore of >=0.5 and <=0.9
|
|
23
23
|
"""
|
|
24
|
-
|
|
24
|
+
|
|
25
|
+
def __init__(
|
|
26
|
+
self,
|
|
27
|
+
lower_bound: float = 0.0,
|
|
28
|
+
upper_bound: float = 1.0,
|
|
29
|
+
dimension: str | None = None,
|
|
30
|
+
):
|
|
25
31
|
if lower_bound < 0 or lower_bound > 1:
|
|
26
32
|
raise ValueError("The lower bound must be between 0 and 1.")
|
|
27
33
|
if upper_bound < 0 or upper_bound > 1:
|
|
28
34
|
raise ValueError("The upper bound must be between 0 and 1.")
|
|
29
35
|
if lower_bound >= upper_bound:
|
|
30
36
|
raise ValueError("The lower bound must be less than the upper bound.")
|
|
31
|
-
|
|
37
|
+
|
|
32
38
|
self.upper_bound = upper_bound
|
|
33
39
|
self.lower_bound = lower_bound
|
|
34
40
|
self.dimension = dimension
|
|
@@ -40,3 +46,9 @@ class UserScoreFilter(RapidataFilter):
|
|
|
40
46
|
lowerbound=self.lower_bound,
|
|
41
47
|
dimension=self.dimension,
|
|
42
48
|
)
|
|
49
|
+
|
|
50
|
+
def __str__(self) -> str:
|
|
51
|
+
return f"UserScoreFilter(lower_bound={self.lower_bound}, upper_bound={self.upper_bound}, dimension={self.dimension})"
|
|
52
|
+
|
|
53
|
+
def __repr__(self) -> str:
|
|
54
|
+
return f"UserScoreFilter(lower_bound={self.lower_bound!r}, upper_bound={self.upper_bound!r}, dimension={self.dimension!r})"
|
|
@@ -6,18 +6,17 @@ from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
|
6
6
|
from tqdm import tqdm
|
|
7
7
|
|
|
8
8
|
from typing import Generator
|
|
9
|
-
from rapidata.rapidata_client.
|
|
10
|
-
logger,
|
|
11
|
-
managed_print,
|
|
12
|
-
RapidataOutputManager,
|
|
13
|
-
)
|
|
9
|
+
from rapidata.rapidata_client.config import logger, managed_print
|
|
14
10
|
import time
|
|
15
11
|
import threading
|
|
16
|
-
from rapidata.rapidata_client.api.
|
|
12
|
+
from rapidata.rapidata_client.api.rapidata_api_client import (
|
|
17
13
|
suppress_rapidata_error_logging,
|
|
18
14
|
)
|
|
19
15
|
from rapidata.rapidata_client.config.rapidata_config import rapidata_config
|
|
20
16
|
|
|
17
|
+
# Add OpenTelemetry context imports for thread propagation
|
|
18
|
+
from opentelemetry import context as otel_context
|
|
19
|
+
|
|
21
20
|
|
|
22
21
|
def chunk_list(lst: list, chunk_size: int) -> Generator:
|
|
23
22
|
for i in range(0, len(lst), chunk_size):
|
|
@@ -62,22 +61,37 @@ class RapidataDataset:
|
|
|
62
61
|
)
|
|
63
62
|
return datapoint
|
|
64
63
|
|
|
64
|
+
def upload_with_context(
|
|
65
|
+
context: otel_context.Context, datapoint: Datapoint, index: int
|
|
66
|
+
) -> Datapoint:
|
|
67
|
+
"""Wrapper function that runs upload_text_datapoint with the provided context."""
|
|
68
|
+
token = otel_context.attach(context)
|
|
69
|
+
try:
|
|
70
|
+
return upload_text_datapoint(datapoint, index)
|
|
71
|
+
finally:
|
|
72
|
+
otel_context.detach(token)
|
|
73
|
+
|
|
65
74
|
successful_uploads: list[Datapoint] = []
|
|
66
75
|
failed_uploads: list[Datapoint] = []
|
|
67
76
|
|
|
77
|
+
# Capture the current OpenTelemetry context before creating threads
|
|
78
|
+
current_context = otel_context.get_current()
|
|
79
|
+
|
|
68
80
|
total_uploads = len(datapoints)
|
|
69
81
|
with ThreadPoolExecutor(
|
|
70
|
-
max_workers=rapidata_config.
|
|
82
|
+
max_workers=rapidata_config.upload.maxWorkers
|
|
71
83
|
) as executor:
|
|
72
84
|
future_to_datapoint = {
|
|
73
|
-
executor.submit(
|
|
85
|
+
executor.submit(
|
|
86
|
+
upload_with_context, current_context, datapoint, i
|
|
87
|
+
): datapoint
|
|
74
88
|
for i, datapoint in enumerate(datapoints)
|
|
75
89
|
}
|
|
76
90
|
|
|
77
91
|
with tqdm(
|
|
78
92
|
total=total_uploads,
|
|
79
93
|
desc="Uploading text datapoints",
|
|
80
|
-
disable=
|
|
94
|
+
disable=rapidata_config.logging.silent_mode,
|
|
81
95
|
) as pbar:
|
|
82
96
|
for future in as_completed(future_to_datapoint.keys()):
|
|
83
97
|
datapoint = future_to_datapoint[future]
|
|
@@ -119,7 +133,7 @@ class RapidataDataset:
|
|
|
119
133
|
urls = datapoint.get_urls()
|
|
120
134
|
|
|
121
135
|
last_exception = None
|
|
122
|
-
for attempt in range(rapidata_config.
|
|
136
|
+
for attempt in range(rapidata_config.upload.maxRetries):
|
|
123
137
|
try:
|
|
124
138
|
with suppress_rapidata_error_logging():
|
|
125
139
|
self.openapi_service.dataset_api.dataset_dataset_id_datapoints_post(
|
|
@@ -136,7 +150,7 @@ class RapidataDataset:
|
|
|
136
150
|
|
|
137
151
|
except Exception as e:
|
|
138
152
|
last_exception = e
|
|
139
|
-
if attempt < rapidata_config.
|
|
153
|
+
if attempt < rapidata_config.upload.maxRetries - 1:
|
|
140
154
|
# Exponential backoff: wait 1s, then 2s, then 4s
|
|
141
155
|
retry_delay = 2**attempt
|
|
142
156
|
time.sleep(retry_delay)
|
|
@@ -144,13 +158,13 @@ class RapidataDataset:
|
|
|
144
158
|
logger.debug(
|
|
145
159
|
"Retrying %s of %s...",
|
|
146
160
|
attempt + 1,
|
|
147
|
-
rapidata_config.
|
|
161
|
+
rapidata_config.upload.maxRetries,
|
|
148
162
|
)
|
|
149
163
|
|
|
150
164
|
# If we get here, all retries failed
|
|
151
165
|
local_failed.append(datapoint)
|
|
152
166
|
tqdm.write(
|
|
153
|
-
f"Upload failed for {datapoint} after {rapidata_config.
|
|
167
|
+
f"Upload failed for {datapoint} after {rapidata_config.upload.maxRetries} attempts. \nFinal error: \n{str(last_exception)}"
|
|
154
168
|
)
|
|
155
169
|
|
|
156
170
|
return local_successful, local_failed
|
|
@@ -183,7 +197,7 @@ class RapidataDataset:
|
|
|
183
197
|
with tqdm(
|
|
184
198
|
total=total_uploads,
|
|
185
199
|
desc="Uploading datapoints",
|
|
186
|
-
disable=
|
|
200
|
+
disable=rapidata_config.logging.silent_mode,
|
|
187
201
|
) as pbar:
|
|
188
202
|
prev_ready = 0
|
|
189
203
|
prev_failed = 0
|
|
@@ -291,17 +305,31 @@ class RapidataDataset:
|
|
|
291
305
|
successful_uploads: list[Datapoint] = []
|
|
292
306
|
failed_uploads: list[Datapoint] = []
|
|
293
307
|
|
|
308
|
+
def process_upload_with_context(
|
|
309
|
+
context: otel_context.Context, datapoint: Datapoint, index: int
|
|
310
|
+
) -> tuple[list[Datapoint], list[Datapoint]]:
|
|
311
|
+
"""Wrapper function that runs _process_single_upload with the provided context."""
|
|
312
|
+
token = otel_context.attach(context)
|
|
313
|
+
try:
|
|
314
|
+
return self._process_single_upload(datapoint, index)
|
|
315
|
+
finally:
|
|
316
|
+
otel_context.detach(token)
|
|
317
|
+
|
|
318
|
+
# Capture the current OpenTelemetry context before creating threads
|
|
319
|
+
current_context = otel_context.get_current()
|
|
320
|
+
|
|
294
321
|
try:
|
|
295
322
|
with ThreadPoolExecutor(
|
|
296
|
-
max_workers=rapidata_config.
|
|
323
|
+
max_workers=rapidata_config.upload.maxWorkers
|
|
297
324
|
) as executor:
|
|
298
325
|
# Process uploads in chunks to avoid overwhelming the system
|
|
299
326
|
for chunk_idx, chunk in enumerate(chunk_list(datapoints, chunk_size)):
|
|
300
327
|
futures = [
|
|
301
328
|
executor.submit(
|
|
302
|
-
|
|
329
|
+
process_upload_with_context,
|
|
330
|
+
current_context,
|
|
303
331
|
datapoint,
|
|
304
|
-
|
|
332
|
+
chunk_idx * chunk_size + i,
|
|
305
333
|
)
|
|
306
334
|
for i, datapoint in enumerate(chunk)
|
|
307
335
|
]
|
|
@@ -19,10 +19,11 @@ from rapidata.rapidata_client.exceptions.failed_upload_exception import (
|
|
|
19
19
|
_parse_failed_uploads,
|
|
20
20
|
)
|
|
21
21
|
from rapidata.rapidata_client.filter import RapidataFilter
|
|
22
|
-
from rapidata.rapidata_client.
|
|
22
|
+
from rapidata.rapidata_client.config import (
|
|
23
23
|
logger,
|
|
24
24
|
managed_print,
|
|
25
|
-
|
|
25
|
+
rapidata_config,
|
|
26
|
+
tracer,
|
|
26
27
|
)
|
|
27
28
|
from rapidata.rapidata_client.validation.validation_set_manager import (
|
|
28
29
|
ValidationSetManager,
|
|
@@ -35,9 +36,9 @@ from rapidata.rapidata_client.selection._base_selection import RapidataSelection
|
|
|
35
36
|
from rapidata.rapidata_client.settings import RapidataSetting
|
|
36
37
|
from rapidata.rapidata_client.workflow import Workflow
|
|
37
38
|
from rapidata.service.openapi_service import OpenAPIService
|
|
38
|
-
from rapidata.rapidata_client.
|
|
39
|
-
from rapidata.rapidata_client.api.rapidata_exception import (
|
|
39
|
+
from rapidata.rapidata_client.api.rapidata_api_client import (
|
|
40
40
|
suppress_rapidata_error_logging,
|
|
41
|
+
RapidataApiClient,
|
|
41
42
|
)
|
|
42
43
|
|
|
43
44
|
|
|
@@ -153,14 +154,19 @@ class RapidataOrderBuilder:
|
|
|
153
154
|
"Using recommended validation set with ID: %s", self.__validation_set_id
|
|
154
155
|
)
|
|
155
156
|
except Exception as e:
|
|
156
|
-
logger.
|
|
157
|
+
logger.debug("No recommended validation set found, error: %s", e)
|
|
157
158
|
|
|
158
|
-
if
|
|
159
|
+
if (
|
|
160
|
+
len(self.__datapoints)
|
|
161
|
+
< rapidata_config.order.minOrderDatapointsForValidation
|
|
162
|
+
):
|
|
159
163
|
logger.debug(
|
|
160
164
|
"No recommended validation set found, dataset too small to create one."
|
|
161
165
|
)
|
|
162
166
|
return
|
|
163
167
|
|
|
168
|
+
logger.info("No recommended validation set found, creating new one.")
|
|
169
|
+
|
|
164
170
|
managed_print()
|
|
165
171
|
managed_print(
|
|
166
172
|
f"No recommended validation set found, new one will be created.\nWe recommend adding some truths to ensure the order is accurate."
|
|
@@ -170,7 +176,9 @@ class RapidataOrderBuilder:
|
|
|
170
176
|
order_name=self._name,
|
|
171
177
|
datapoints=random.sample(
|
|
172
178
|
self.__datapoints,
|
|
173
|
-
min(
|
|
179
|
+
min(
|
|
180
|
+
rapidata_config.order.autoValidationSetSize, len(self.__datapoints)
|
|
181
|
+
),
|
|
174
182
|
),
|
|
175
183
|
settings=self.__settings,
|
|
176
184
|
)
|
|
@@ -182,9 +190,6 @@ class RapidataOrderBuilder:
|
|
|
182
190
|
"""
|
|
183
191
|
Create the Rapidata order by making the necessary API calls based on the builder's configuration.
|
|
184
192
|
|
|
185
|
-
Args:
|
|
186
|
-
max_upload_workers (int, optional): The maximum number of worker threads for processing media paths. Defaults to 10.
|
|
187
|
-
|
|
188
193
|
Raises:
|
|
189
194
|
ValueError: If both media paths and texts are provided, or if neither is provided.
|
|
190
195
|
AssertionError: If the workflow is a CompareWorkflow and media paths are not in pairs.
|
|
@@ -225,10 +230,11 @@ class RapidataOrderBuilder:
|
|
|
225
230
|
logger.debug("Adding media to the order.")
|
|
226
231
|
|
|
227
232
|
if self.__dataset:
|
|
228
|
-
|
|
233
|
+
with tracer.start_as_current_span("add_datapoints"):
|
|
234
|
+
_, failed_uploads = self.__dataset.add_datapoints(self.__datapoints)
|
|
229
235
|
|
|
230
|
-
|
|
231
|
-
|
|
236
|
+
if failed_uploads:
|
|
237
|
+
raise FailedUploadException(self.__dataset, order, failed_uploads)
|
|
232
238
|
|
|
233
239
|
else:
|
|
234
240
|
raise RuntimeError(
|
|
@@ -20,12 +20,13 @@ from rapidata.api_client.models.preliminary_download_model import (
|
|
|
20
20
|
from rapidata.api_client.models.workflow_artifact_model import WorkflowArtifactModel
|
|
21
21
|
from rapidata.rapidata_client.order.rapidata_results import RapidataResults
|
|
22
22
|
from rapidata.service.openapi_service import OpenAPIService
|
|
23
|
-
from rapidata.rapidata_client.
|
|
23
|
+
from rapidata.rapidata_client.config import (
|
|
24
24
|
logger,
|
|
25
25
|
managed_print,
|
|
26
|
-
|
|
26
|
+
rapidata_config,
|
|
27
|
+
tracer,
|
|
27
28
|
)
|
|
28
|
-
from rapidata.rapidata_client.api.
|
|
29
|
+
from rapidata.rapidata_client.api.rapidata_api_client import (
|
|
29
30
|
suppress_rapidata_error_logging,
|
|
30
31
|
)
|
|
31
32
|
|
|
@@ -74,36 +75,40 @@ class RapidataOrder:
|
|
|
74
75
|
|
|
75
76
|
def run(self) -> "RapidataOrder":
|
|
76
77
|
"""Runs the order to start collecting responses."""
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
self.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
78
|
+
with tracer.start_as_current_span("RapidataOrder.run"):
|
|
79
|
+
logger.info("Starting order '%s'", self)
|
|
80
|
+
self.__openapi_service.order_api.order_order_id_submit_post(
|
|
81
|
+
self.id, SubmitOrderModel(ignoreFailedDatapoints=True)
|
|
82
|
+
)
|
|
83
|
+
logger.debug("Order '%s' has been started.", self)
|
|
84
|
+
managed_print(
|
|
85
|
+
f"Order '{self.name}' is now viewable under: {self.order_details_page}"
|
|
86
|
+
)
|
|
87
|
+
return self
|
|
86
88
|
|
|
87
89
|
def pause(self) -> None:
|
|
88
90
|
"""Pauses the order."""
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
with tracer.start_as_current_span("RapidataOrder.pause"):
|
|
92
|
+
logger.info("Pausing order '%s'", self)
|
|
93
|
+
self.__openapi_service.order_api.order_order_id_pause_post(self.id)
|
|
94
|
+
logger.debug("Order '%s' has been paused.", self)
|
|
95
|
+
managed_print(f"Order '{self}' has been paused.")
|
|
93
96
|
|
|
94
97
|
def unpause(self) -> None:
|
|
95
98
|
"""Unpauses/resumes the order."""
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
with tracer.start_as_current_span("RapidataOrder.unpause"):
|
|
100
|
+
logger.info("Unpausing order '%s'", self)
|
|
101
|
+
self.__openapi_service.order_api.order_order_id_resume_post(self.id)
|
|
102
|
+
logger.debug("Order '%s' has been unpaused.", self)
|
|
103
|
+
managed_print(f"Order '{self}' has been unpaused.")
|
|
100
104
|
|
|
101
105
|
def delete(self) -> None:
|
|
102
106
|
"""Deletes the order."""
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
+
with tracer.start_as_current_span("RapidataOrder.delete"):
|
|
108
|
+
logger.info("Deleting order '%s'", self)
|
|
109
|
+
self.__openapi_service.order_api.order_order_id_delete(self.id)
|
|
110
|
+
logger.debug("Order '%s' has been deleted.", self)
|
|
111
|
+
managed_print(f"Order '{self}' has been deleted.")
|
|
107
112
|
|
|
108
113
|
def get_status(self) -> str:
|
|
109
114
|
"""
|
|
@@ -119,7 +124,8 @@ class RapidataOrder:
|
|
|
119
124
|
Completed: The order has been completed.\n
|
|
120
125
|
Failed: The order has failed.
|
|
121
126
|
"""
|
|
122
|
-
|
|
127
|
+
with tracer.start_as_current_span("RapidataOrder.get_status"):
|
|
128
|
+
return self.__openapi_service.order_api.order_order_id_get(self.id).state
|
|
123
129
|
|
|
124
130
|
def display_progress_bar(self, refresh_rate: int = 5) -> None:
|
|
125
131
|
"""
|
|
@@ -150,7 +156,7 @@ class RapidataOrder:
|
|
|
150
156
|
desc="Processing order",
|
|
151
157
|
unit="%",
|
|
152
158
|
bar_format="{desc}: {percentage:3.0f}%|{bar}| completed [{elapsed}<{remaining}, {rate_fmt}]",
|
|
153
|
-
disable=
|
|
159
|
+
disable=rapidata_config.logging.silent_mode,
|
|
154
160
|
) as pbar:
|
|
155
161
|
last_percentage = 0
|
|
156
162
|
while True:
|
|
@@ -193,31 +199,37 @@ class RapidataOrder:
|
|
|
193
199
|
preliminary_results: If True, returns the preliminary results of the order. Defaults to False.
|
|
194
200
|
Note that preliminary results are not final and may not contain all the datapoints & responses. Only the onese that are already available.
|
|
195
201
|
"""
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
202
|
+
with tracer.start_as_current_span("RapidataOrder.get_results"):
|
|
203
|
+
logger.info("Getting results for order '%s'...", self)
|
|
204
|
+
if preliminary_results and self.get_status() not in [OrderState.COMPLETED]:
|
|
205
|
+
return self.__get_preliminary_results()
|
|
206
|
+
|
|
207
|
+
elif preliminary_results and self.get_status() in [OrderState.COMPLETED]:
|
|
208
|
+
managed_print("Order is already completed. Returning final results.")
|
|
209
|
+
|
|
210
|
+
while (state := self.get_status()) not in [
|
|
211
|
+
OrderState.COMPLETED,
|
|
212
|
+
OrderState.PAUSED,
|
|
213
|
+
OrderState.MANUALREVIEW,
|
|
214
|
+
OrderState.FAILED,
|
|
215
|
+
]:
|
|
216
|
+
sleep(5)
|
|
217
|
+
logger.debug(
|
|
218
|
+
"Order '%s' is in state %s not yet completed. Waiting...",
|
|
219
|
+
self,
|
|
220
|
+
state,
|
|
221
|
+
)
|
|
210
222
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
223
|
+
try:
|
|
224
|
+
return RapidataResults(
|
|
225
|
+
json.loads(
|
|
226
|
+
self.__openapi_service.order_api.order_order_id_download_results_get(
|
|
227
|
+
order_id=self.id
|
|
228
|
+
)
|
|
216
229
|
)
|
|
217
230
|
)
|
|
218
|
-
)
|
|
219
|
-
|
|
220
|
-
raise Exception(f"Failed to get order results: {str(e)}") from e
|
|
231
|
+
except (ApiException, json.JSONDecodeError) as e:
|
|
232
|
+
raise Exception(f"Failed to get order results: {str(e)}") from e
|
|
221
233
|
|
|
222
234
|
def view(self) -> None:
|
|
223
235
|
"""
|