show daily weather at different times, use weather icons, get prevalent weather icon for the day

This commit is contained in:
Konstantin Kollar
2022-09-02 14:32:36 +02:00
parent 4fac2ecf0a
commit 20d197c505
3 changed files with 104 additions and 23 deletions
+24
View File
@@ -1,3 +1,5 @@
import 'dart:collection';
import 'package:wetter/models/hourly_weather_model.dart';
import 'dart:math';
@@ -54,4 +56,26 @@ class DailyWeatherModel {
return csm.toString();
}
}
HourlyWeatherModel hourlyWeatherModelAtTimeOfDay(int tod) {
return hourlyForecasts
.firstWhere((element) => element.timestamp.hour == tod);
}
String prevalentWeatherIcon() {
List<String> icons = hourlyForecasts.map((e) => e.icon!).toList();
Map<String, int> usedIconCount = {};
for (String i in icons) {
if (!usedIconCount.containsKey(i)) {
usedIconCount[i] = 1;
} else {
usedIconCount[i] = (usedIconCount[i]! + 1);
}
}
Map<String, int> sortedValuesDesc = SplayTreeMap<String, int>.from(
usedIconCount,
(keys1, keys2) =>
usedIconCount[keys2]!.compareTo(usedIconCount[keys1]!));
return sortedValuesDesc.keys.first;
}
}