Begin statistics creation
This commit is contained in:
@@ -77,45 +77,6 @@ final class LocalizedPost: ChangeObservingItem {
|
||||
var hasVideos: Bool {
|
||||
images.contains { $0.type.isVideo }
|
||||
}
|
||||
|
||||
func updateLabels(from workout: RouteOverview, locale: Locale) {
|
||||
insertOrReplace(label: .init(icon: .statisticsDistance, value: String(format: "%.1f km", locale: locale, workout.distance / 1000)))
|
||||
insertOrReplace(label: .init(icon: .statisticsTime, value: workout.duration.duration(locale: locale)))
|
||||
insertOrReplace(label: .init(icon: .statisticsElevationUp, value: workout.ascendedElevation.length(roundingToNearest: 50)))
|
||||
insertOrReplace(label: .init(icon: .statisticsEnergy, value: workout.energy.energy(roundingToNearest: 50)))
|
||||
}
|
||||
|
||||
func insertOrReplace(label: ContentLabel) {
|
||||
if let index = labels.firstIndex(where: { $0.icon == label.icon }) {
|
||||
labels[index] = label
|
||||
} else {
|
||||
labels.append(label)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension TimeInterval {
|
||||
|
||||
func duration(locale: Locale) -> String {
|
||||
let totalMinutes = Int((self / 60).rounded(to: 5))
|
||||
let hours = totalMinutes / 60
|
||||
let minutes = totalMinutes % 60
|
||||
|
||||
let suffix = locale.identifier.hasPrefix("de") ? "Std" : "h"
|
||||
|
||||
return String(format: "%d:%02d ", hours, minutes) + suffix
|
||||
}
|
||||
|
||||
func length(roundingToNearest interval: Double) -> String {
|
||||
let rounded = Int(self.rounded(to: interval))
|
||||
return "\(rounded) m"
|
||||
}
|
||||
|
||||
func energy(roundingToNearest interval: Double) -> String {
|
||||
let rounded = Int(self.rounded(to: interval))
|
||||
return "\(rounded) kcal"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: Storage
|
||||
|
||||
Reference in New Issue
Block a user