diff --git a/lib/components/compact_weather_data.dart b/lib/components/compact_weather_data.dart index 42e6571..aca713f 100644 --- a/lib/components/compact_weather_data.dart +++ b/lib/components/compact_weather_data.dart @@ -25,22 +25,16 @@ class _CompactWeatherDataState extends State { "${DateFormat('EEEE').format(widget.dwm.dateOfDay())}, ${widget.dwm.dateOfDay().day}.${widget.dwm.dateOfDay().month}.", style: Theme.of(context).textTheme.headline5, ), - const SizedBox(height: 20), - Icon(weatherIcon(widget.dwm.prevalentWeatherIcon())), - Row(mainAxisAlignment: MainAxisAlignment.center, children: [ - const Icon(WeatherIcons.thermometer), - Text( - "${widget.dwm.dailyMaxTemp()} °C", - style: Theme.of(context).textTheme.bodyLarge, - ) - ]), - const SizedBox(height: 20), - Row(mainAxisAlignment: MainAxisAlignment.center, children: [ - const Icon(WeatherIcons.thermometer_exterior), - Text( - "${widget.dwm.dailyMinTemp()} °C", - style: Theme.of(context).textTheme.bodyLarge, - ) + const SizedBox(height: 10), + Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ + _weatherData(), + Expanded( + child: Padding( + padding: const EdgeInsets.all(35), + child: FittedBox( + fit: BoxFit.fill, + child: Icon(weatherIcon( + widget.dwm.prevalentWeatherIcon()))))), ]), const SizedBox(height: 20), Row( @@ -67,4 +61,58 @@ class _CompactWeatherDataState extends State { ], ); } + + Widget _weatherData() { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + Text( + "${widget.dwm.dailyMaxTemp()} °C ", + style: Theme.of(context) + .textTheme + .titleLarge! + .copyWith(fontStyle: FontStyle.normal), + ), + const Icon( + Icons.circle, + size: 10, + color: Colors.grey, + ), + Text( + " ${widget.dwm.dailyMinTemp()} °C", + style: Theme.of(context) + .textTheme + .titleLarge! + .copyWith(fontStyle: FontStyle.normal, color: Colors.grey), + ) + ], + ), + Row(crossAxisAlignment: CrossAxisAlignment.end, children: [ + const Icon(WeatherIcons.barometer), + const SizedBox(width: 10), + Text("${widget.dwm.dailyAveragePressure().toString()} hPa") + ]), + const SizedBox(height: 5), + Row(crossAxisAlignment: CrossAxisAlignment.end, children: [ + const Icon(WeatherIcons.raindrop), + const SizedBox(width: 10), + Text("${widget.dwm.dailyPrecipitation().toString()} mm") + ]), + const SizedBox(height: 5), + Row(crossAxisAlignment: CrossAxisAlignment.end, children: [ + const Icon(WeatherIcons.cloud), + const SizedBox(width: 10), + Text("${widget.dwm.dailyAverageCloudCover().toString()} %") + ]), + const SizedBox(height: 5), + Row(crossAxisAlignment: CrossAxisAlignment.end, children: [ + const Icon(WeatherIcons.windy), + const SizedBox(width: 10), + Text("${widget.dwm.dailyAverageWindSpeed().toString()} km/h") + ]), + ], + ); + } } diff --git a/lib/models/daily_weather_model.dart b/lib/models/daily_weather_model.dart index a78e940..b4bcdd7 100644 --- a/lib/models/daily_weather_model.dart +++ b/lib/models/daily_weather_model.dart @@ -18,6 +18,55 @@ class DailyWeatherModel { } } + int dailyAveragePressure() { + double pressureSum = 0; + int failuresInData = 0; + for (HourlyWeatherModel forecast in hourlyForecasts) { + if (forecast.pressure != null) { + pressureSum = pressureSum + forecast.pressure!; + } else { + failuresInData += 1; + } + } + return (pressureSum / (hourlyForecasts.length - failuresInData)).round(); + } + + int dailyPrecipitation() { + double precipitation = 0; + for (HourlyWeatherModel forecast in hourlyForecasts) { + if (forecast.precipitation != null) { + precipitation = precipitation + forecast.precipitation!; + } + } + return precipitation.round(); + } + + int dailyAverageCloudCover() { + double cloudCoverSum = 0; + int failuresInData = 0; + for (HourlyWeatherModel forecast in hourlyForecasts) { + if (forecast.cloudCover != null) { + cloudCoverSum = cloudCoverSum + forecast.cloudCover!; + } else { + failuresInData += 1; + } + } + return (cloudCoverSum / (hourlyForecasts.length - failuresInData)).round(); + } + + int dailyAverageWindSpeed() { + double windSpeedSum = 0; + int failuresInData = 0; + for (HourlyWeatherModel forecast in hourlyForecasts) { + if (forecast.windSpeed != null) { + windSpeedSum = windSpeedSum + forecast.windSpeed!; + } else { + failuresInData += 1; + } + } + return (windSpeedSum / (hourlyForecasts.length - failuresInData)).round(); + } + String dailyAverageTemp() { double tempSum = 0; for (var forecast in hourlyForecasts) { diff --git a/lib/models/hourly_weather_model.dart b/lib/models/hourly_weather_model.dart index cee93c5..9d0f3b1 100644 --- a/lib/models/hourly_weather_model.dart +++ b/lib/models/hourly_weather_model.dart @@ -2,7 +2,7 @@ class HourlyWeatherModel { late DateTime timestamp; String? sourceId; double? precipitation; - int? pressure; + double? pressure; int? sunshine; late double temperature; int? windDirection; @@ -21,7 +21,7 @@ class HourlyWeatherModel { HourlyWeatherModel.fromJson(Map json) { sourceId = json['source_id'].toString(); precipitation = json['precipitation']; - pressure = json['pressure']; + pressure = json['pressure_msl']; sunshine = json['sundshine']; temperature = json['temperature']; windDirection = json['wind_direction'];