daily_validation
measurement.dash_apps.daily_validation
¤
Attributes¤
DATA_GRANULAR: pd.DataFrame = pd.DataFrame()
module-attribute
¤
DATA_SUMMARY: pd.DataFrame = pd.DataFrame()
module-attribute
¤
SELECTED_DAY: date | None = None
module-attribute
¤
app = DjangoDash('DailyValidation', external_stylesheets=[dbc.themes.BOOTSTRAP, '/static/styles/dashstyle.css'])
module-attribute
¤
detail_date_picker = html.Div(children=[html.Div(children=['Open detailed view'], style={'display': 'inline-block', 'padding-right': '5px'}), dcc.DatePickerSingle(id='detail-date-picker', display_format='YYYY-MM-DD', min_date_allowed=None, max_date_allowed=None)], style={'display': 'inline-block', 'width': '50%', 'text-align': 'right'})
module-attribute
¤
filters = html.Div(children=[filters_row1, filters_row2])
module-attribute
¤
filters_row1 = html.Div(children=[html.Div([html.Label('Station:', style={'display': 'block', 'font-weight': 'bold'}), dcc.Dropdown(id='station_drop', options=[], value=None)], style={'margin-right': '20px', 'width': '286px', 'display': 'inline-block'}), html.Div([html.Label('Variable:', style={'display': 'block', 'font-weight': 'bold'}), dcc.Dropdown(id='variable_drop', options=[], value=None)], style={'margin-right': '20px', 'width': '286px', 'display': 'inline-block'}), html.Div([html.Label('Date Range:', style={'display': 'block', 'font-weight': 'bold'}), dcc.DatePickerRange(id='date_range_picker', display_format='YYYY-MM-DD', start_date=None, end_date=None)], style={'width': '286px', 'display': 'inline-block'})], style={'display': 'flex', 'justify-content': 'flex-start', 'margin-bottom': '10px'})
module-attribute
¤
filters_row2 = html.Div(children=[html.Div([html.Label('Minimum:', style={'display': 'block', 'font-weight': 'bold'}), dcc.Input(id='minimum_input', type='number', value=None)], style={'margin-right': '20px', 'width': '286px'}), html.Div([html.Label('Maximum:', style={'display': 'block', 'font-weight': 'bold'}), dcc.Input(id='maximum_input', type='number', value=None)], style={'margin-right': '20px', 'width': '286px'}), html.Div([html.Label('Validation status:', style={'display': 'block', 'font-weight': 'bold'}), dcc.Dropdown(id='validation_status_drop', options=[{'label': 'Validated', 'value': 'validated'}, {'label': 'Not validated', 'value': 'not_validated'}], value='not_validated')], style={'width': '286px'})], style={'display': 'flex', 'justify-content': 'flex-start'})
module-attribute
¤
menu = html.Div(children=[html.Div(children=[html.Button('Validate', id='save-button')], style={'display': 'inline-block', 'width': '50%'}), detail_date_picker], style={'background-color': '#f0f0f0', 'width': '100%'})
module-attribute
¤
plot = html.Div(children=[dcc.Graph(id='plot', figure=create_empty_plot(), style={'width': '100%'}), dcc.RadioItems(id='plot_radio', options=[{'value': c, 'label': c.capitalize()} for c in ['value', 'maximum', 'minimum']], value='value', style={'width': '100px'}, labelStyle={'display': 'block'})], style={'display': 'flex', 'justify-content': 'space-between', 'height': '400px'})
module-attribute
¤
status_message = html.Div(id='status-message', children=[''], style={'min-height': '20px', 'padding-top': '5px', 'padding-bottom': '10px'})
module-attribute
¤
table_daily = AgGrid(id='table_daily', rowData=[], columnDefs=create_columns_daily(), columnSize='sizeToFit', defaultColDef={'resizable': True, 'sortable': True, 'checkboxSelection': {'function': 'params.column == params.columnApi.getAllDisplayedColumns()[0]'}, 'headerCheckboxSelection': {'function': 'params.column == params.columnApi.getAllDisplayedColumns()[0]'}, 'headerCheckboxSelectionFilteredOnly': True}, dashGridOptions={'rowSelection': 'multiple', 'suppressRowClickSelection': True}, selectAll=True, getRowId='params.data.date')
module-attribute
¤
table_detail = AgGrid(id='table_detail', rowData=[], columnDefs=create_columns_detail(), columnSize='sizeToFit', defaultColDef={'resizable': True, 'sortable': True, 'checkboxSelection': {'function': 'params.column == params.columnApi.getAllDisplayedColumns()[0]'}, 'headerCheckboxSelection': {'function': 'params.column == params.columnApi.getAllDisplayedColumns()[0]'}, 'headerCheckboxSelectionFilteredOnly': True}, dashGridOptions={'rowSelection': 'multiple', 'suppressRowClickSelection': True}, selectAll=True, getRowId='params.data.id')
module-attribute
¤
Classes¤
Variable
¤
Bases: PermissionsBase
A variable with a physical meaning.
Such as precipitation, wind speed, wind direction, soil moisture, including the associated unit. It also includes metadata to help identify what is a reasonable value for the data, to flag outliers and to help with the validation process.
The nature of the variable can be one of the following:
- sum: Cumulative value over a period of time.
- average: Average value over a period of time.
- value: One-off value.
Attributes:
Name | Type | Description |
---|---|---|
variable_id |
AutoField
|
Primary key. |
variable_code |
CharField
|
Code of the variable, eg. airtemperature. |
name |
CharField
|
Human-readable name of the variable, eg. Air temperature. |
unit |
ForeignKey
|
Unit of the variable. |
maximum |
DecimalField
|
Maximum value allowed for the variable. |
minimum |
DecimalField
|
Minimum value allowed for the variable. |
diff_error |
DecimalField
|
If two sequential values in the time-series data of this variable differ by more than this value, the validation process can mark this with an error flag. |
outlier_limit |
DecimalField
|
The statistical deviation for defining outliers, in times the standard deviation (sigma). |
null_limit |
DecimalField
|
The max % of null values (missing, caused by e.g. equipment malfunction) allowed for hourly, daily, monthly data. Cumulative values are not deemed trustworthy if the number of missing values in a given period is greater than the null_limit. |
nature |
CharField
|
Nature of the variable, eg. if it represents a one-off value, the average over a period of time or the cumulative value over a period |
Attributes¤
is_cumulative: bool
property
¤
Return True if the nature of the variable is sum.
Functions¤
__str__()
¤
Return the string representation of the object.
Source code in variable\models.py
165 166 167 |
|
clean()
¤
Validate the model fields.
Source code in variable\models.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
|
get_absolute_url()
¤
Get the absolute URL of the object.
Source code in variable\models.py
169 170 171 |
|
Functions¤
callbacks(in_submit_clicks, in_save_clicks, in_detail_date, in_plot_radio_value, in_tabs_value, in_station, in_variable, in_start_date, in_end_date, in_minimum, in_maximum, in_daily_selected_rows, in_daily_row_data, in_detail_selected_rows, in_detail_row_data, in_validation_status)
¤
Callbacks for daily validation app
Parameters:
Name | Type | Description | Default |
---|---|---|---|
in_submit_clicks |
int
|
Number of times submit-button was clicked |
required |
in_save_clicks |
int
|
Number of times save-button was clicked |
required |
in_detail_date |
str
|
Date for detail view |
required |
in_plot_radio_value |
str
|
Value of plot radio button |
required |
in_tabs_value |
str
|
Value of tabs |
required |
in_station |
str
|
Station from filters |
required |
in_variable |
str
|
Variable from filters |
required |
in_start_date |
str
|
Start date from filters |
required |
in_end_date |
str
|
End date from filters |
required |
in_minimum |
float
|
Minimum from filters |
required |
in_maximum |
float
|
Maximum from filters |
required |
in_daily_selected_rows |
list[dict]
|
Selected rows in table_daily |
required |
in_daily_row_data |
list[dict]
|
Full row data for table_daily |
required |
in_detail_selected_rows |
list[dict]
|
Selected rows in table_detail |
required |
in_detail_row_data |
list[dict]
|
Full row data for table_detail |
required |
Returns:
Name | Type | Description |
---|---|---|
out_loading_top |
no_update
|
Loading spinner for top |
out_loading |
no_update
|
Loading spinner for bottom |
out_status |
str
|
Status message |
out_plot |
Figure
|
Plot |
out_daily_row_data |
list[dict]
|
Data for daily table |
out_detail_row_data |
list[dict]
|
Data for detail table |
out_daily_selected_rows |
list[dict]
|
Selected rows in daily table |
out_detail_selected_rows |
list[dict]
|
Selected rows in detail table |
out_tab_detail_disabled |
bool
|
Disabled status for detail tab |
out_tab_detail_label |
str
|
Label for detail tab |
out_tabs_value |
str
|
Value for tabs |
out_save_label |
str
|
Label for save button |
Source code in measurement\dash_apps\daily_validation.py
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 |
|
create_columns_daily()
¤
Creates columns for Daily Report table
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value_columns |
list
|
List of value columns |
required |
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
List of columns |
Source code in measurement\dash_apps\tables.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
create_columns_detail()
¤
Creates columns for Detail table
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value_columns |
list
|
List of value columns |
required |
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
List of columns |
Source code in measurement\dash_apps\tables.py
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 |
|
create_empty_plot()
¤
Creates empty plot
Returns:
Type | Description |
---|---|
scatter
|
px.Scatter: Plot |
Source code in measurement\dash_apps\plots.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
create_validation_plot(data, variable_name, field)
¤
Creates plot for Validation app
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
DataFrame
|
Data |
required |
variable_name |
str
|
Variable name |
required |
field |
str
|
'value', 'minimum' or 'maximum' |
required |
Returns:
Type | Description |
---|---|
Figure
|
go.Figure: Plot |
Source code in measurement\dash_apps\plots.py
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 |
|
generate_validation_report(station, variable, start_time, end_time, maximum, minimum, is_validated=False)
¤
Generates a report of the data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
station |
str
|
Station of interest. |
required |
variable |
str
|
Variable of interest. |
required |
start_time |
str
|
Start time. |
required |
end_time |
str
|
End time. |
required |
maximum |
Decimal
|
The maximum allowed value. |
required |
minimum |
Decimal
|
The minimum allowed value. |
required |
is_validated |
bool
|
Whether to retrieve validated or non-validated data. |
False
|
Returns:
Type | Description |
---|---|
tuple[DataFrame, DataFrame]
|
A tuple with the summary report and the granular report. |
Source code in measurement\validation.py
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 |
|
get_date_range(station, variable)
¤
Get the date range covered by a chosen station and variable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
station |
str
|
Code for the chosen station |
required |
variable |
str
|
Code for the chosen variable |
required |
Returns:
Type | Description |
---|---|
tuple[str, str]
|
tuple[str, str]: Start date, end date |
Source code in measurement\filters.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
get_min_max(station, variable)
¤
Get the min and max of the data for a chosen station and variable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
station |
str
|
Code for the chosen station |
required |
variable |
str
|
Code for the chosen variable |
required |
Returns:
Type | Description |
---|---|
tuple[Decimal, Decimal]
|
tuple[Decimal, Decimal]: Min value, max value |
Source code in measurement\filters.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 |
|
get_station_options(station_codes)
¤
Get valid station options and default value based on permissions and data availability.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
station_codes |
list[str]
|
List of station codes based on permissions |
required |
Returns:
Type | Description |
---|---|
tuple[list[dict[str, str]], str | None]
|
tuple[list[dict], str]: Options for the station dropdown, default value |
Source code in measurement\filters.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
get_variable_options(station)
¤
Get valid variable options and default value based on the chosen station.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
station |
str
|
Code for the chosen station |
required |
Returns:
Type | Description |
---|---|
tuple[list[dict[str, str]], str | None]
|
tuple[list[dict], str]: Options for the variable dropdown, default value |
Source code in measurement\filters.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
populate_stations_dropdown(station_codes)
¤
Populate the station dropdown based on the list of station codes.
Source code in measurement\dash_apps\daily_validation.py
630 631 632 633 634 635 636 637 638 |
|
populate_variable_dropdown(chosen_station)
¤
Populate the variable dropdown based on the chosen station.
Source code in measurement\dash_apps\daily_validation.py
641 642 643 644 645 646 647 648 649 |
|
reset_validated_days(station, variable, start_date, end_date)
¤
Resets validation and active status for the selected data.
It also deletes the associated report data.
TODO: should this also reset any modified value, minimum or maximum entries?
Parameters:
Name | Type | Description | Default |
---|---|---|---|
station |
str
|
Station code |
required |
variable |
str
|
Variable code |
required |
start_date |
str
|
Start date |
required |
end_date |
str
|
End date |
required |
Source code in measurement\validation.py
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 |
|
reset_validated_entries(ids)
¤
Resets validation and activation status for the selected data.
TODO: should this also reset any modified value, minimum or maximum entries?
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ids |
list
|
List of measurement ids to reset. |
required |
Source code in measurement\validation.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
|
save_validated_days(data)
¤
Saves the validated days to the database and launches the report calculation.
Only the data that is flagged as "validate?" will be saved. The only updated field is is_active. To update the value, maximum or minimum, use save_validated_entries.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
DataFrame
|
The dataframe with the validated data. |
required |
Source code in measurement\validation.py
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 |
|
save_validated_entries(data)
¤
Saves the validated data to the database.
Only the data that is flagged as "validate?" will be saved. Possible updated fields are: value, maximum, minimum and is_active.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
DataFrame
|
The dataframe with the validated data. |
required |
Source code in measurement\validation.py
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 |
|
set_date_range_min_max(chosen_station, chosen_variable)
¤
Set the default date range and min/max based on the chosen station and variable.
Source code in measurement\dash_apps\daily_validation.py
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 |
|
set_detail_date_range(daily_row_data)
¤
Set the min and max date for the detail date picker based on the daily data.
This will run whenever the data is updated.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
daily_row_data |
list[dict]
|
Data for the daily table |
required |
Returns:
Type | Description |
---|---|
tuple[str, str]
|
tuple[str, str]: Min date, max date |
Source code in measurement\dash_apps\daily_validation.py
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 |
|