Skip to content

Commit

Permalink
Added Wind Gust to Daily Forecast
Browse files Browse the repository at this point in the history
  • Loading branch information
briis committed Jan 4, 2024
1 parent af6ae16 commit b079bc7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## Release 1.0.3

**Date**: `2024-01-04`

### Changes

- Added `wind_gust` to Daily Forecast

## Release 1.0.2

**Date**: `2023-12-23`
Expand Down
7 changes: 7 additions & 0 deletions pyweatherflow_forecast/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def __init__(
precipitation: float,
wind_bearing: int,
wind_speed: float,
wind_gust: float,
) -> None:
"""Dataset constructor."""
self._datetime = datetime
Expand All @@ -166,6 +167,7 @@ def __init__(
self._precipitation = precipitation
self._wind_bearing = wind_bearing
self._wind_speed = wind_speed
self._wind_gust = wind_gust

@property
def datetime(self) -> datetime:
Expand Down Expand Up @@ -217,6 +219,11 @@ def wind_speed(self) -> float:
"""Wind speed (m/s)."""
return self._wind_speed

@property
def wind_gust(self) -> float:
"""Wind gust (m/s)."""
return self._wind_gust


class WeatherFlowForecastHourly:
"""Class to hold hourly forecast data."""
Expand Down
8 changes: 7 additions & 1 deletion pyweatherflow_forecast/wffcst_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,20 +236,24 @@ def _calced_day_values(day_number, hourly_data) -> dict[str, Any]:
_precipitation: float = 0
_wind_speed = []
_wind_bearing = []
_wind_gust = []

for item in hourly_data:
if item.get("local_day") == day_number:
_precipitation += item.get("precip", 0)
_wind_bearing.append(item.get("wind_direction", 0))
_wind_speed.append(item.get("wind_avg", 0))
_wind_gust.append(item.get("wind_gust", 0))

_sum_wind_speed = sum(_wind_speed) / len(_wind_speed)
_sum_wind_bearing = sum(_wind_bearing) / len(_wind_bearing)
_max_wind_gust = max(_wind_gust)

return {
"precipitation": _precipitation,
"wind_bearing": _sum_wind_bearing,
"wind_speed": _sum_wind_speed
"wind_speed": _sum_wind_speed,
"wind_gust": _max_wind_gust,
}


Expand All @@ -276,6 +280,7 @@ def _get_forecast(api_result: dict) -> WeatherFlowForecastData:
precipitation = _calc_values["precipitation"]
wind_bearing = _calc_values["wind_bearing"]
wind_speed = _calc_values["wind_speed"]
wind_gust = _calc_values["wind_gust"]

forecast_d = WeatherFlowForecastDaily(
valid_time,
Expand All @@ -288,6 +293,7 @@ def _get_forecast(api_result: dict) -> WeatherFlowForecastData:
precipitation,
wind_bearing,
wind_speed,
wind_gust,
)
forecasts_daily.append(forecast_d)

Expand Down

0 comments on commit b079bc7

Please sign in to comment.