Skip to content

Commit

Permalink
Merge pull request #19 from wmo-raf/dev
Browse files Browse the repository at this point in the history
Add weather reports page and parameter icons
  • Loading branch information
erick-otenyo authored Mar 26, 2024
2 parents b002bb4 + 6f93ac6 commit dc410e5
Show file tree
Hide file tree
Showing 20 changed files with 150 additions and 16 deletions.
48 changes: 39 additions & 9 deletions forecastmanager/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,71 +109,84 @@
"name": "air_temperature_max",
"label": "Maximum Air Temperature",
"unit": "°C",
"data_type": "int"
"data_type": "int",
"icon": "temperature-high"
},
{
"name": "air_temperature_min",
"label": "Minimum Air Temperature",
"unit": "°C",
"data_type": "int"
"data_type": "int",
"icon": "temperature-low"
},
{
"name": "air_temperature",
"label": "Air Temperature",
"unit": "°C",
"data_type": "int"
"data_type": "int",
"icon": "temperature-half"
},
{
"name": "dew_point_temperature",
"label": "Dew Point Temperature",
"unit": "°C",
"data_type": "int"
"data_type": "int",
"icon": "droplet-degree"
},
{
"name": "precipitation_amount",
"label": "Precipitation Amount",
"unit": "mm",
"data_type": "float"
"data_type": "float",
"icon": "umbrella-simple"
},
{
"name": "air_pressure_at_sea_level",
"label": "Air Pressure (Sea level)",
"unit": "hPa",
"data_type": "int"
"data_type": "int",
"icon": "pressure-gauge"
},
{
"name": "wind_speed",
"label": "Wind Speed",
"unit": "m/s",
"data_type": "int"
"data_type": "int",
"icon": "wind"
},
{
"name": "wind_from_direction",
"label": "Wind Direction",
"unit": "°",
"data_type": "int"
"data_type": "int",
"icon": "direction"
},
{
"name": "relative_humidity",
"label": "Relative Humidity",
"unit": "%",
"data_type": "int"
"data_type": "int",
"icon": "droplet-percent"
},
{
"name": "sunrise",
"label": "Sunrise",
"icon": "sunrise"
},
{
"name": "sunset",
"label": "Sunset",
"icon": "sunset"
},
{
"name": "moonrise",
"label": "Moonrise",
"icon": "moonrise"
},
{
"name": "moonset",
"label": "Moonset",
"icon": "moonset"
},
]

Expand All @@ -190,3 +203,20 @@
'icon_url': static("forecastmanager/weathericons/{0}.png".format(condition["id"]))} for condition in
WEATHER_CONDITIONS
]

WEATHER_PARAMETERS_ICON_LIST = [
"direction",
"droplet-degree",
"droplet-percent",
"moonrise",
"moonset",
"pressure-gauge",
"sunrise",
"sunset",
"temperature-half",
"temperature-high",
"temperature-low",
"umbrella-simple",
"wind",
"wind-sock",
]
5 changes: 4 additions & 1 deletion forecastmanager/forecast_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class ForecastSetting(ClusterableModel, BaseSiteSetting):
default_city = models.ForeignKey("City", blank=True, null=True, on_delete=models.CASCADE,
verbose_name=_("Default City"))
weather_detail_page = models.ForeignKey("wagtailcore.Page", blank=True, null=True, on_delete=models.SET_NULL, )
weather_reports_page = models.ForeignKey("wagtailcore.Page", blank=True, null=True, on_delete=models.SET_NULL,
related_name="weather_reports_page")

edit_handler = TabbedInterface([
ObjectList([
Expand All @@ -40,7 +42,8 @@ class ForecastSetting(ClusterableModel, BaseSiteSetting):
ObjectList([
FieldPanel('default_city'),
FieldPanel('weather_detail_page'),
], heading=_("City")),
FieldPanel('weather_reports_page'),
], heading=_("Other Settings")),
])

@cached_property
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.2.3 on 2024-03-26 10:13

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('wagtailcore', '0089_log_entry_data_json_null_to_object'),
('forecastmanager', '0020_alter_city_slug'),
]

operations = [
migrations.AddField(
model_name='forecastsetting',
name='weather_reports_page',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='weather_reports_page', to='wagtailcore.page'),
),
]
11 changes: 11 additions & 0 deletions forecastmanager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,30 @@ def data_values_dict(self):
for data_value in self.data_values.all():
data_values[data_value.parameter.parameter] = {
"value": data_value.parsed_value,
"name": data_value.parameter.name,
"label": data_value.parameter.parameter_info.get("label"),
"units": data_value.parameter.parameter_info.get("unit"),
"value_with_units": data_value.value_with_units,
"icon": data_value.parameter.parameter_info.get("icon"),
}

# Group temperature values
temperature = {}
if "air_temperature_max" in data_values:
temperature["max_temp"] = data_values.get("air_temperature_max")
# remove air_temperature_max from data_values
data_values.pop("air_temperature_max")

if "air_temperature_min" in data_values:
temperature["min_temp"] = data_values.get("air_temperature_min")
# remove air_temperature_max from data_values
data_values.pop("air_temperature_min")

if "air_temperature" in data_values:
temperature["temp"] = data_values.get("air_temperature")
# remove air_temperature_max from data_values
data_values.pop("air_temperature")

if temperature:
data_values["temperature"] = temperature

Expand Down
4 changes: 4 additions & 0 deletions forecastmanager/templates/forecastmanager/icons/direction.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions forecastmanager/templates/forecastmanager/icons/moonrise.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions forecastmanager/templates/forecastmanager/icons/moonset.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions forecastmanager/templates/forecastmanager/icons/sunrise.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit dc410e5

Please sign in to comment.