|
5 | 5 | from django.core.management.base import BaseCommand |
6 | 6 | from wagtail.models import Site |
7 | 7 |
|
8 | | -from forecastmanager.forecast_settings import ForecastSetting, WeatherCondition, ForecastPeriod |
| 8 | +from forecastmanager.forecast_settings import ForecastSetting, WeatherCondition, ForecastPeriod, ForecastDataParameters |
9 | 9 | from forecastmanager.models import City, CityForecast, DataValue, Forecast |
10 | 10 | from forecastmanager.constants import WEATHER_CONDITIONS_AS_DICT |
11 | 11 |
|
@@ -46,6 +46,20 @@ def handle(self, *args, **options): |
46 | 46 | conditions_by_symbol = {condition.symbol: condition for condition in conditions} |
47 | 47 |
|
48 | 48 | parameters = forecast_setting.data_parameters.all() |
| 49 | + if not parameters.exists(): |
| 50 | + # create default forecast parameters |
| 51 | + default_parameters = [ |
| 52 | + {"parameter": "air_temperature_max", "name": "Maximum Air Temperature", "parameter_unit": "°C"}, |
| 53 | + {"parameter": "air_temperature_min", "name": "Minimum Air Temperature", "parameter_unit": "°C"}, |
| 54 | + {"parameter": "wind_speed", "name": "Wind Speed", "parameter_unit": "m/s"}, |
| 55 | + {"parameter": "precipitation_amount", "name": "Precipitation Amount", "parameter_unit": "mm"} |
| 56 | + ] |
| 57 | + |
| 58 | + for default_parameter in default_parameters: |
| 59 | + ForecastDataParameters.objects.create(parent=forecast_setting, **default_parameter) |
| 60 | + |
| 61 | + parameters = forecast_setting.data_parameters.all() |
| 62 | + |
49 | 63 | parameters_dict = {parameter.parameter: parameter for parameter in parameters} |
50 | 64 |
|
51 | 65 | forecast_periods = forecast_setting.periods.all() |
@@ -83,6 +97,7 @@ def handle(self, *args, **options): |
83 | 97 | data = response.json() |
84 | 98 |
|
85 | 99 | day_intervals = data['dayIntervals'] |
| 100 | + |
86 | 101 | for day in day_intervals[:8]: |
87 | 102 | date = parse(day.get("start")) |
88 | 103 | condition = day.get("twentyFourHourSymbol") |
|
0 commit comments