Begin statistics creation

This commit is contained in:
Christoph Hagen
2025-08-31 16:27:32 +02:00
parent f972a2c020
commit 96bd07bdb7
33 changed files with 1406 additions and 187 deletions

View File

@@ -17,4 +17,38 @@ struct RouteOverview {
let start: Date?
let end: Date?
static func combine(_ overviews: [RouteOverview]) -> RouteOverview {
RouteOverview(
energy: overviews.reduce(0) { $0 + $1.energy },
distance: overviews.reduce(0) { $0 + $1.distance },
duration: overviews.reduce(0) { $0 + $1.duration },
ascendedElevation: overviews.reduce(0) { $0 + $1.ascendedElevation },
start: overviews.compactMap { $0.start }.min(),
end: overviews.compactMap { $0.end }.max())
}
var days: Int {
guard let start, let end else {
return 0
}
return start.inclusiveDays(to: end)
}
}
extension RouteOverview {
func update(labels: inout [ContentLabel], language: ContentLanguage) {
let locale = language.locale
let days = self.days
if days != 1 {
labels.insertOrReplace(icon: .calendar, value: language.text(days: days))
} else {
labels.insertOrReplace(icon: .statisticsTime, value: duration.duration(locale: locale))
}
labels.insertOrReplace(icon: .statisticsDistance, value: String(format: "%.1f km", locale: locale, distance / 1000))
labels.insertOrReplace(icon: .statisticsElevationUp, value: ascendedElevation.length(roundingToNearest: 50))
labels.insertOrReplace(icon: .statisticsEnergy, value: energy.energy(roundingToNearest: 50))
}
}