rs_workflows/record_performance.md
Module with task used to insert or update flow run table.
extract_min_datetime(list_items)
Finds the earliest datetime to insert in column sensing_start_datetime of product_expected.
Source code in docs/rs-client-libraries/rs_workflows/record_performance.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | |
get_db_session()
Initialize and return a DB session.
Source code in docs/rs-client-libraries/rs_workflows/record_performance.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
get_flow_run_id(prefect_flow_id)
Return id from flow_run table for given prefect_flow_id.
Source code in docs/rs-client-libraries/rs_workflows/record_performance.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
get_pi_category_id(eopf_type)
Return id from pi_category table based on eopf_type.
Mapping rules (example): - S01 -> mission='S1', name='L12-NRT' - S02 -> mission='S2', name='L1C' - S03* -> mission='S3', name='NRT'
"S01SIWOCN": 5, # Level-1/2 IW/GRD Sentinel-1
"S01SIWV": 6, # Level-2 Wave Sentinel-1
"S02L1C": 9, # Level-1C Sentinel-2
"S02L2A": 10, # Level-2A Sentinel-2
"S03NRT": 12 # All NRT Sentinel-3
Source code in docs/rs-client-libraries/rs_workflows/record_performance.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
record_flow_run(start_date=None, stop_date=None, status=None, flow_run_type=None, mission=None, dpr_processor_name=None, dpr_processor_version=None, dpr_processor_unit=None, dpr_processing_input_stac_items=None)
Insert or update a record in flow_run table and return the DB id.
Source code in docs/rs-client-libraries/rs_workflows/record_performance.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
record_performance_indicators(start_date=None, stop_date=None, status=None, flow_run_type=None, mission=None, dpr_processor_name=None, dpr_processor_version=None, dpr_processor_unit=None, dpr_processing_input_stac_items=None, payload=None, stac_items=None)
Main task that orchestrates DB recording for flow_run and product_realised.
Source code in docs/rs-client-libraries/rs_workflows/record_performance.py
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 | |
record_product_expected(flow_run_id, dpr_processor_name, payload)
Insert expected product definitions into the product_expected table for a given flow run.
This task records all product types that are expected to be generated by a specific
DPR processor (currently only s3_l0). It defines each expected product type with
its minimum and maximum expected counts and stores them in the product_expected table.
Behavior
- Inserts one record per expected product type, if it does not already exist
for the given
flow_run_id. - Uses a hardcoded mapping of expected product types and their min/max count.
- Derives the sensing start time from the input STAC items in the payload.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flow_run_id
|
str
|
Unique identifier of the current flow run. |
required |
dpr_processor_name
|
str
|
Name of the DPR processor (e.g., |
required |
payload
|
dict
|
JSON-like payload containing workflow metadata and STAC inputs/outputs. |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If an expected EOPF type from the payload is not found in the lookup mapping. |
Exception
|
For any unexpected errors during lookup or database operations. |
Logging
- Logs skipped execution for unsupported processors.
- Logs each successful product insertion.
- Logs lookup failures or unexpected database errors.
Notes
- The hardcoded mapping (
eopf_type_dict) defines the expected product types and their respective min/max expected counts. - The sensing start datetime (
sensing_start_datetime) is derived from workflow inputs usingextract_min_datetime(). - The
pi_category_idfield is determined dynamically fromget_pi_category_id(). - Duplicate entries for the same
(flow_run_id, eopf_type)are not reinserted.
Source code in docs/rs-client-libraries/rs_workflows/record_performance.py
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 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | |
record_product_realised(flow_run_id, stac_items)
Insert STAC product metadata into the product_realised database table.
This task records all products discovered during a flow run by inserting
one row per STAC item into the product_realised table. Each inserted record
includes product metadata (EOPF type, sensing time, origin date, etc.) and
default validation flags, which will later be updated by the validation step.
Behavior
- Skips insertion if no STAC items are provided.
- Inserts new rows only (no upsert logic).
- Marks all timing and validation flags (
unexpected,on_time_X_day) as False initially. - Rolls back the transaction on any error to avoid partial inserts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flow_run_id
|
str | UUID
|
Identifier of the current flow run, used to link inserted records. |
required |
stac_items
|
list[dict]
|
List of STAC item dictionaries generated by DPR or discovery steps. |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If a required field (e.g., |
Exception
|
For any other unexpected database or runtime errors. |
Logging
- Logs when no STAC items are provided.
- Logs each successful insert operation.
- Logs detailed errors on failure.
Notes
- The
sensing_start_datetimeandorigin_datefields are extracted from the STAC item's properties. If missing, the current timestamp (datetime.now()) is used as a fallback. - The
pi_category_idis derived from the product type usingget_pi_category_id().
Source code in docs/rs-client-libraries/rs_workflows/record_performance.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
resolve_param(param_value, runtime_key, default)
Return param_value if set, else runtime parameter, else default.
Source code in docs/rs-client-libraries/rs_workflows/record_performance.py
48 49 50 51 52 53 | |
update_timeliness_fields(flow_run_id)
Compute and update timeliness metrics for all realised products in a given flow run.
This task evaluates how promptly each product was stored in the catalog after its
origin time and updates corresponding boolean flags (on_time_X_day) in the
product_realised table. These flags indicate whether each product met its
expected timeliness threshold based on the category-specific maximum delay.
Behavior
- Retrieves all
product_realisedrecords for the specifiedflow_run_id. - For each product, calculates the delay between
origin_dateandcatalog_stored_datetime. - Compares the delay against the maximum allowed delay from
pi_categoryto determine timeliness flags at 0, 1, 2, 3, and 7-day thresholds. - Updates the relevant fields in the database for each product.
- Skips execution if no products are found for the given
flow_run_id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flow_run_id
|
str | UUID
|
Unique identifier of the flow run whose products should be updated. |
required |
Raises:
| Type | Description |
|---|---|
Exception
|
For any unexpected database or runtime errors during the update process. |
Logging
- Logs the computed delay for each product.
- Logs when updates are applied or when no products are found.
- Logs detailed errors on exceptions.
Notes
- The
max_delay_secondsvalue is retrieved from the associatedpi_categoryentry. - The timeliness thresholds (0, 1, 2, 3, and 7 days) are evaluated relative to the product’s origin time.
- All updates are committed at once after processing all records; a rollback occurs on any error.
- Running this task multiple times simply recalculates and updates fields, maintaining idempotence.
Source code in docs/rs-client-libraries/rs_workflows/record_performance.py
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 | |
validate_products(flow_run_id)
Validate realised products against expected definitions for a given flow run.
This task ensures that the products generated during a flow run (product_realised)
match the products defined as expected (product_expected). It performs a
consistency check between expected and realised product types and counts, updating
the database accordingly.
Behavior
- For each expected product type, counts the number of realised instances.
- Marks missing or excess products based on defined min/max thresholds.
- Inserts missing product records into the
product_missingtable if they are not already present. - Flags unexpected or surplus realised products in the
product_realisedtable by settingunexpected=True. - Detects any realised product types that were not listed in the expectations and marks them as unexpected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flow_run_id
|
str
|
Unique identifier of the current flow run. |
required |
Raises:
| Type | Description |
|---|---|
Exception
|
For any unexpected errors during validation or database operations. |
Logging
- Logs counts and validation results for each product type.
- Logs creation of missing-product records.
- Logs when products are marked as unexpected or already processed.
- Logs warnings when metadata for missing products cannot be inferred.
Notes
- Running this validation multiple times is idempotent; it will not duplicate inserts or updates.
- The logic relies on existing rows in
product_expectedandproduct_realised. product_missingentries are created only when a deficit is detected.- Products exceeding the allowed maximum or with unexpected types are flagged instead of deleted.
- All changes are committed at the end; a rollback occurs on any exception.
Source code in docs/rs-client-libraries/rs_workflows/record_performance.py
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 | |