getDailyTotalPrecipitation method
Get daily total precipitation. Sums all hourly precipitation values for each day.
Implementation
Map<DateTime, double> getDailyTotalPrecipitation() {
final dailyPrecipitation = <DateTime, List<double>>{};
for (final point in data) {
// Include 0 values, skip only null.
if (point.precipitation == null) continue;
final date = DateTime(point.time.year, point.time.month, point.time.day);
dailyPrecipitation.putIfAbsent(date, () => []).add(point.precipitation!);
}
// Return empty map ONLY if no precipitation data exists at all
// If all values are 0, we still return the data (not empty map)
if (dailyPrecipitation.isEmpty) return {};
return dailyPrecipitation.map(
(date, precipitations) => MapEntry(
date,
precipitations.reduce((a, b) => a + b), // Sum all hourly values
),
);
}