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
¤
filters = html.Div(style={'width': '286px'}, children=[html.Label('Temporality:', style={'font-weight': 'bold'}), dcc.Dropdown(id='temporality_drop', options=[{'label': 'Raw measurement', 'value': 'measurement'}, {'label': 'Validated measurement', 'value': 'validated'}, {'label': 'Hourly', 'value': 'hourly'}, {'label': 'Daily', 'value': 'daily'}, {'label': 'Monthly', 'value': 'monthly'}], value='measurement'), html.Br(), html.Label('Station:', style={'font-weight': 'bold'}), dcc.Dropdown(id='station_drop', options=[], value=None), html.Br(), html.Label('Variable:', style={'font-weight': 'bold'}), dcc.Dropdown(id='variable_drop', options=[], value=None), html.Br(), 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), html.Br(), html.Div(id='csv_div', style={'margin-top': '30px'})])
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¤
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_report_plot(data, variable_name, station_code, agg='')
¤
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 "". |
''
|
Returns:
Type | Description |
---|---|
Figure
|
go.Figure: Plot |
Source code in measurement\dash_apps\plots.py
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 |
|
download_csv_report(n_clicks, temporality, station, variable, start_time, end_time)
¤
Source code in measurement\dash_apps\data_report.py
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 |
|
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
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
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
267 268 269 270 271 272 273 274 275 |
|
populate_variable_dropdown(chosen_station)
¤
Populate the variable dropdown based on the chosen station.
Source code in measurement\dash_apps\data_report.py
278 279 280 281 282 283 284 285 286 |
|
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
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
|
update_alert(temporality, station, variable, start_time, end_time, figure)
¤
Source code in measurement\dash_apps\data_report.py
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 |
|
update_graph(relayout_data, n_clicks, temporality, station, variable, start_time, end_time, figure, callback_context)
¤
Source code in measurement\dash_apps\data_report.py
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 |
|