tasks
importing.tasks
¤
Classes¤
DataImport
¤
Bases: PermissionsBase
Model to store the data imports.
This model stores the data imports, which are, often, files with data that are uploaded to the system. The data is then processed asynchronously and stored in the database.
Attributes:
| Name | Type | Description |
|---|---|---|
station |
ForeignKey
|
Station to which the data belongs. |
format |
ForeignKey
|
Format of the data. |
rawfile |
FileField
|
File with the data to be imported. |
date |
DateTimeField
|
Date of submission of the data. |
start_date |
DateTimeField
|
Start date of the data. |
end_date |
DateTimeField
|
End date of the data. |
records |
IntegerField
|
Number of records in the data. |
observations |
TextField
|
Notes or observations about the data. |
status |
TextField
|
Status of the import. |
log |
TextField
|
Log of the data ingestion, indicating any errors. |
Functions¤
clean()
¤
Validate information and uploads the measurement data.
Source code in importing/models.py
138 139 140 141 142 143 144 145 | |
Functions¤
clear_cache()
¤
Clear the cache.
Source code in importing/tasks.py
44 45 46 47 48 49 | |
ingest_data(data_import_pk)
¤
Initiate the ingestion of data into the DB.
If the status of the data import is "not queued", the request is processed. The data loaded and saved to the database. The status is updated to completed or failed depending on the outcome.
Source code in importing/tasks.py
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 | |
save_temp_data_to_permanent(data_import)
¤
Function to pass the temporary import to the final table.
This function carries out the following steps: - Bulk delete of existing data between two times on a given measurement table for the station in question. - Bulk create to add the new data from the uploaded file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_import
|
DataImport
|
The DataImport object. |
required |
Returns:
| Type | Description |
|---|---|
tuple[datetime, datetime, int]
|
A tuple containing the start date, end date and number of records inserted. |
Source code in importing/functions.py
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 | |
update_variables_for_station(*station_codes)
¤
Update the variables for the given station codes.
The variables are updated based on the measurements associated with the station. The variables are saved as a comma-separated string in the variables field of the station model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
station_codes
|
tuple[str]
|
Station codes for which to update the variables. If not provided, all station codes with measurements are considered. |
()
|
Source code in station/functions.py
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 | |