show daily weather at different times, use weather icons, get prevalent weather icon for the day
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user