event_quality_warnings
EventQualityWarnings
Bases: Component
Component that calculates Quality Warnings from the Quality Metrics generated by the Event Cleaning component
Source code in multimno/components/quality/event_quality_warnings/event_quality_warnings.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 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 83 84 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 145 146 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 224 225 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 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 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 443 444 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 620 621 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 708 709 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 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 | |
data_size_qw(df_freq_distribution, lookback_period_in_days, variablility, lower_limit, upper_limit, type_of_data, measure_definition_canva=f'{MeasureDefinitions.size_data}', cond_warn_variability_canva=f'{Conditions.size_data_variability}-{Warnings.size_data_variability}', cond_warn_upper_lower_canva=f'{Conditions.size_data_upper_lower}-{Warnings.size_data_upper_lower}')
A unified function to check both raw and clean data sizes, calculates four types of QWs: LOWER_VARIABILITY - for each row using calculated mean and std compute lower variability limit which is mean - SDvariability, check if daily_value is lower tan limit UPPER_VARIABILITY - for each row using calculated mean and std compute upper variability limit which is mean + SDvariability, check if daily_value exceeds limit ABS_LOWER_LIMIT - check if daily_value is lower than absolute number lower_limit ABS_UPPER_LIMIT - check if daily_value exceeds absolute number upper_limit All four QWs depend on thresholds, in case if statement condition is met -> store cond-warn-condition_value information in array column, some rows may have several QWs. In the end array column is exploded and cond-warn-consition_value information is split into three corresponding columns. The function returns almost ready dfs for SilverEventDataSyntacticQualityWarningsLogTable and SilverEventDataSyntacticQualityWarningsForPlots DOs
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_freq_distribution
|
DataFrame
|
df with frequency data |
required |
lookback_period_in_days
|
int
|
lenght of lookback period in days |
required |
variablility
|
Union[int, float]
|
config param, the number of SD to define the upper and lower varibaility limits: mean_size ± SD*variability, which daily_value should not exceed/be lower |
required |
lower_limit
|
Union[int, float]
|
absolute number which daily_value should not be lower |
required |
upper_limit
|
Union[int, float]
|
absolute number which daily_value can not exceed |
required |
type_of_data
|
str
|
which type of data raw or clean to check for QWs |
required |
measure_definition_canva
|
str
|
canva text to use for measure_definition column (see measure_definition.py) |
f'{size_data}'
|
cond_warn_variability_canva
|
str
|
canva text to use for lower_upper_variability cases of data_size QWs (see conditions.py and warnings.py) |
f'{size_data_variability}-{size_data_variability}'
|
cond_warn_upper_lower_canva
|
str
|
canva text to use for lower_upper_limit cases of data_size QWs (see conditions.py and warnings.py) |
f'{size_data_upper_lower}-{size_data_upper_lower}'
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
(DataFrame, DataFrame)
|
a tuple, where first df is used for warning log table, and the second df - for plots |
Source code in multimno/components/quality/event_quality_warnings/event_quality_warnings.py
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 443 444 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 | |
error_rate_qw(df_freq_distribution, lookback_period_in_days, variables, error_rate_over_average, error_rate_upper_variability, error_rate_upper_limit, error_rate_measure_definition_canva=f'{MeasureDefinitions.error_rate}', error_rate_cond_warn_over_average_canva=f'{Conditions.error_rate_over_average}-{Warnings.error_rate_over_average}', error_rate_cond_warn_upper_variability_canva=f'{Conditions.error_rate_upper_variability}-{Warnings.error_rate_upper_variability}', error_rate_cond_warn_upper_limit_canva=f'{Conditions.error_rate_upper_limit}-{Warnings.error_rate_upper_limit}', save_data_for_plots=False)
Prepare data for error rate calculation. First fill in different string canvas, then define window of aggregation, and calculate error_rate over the window on follwoing formula: (Total initial frequency - Total final frequency) / Total initial frequency*100. Parse preprocessed input to self.rate_common_qw function which calculates three types of QWs: OVER_AVERAGE, UPPER_VARIABILITY, and ABS_UPPER_LIMIT
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_freq_distribution
|
DataFrame
|
df with frequency data. |
required |
lookback_period_in_days
|
int
|
number of days prior to date of interest. |
required |
variables
|
List[str]
|
list of column names by which error rate is calculated, kind of granularity level |
required |
error_rate_over_average
|
Union[int, float]
|
config param, specifies the upper limit which a daily value can not exceed its corresponding mean error rate |
required |
error_rate_upper_variability
|
Union[int, float]
|
config param, the number of SD to define the upper varibaility limit: mean_rate + SD*error_rate_upper_variability, which error rate can't exceed |
required |
error_rate_upper_limit
|
Union[int, float]
|
absolute number which error rate can not exceed |
required |
error_rate_measure_definition_canva
|
str
|
canva text to use for measure_definition column (see measure_definition.py) |
f'{error_rate}'
|
error_rate_cond_warn_over_average_canva
|
str
|
canva text to use for over_average cases of error_rate QWs (see conditions.py and warnings.py) |
f'{error_rate_over_average}-{error_rate_over_average}'
|
error_rate_cond_warn_upper_variability_canva
|
str
|
canva text to use for upper_variability cases of error_rate QWs (see conditions.py and warnings.py) |
f'{error_rate_upper_variability}-{error_rate_upper_variability}'
|
error_rate_cond_warn_upper_limit_canva
|
str
|
canva text to use for upper_limit cases of error_rate QWs (see conditions.py and warnings.py) |
f'{error_rate_upper_limit}-{error_rate_upper_limit}'
|
save_data_for_plots
|
bool
|
boolean, decide whether to store error rate and its corresponding average and upper variability limit for plots, default False |
False
|
Returns: tuple(Union[DataFrame, None]): a tuple, where first df is used for warning log table, and the second df - for plots (could be also None)
Source code in multimno/components/quality/event_quality_warnings/event_quality_warnings.py
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 620 621 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 | |
error_type_rate_qw(df_qa_by_column, df_freq_distribution, field_name, error_type, lookback_period_in_days, error_type_rate_over_average, error_type_rate_upper_variability, error_type_rate_upper_limit, error_type_rate_measure_definition_canva=f'{MeasureDefinitions.error_type_rate}', error_type_rate_cond_warn_over_average_canva=f'{Conditions.error_type_rate_over_average}-{Warnings.error_type_rate_over_average}', error_type_rate_cond_warn_upper_variability_canva=f'{Conditions.error_type_rate_upper_variability}-{Warnings.error_type_rate_upper_variability}', error_type_rate_cond_warn_upper_limit_canva=f'{Conditions.error_type_rate_upper_limit}-{Warnings.error_type_rate_upper_limit}')
Prepare data for error type rate calculation. First fill in different string canvas, then based on field name and error type calculate their corresponding error rate using formula: number of errors of this error_type&field_name combo / Total initial frequency *100 (BY DATE). Parse preprocessed input along with window (which is a lookback period) to self.rate_common_qw function which calculates three types of QWs: OVER_AVERAGE, UPPER_VARIABILITY, and ABS_UPPER_LIMIT
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_qa_by_column
|
DataFrame
|
df with qa by column data. |
required |
df_freq_distribution
|
DataFrame
|
df with frequency data. |
required |
field_name
|
str | None
|
config param, the name of column of which to check error_type. |
required |
error_type
|
str
|
config param, the name of error type. |
required |
lookback_period_in_days
|
int
|
number of days prior to date of intrest. |
required |
error_type_rate_over_average
|
Union[int, float]
|
config param, specifies the upper limit over which daily value can not exceed its corresponding mean error rate. |
required |
error_type_rate_upper_variability
|
Union[int, float]
|
config param, the number of SD to define the upper varibaility limit: mean_rate + SD*error_type_rate_upper_variability, which daily value can not exceed |
required |
error_type_rate_upper_limit
|
Union[int, float]
|
absolute number which daily value can not exceed |
required |
error_type_rate_measure_definition_canva
|
str
|
canva text to use for measure_definition column (see measure_definition.py) |
f'{error_type_rate}'
|
error_type_rate_cond_warn_over_average_canva
|
str
|
canva text to use for over_average cases of error_type_rate QWs (see conditions.py and warnings.py) |
f'{error_type_rate_over_average}-{error_type_rate_over_average}'
|
error_type_rate_cond_warn_upper_variability_canva
|
str
|
canva text to use for upper_variability cases of error_type_rate QWs (see conditions.py and warnings.py) |
f'{error_type_rate_upper_variability}-{error_type_rate_upper_variability}'
|
error_type_rate_cond_warn_upper_limit_canva
|
str
|
canva text to use for upper_limit cases of error_type_rate QWs (see conditions.py and warnings.py) |
f'{error_type_rate_upper_limit}-{error_type_rate_upper_limit}'
|
Returns: tuple(Union[DataFrame, None]): a tuple, where first df is used for warning log table, and the second df - for plots, but since save_data_for_plots always False, output=None
Source code in multimno/components/quality/event_quality_warnings/event_quality_warnings.py
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 708 709 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 761 | |
rate_common_qw(df_temp, window, rate_upper_variability, rate_over_average, rate_upper_limit, measure_definition, cond_warn_upper_variability, cond_warn_over_average, cond_warn_upper_limit, save_data_for_plots=False)
Take input df with "daily_value" column, and calculates three types of QWs: OVER_AVERAGE - for each row first based on specified window take mean of values, and then check if daily_value exceeds mean by more than rate_over_average UPPER_VARIABILITY - for each row using already calculated mean compute upper variability limit which is mean + SD*rate_upper_variability, check if daily_value exceeds it ABS_UPPER_LIMIT - check if daily_value exceeds absolute number rate_upper_limit All three QWs depend on specified thresholds, if daily_value exceeds one of calculated values it will store cond-warn-condition_value information in array column, some rows may have several QWs. In the end array column is exploded and cond-warn-condition_value information is split into three corresponding columns. The function returns almost ready df for SilverEventDataSyntacticQualityWarningsLogTable DO, and based on save_data_for_plots arg returns either almost ready data for plots or None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_temp
|
DataFrame
|
temprory data that must have daily_value column to be used in further QW calculations |
required |
window
|
Window
|
a window within which perform aggregation |
required |
rate_upper_variability
|
int | float
|
config param, specifies the upper limit over which daily value can not exceed its corresponding mean error rate |
required |
rate_over_average
|
int | float
|
config param, the number of SD to define the upper varibaility limit: mean_rate + SD*error_rate_upper_variability, which daily value can not exceed |
required |
rate_upper_limit
|
int | float
|
absolute number which daily value can not exceed |
required |
measure_definition
|
str
|
canva text to use for measure_definition column (see measure_definition.py) |
required |
cond_warn_over_average
|
str
|
canva text to use for over_average cases (see conditions.py and warnings.py) |
required |
cond_warn_upper_variability
|
str
|
canva text to use for upper_variability cases (see conditions.py and warnings.py) |
required |
cond_warn_upper_limit
|
str
|
canva text to use for upper_limit cases (see conditions.py and warnings.py) |
required |
save_data_for_plots
|
bool
|
boolean, decide whether to store daily_value and its corresponding average and upper variability limit for plots. Defaults to False. |
False
|
Returns: tuple(Union[DataFrame, None]): a tuple, where first df is used for warning log table, and the second df - for plots
Source code in multimno/components/quality/event_quality_warnings/event_quality_warnings.py
763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 | |
save_quality_warnings_output(dfs_qw, output_do)
Concatenates all elements in dfs_qw list, adjustes to schema of output_do, and using write method of output_do stores the result
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dfs_qw
|
list
|
description |
required |
output_do
|
SilverEventDataSyntacticQualityWarningsLogTable | SilverEventDataSyntacticQualityWarningsForPlots
|
description |
required |
Source code in multimno/components/quality/event_quality_warnings/event_quality_warnings.py
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 | |