data_report
measurement.dash_apps.data_report
¤
Attributes¤
MAX_POINTS = 1000
module-attribute
¤
Maximum number of points to display in the graph.
app = DjangoDash('DataReport', external_stylesheets=[dbc.themes.BOOTSTRAP, '/static/styles/dashstyle.css'])
module-attribute
¤
buttons_div = html.Div(children=[dbc.Button('Download CSV', color='primary', className='me-1', id='csv_button'), dbc.Button('Display data', color='success', className='me-1', id='display_button', style={'margin-left': '10px'}, n_clicks=0)], id='buttons_div', hidden=False, style={'margin-top': '30px'})
module-attribute
¤
filters = html.Div(style={'width': '35%', 'height': '100%', 'padding': '10px'}, children=[_traces_selection('primary'), html.Label('Date Range:', style={'font-weight': 'bold'}), dcc.DatePickerRange(id='date_range_picker', display_format='YYYY-MM-DD', start_date=None, end_date=None), secondary_trace, buttons_div])
module-attribute
¤
secondary_trace = html.Div(style={'margin-top': '10px', 'margin-left': '10px'}, children=[dbc.Checklist(options=[{'label': 'Add secondary trace', 'value': 1}], value=[], id='switch-show-secondary', switch=True), html.Div(_traces_selection('secondary'), id='secondary_traces_div', hidden=True)])
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
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 | |
get_absolute_url()
¤
Get the absolute URL of the object.
Source code in variable/models.py
169 170 171 | |
Functions¤
_traces_selection(block_id)
¤
Build the traces selection widgets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
block_id
|
str
|
Prefix used to build the component id. |
required |
Returns:
| Type | Description |
|---|---|
|
html.Div: Scrollable container holding the traces selection widgets. |
Source code in measurement/dash_apps/data_report.py
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
add_nans_for_gaps(data)
¤
Add NaN values to create gaps in the plot when there are missing points.
Using values for maximum and minimum results in a shaded area indicating the gap which is more visually intuitive than just breaking the line.
We use 1.5 times the median time difference as a threshold to detect gaps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
The data to process, must contain 'time', 'value', 'maximum' and 'minimum' columns. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Data with NaN values added for gaps |
Source code in measurement/dash_apps/plots.py
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 | |
create_empty_plot()
¤
Creates empty plot
Returns:
| Type | Description |
|---|---|
scatter
|
px.Scatter: Plot |
Source code in measurement/dash_apps/plots.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | |
create_report_plot(data, variable_name, station_code, agg='', add_secondary_axis=False, fig=None)
¤
Creates plot for Report app
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
Data |
required |
variable_name
|
str
|
Variable name |
required |
station_code
|
str
|
Station code |
required |
agg
|
str
|
Aggregation level. Defaults to "". |
''
|
add_secondary_axis
|
bool
|
Whether to use secondary y-axis. Defaults to False. |
False
|
fig
|
Figure | None
|
Existing figure to add traces to. Defaults to None. |
None
|
Returns: go.Figure: Plot
Source code in measurement/dash_apps/plots.py
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 | |
download_csv_report(n_clicks, temporality, station, variable, start_time, end_time)
¤
Source code in measurement/dash_apps/data_report.py
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 | |
get_aggregation_level(timeseries, aggregate=False)
¤
Calculates the aggregation level based on the timeseries separation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeseries
|
Series
|
Time data to be aggregated. |
required |
aggregate
|
bool
|
Flag indicating if there should be aggregation |
False
|
Return
String indicating the aggregation level as " - LEVEL UNITS aggregation" or an empty string if no aggregation is required.
Source code in measurement/dash_apps/plots.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
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_report_data_from_db(station, variable, start_time, end_time, report_type, whole_months=True)
cached
¤
Retrieves the report data from the database.
Time is set to the station timezone and the time range is inclusive of both start and end times.
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 |
report_type
|
str
|
Type of report to retrieve. |
required |
whole_months
|
bool
|
Whether to cover whole months or not. |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
A dataframe with the report data. |
Source code in measurement/reporting.py
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 | |
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/data_report.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | |
populate_variable_dropdown(primary_chosen_station, secondary_chosen_station)
¤
Populate the variable dropdown based on the chosen station.
Source code in measurement/dash_apps/data_report.py
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 | |
set_date_range(chosen_station, chosen_variable)
¤
Set the default date range based on the chosen station and variable.
Source code in measurement/dash_apps/data_report.py
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 | |
toggle_secondary_traces_div(show_secondary)
¤
Show or hide the secondary traces selection div based on the switch value.
Source code in measurement/dash_apps/data_report.py
363 364 365 366 367 368 369 | |
update_graph(relayout_data, n_clicks, temporality, station, variable, start_time, end_time, figure, show_secondary, secondary_temporality, secondary_station, secondary_variable, callback_context)
¤
Source code in measurement/dash_apps/data_report.py
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 | |