Results API¶
io ¶
API client for the results extension.
This module exposes :class:ResultsAPI as the low-level entry point
for analysis and result persistence.
Examples:
>>> from owi.metadatabase.results import ResultsAPI
>>> isinstance(ResultsAPI(token="dummy"), ResultsAPI)
True
Classes¶
ResultsAPI ¶
Bases: API
Low-level API client for the results extension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_subdir
|
str
|
API sub-path appended to the base root. |
"/results/routes/"
|
**kwargs
|
Forwarded to :class: |
{}
|
Examples:
Source code in src/owi/metadatabase/results/io.py
Functions¶
ping ¶
Return a basic health response.
Examples:
list_analyses ¶
Return analysis metadata rows.
Examples:
>>> from unittest.mock import patch
>>> api = ResultsAPI(token="dummy")
>>> result = (pd.DataFrame({'id': [1]}), {'existance': True})
>>> with patch.object(ResultsAPI, 'process_data', return_value=result):
... out = api.list_analyses(name='WindSpeedHistogram')
>>> out['exists']
True
Source code in src/owi/metadatabase/results/io.py
get_analysis ¶
Return a single analysis row.
To make sure a single analysis is returned, use either the id parameter,
or, for a more user-friendly query, the following combination of parameters
that identify a single analysis, i.e., name, model_definition__title,
timestamp, and location__title, since they uniquely identify an
analysis in the backend.
Examples:
>>> from unittest.mock import patch
>>> api = ResultsAPI(token="dummy")
>>> result = (pd.DataFrame({'id': [1]}), {'existance': True, 'id': 1})
>>> with patch.object(ResultsAPI, 'process_data', return_value=result):
... out = api.get_analysis(id=1)
>>> out['exists']
True
>>> out['id']
1
>>> api = ResultsAPI(token="dummy")
>>> analysis_params = {
... 'analysis__name': 'WindSpeedHistogram',
... 'model_definition__title': 'ERA5 reanalysis',
... 'timestamp': '2023-01-01T00:00:00Z',
... 'location__title': 'Test Location',
... }
Source code in src/owi/metadatabase/results/io.py
list_results ¶
Return raw result rows from the backend.
To return all the results related to a specific analysis, use on of the
following:
* analysis or analysis__id parameter with the analysis ID.
* analysis__name, analysis__model_definition__title,
analysis__timestamp, and analysis__location__title parameters
because this identifies a single analysis (see get_analysis).
Examples:
>>> from owi.metadatabase.results import ResultsAPI
>>> api = ResultsAPI(token="dummy")
>>> results = api.list_results(analysis__id=1)
>>> results['exists']
True
Source code in src/owi/metadatabase/results/io.py
get_results_raw ¶
Return a single raw result row.
Source code in src/owi/metadatabase/results/io.py
create_analysis ¶
Create a new analysis record.
Source code in src/owi/metadatabase/results/io.py
create_result ¶
Create a single result row.
Source code in src/owi/metadatabase/results/io.py
update_result ¶
Patch a single result row.
Source code in src/owi/metadatabase/results/io.py
create_results_bulk ¶
Create multiple result rows in one request.
Falls back to single-row creation when the backend does not expose a bulk mutation endpoint.
Source code in src/owi/metadatabase/results/io.py
create_or_update_results_bulk ¶
Create missing result rows and patch existing ones in bulk.
Existing rows are matched within the same analysis using the
short_description field of each payload.
If duplicate short_description values are found for the same result (row) in the backend,
the method will raise an error to avoid ambiguity in the update process.
In this case, the user should first resolve the duplicates in the backend, e.g. by
renaming the short_description values, and then retry the bulk create or update operation.
Source code in src/owi/metadatabase/results/io.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |