From a6b816a74753853c7174b7166db07107469abe65 Mon Sep 17 00:00:00 2001 From: lumaa-dev Date: Sat, 2 Nov 2024 18:15:52 +0100 Subject: [PATCH] Added avg. favs --- Bubble/Data/Metrics/MetricsManager.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Bubble/Data/Metrics/MetricsManager.swift b/Bubble/Data/Metrics/MetricsManager.swift index 09d31e2..b5e0ac4 100644 --- a/Bubble/Data/Metrics/MetricsManager.swift +++ b/Bubble/Data/Metrics/MetricsManager.swift @@ -11,6 +11,7 @@ final class MetricsManager { private(set) public var postCount: [IntData] = [] private(set) public var postType: [StatusTypeData] = [] + private(set) public var averageFavorites: Int = 0 init(accountManager: AccountManager) { if let cli = accountManager.getClient() { @@ -51,6 +52,17 @@ final class MetricsManager { } } + private func averageFavorites(_ statuses: [Status]) -> Int { + let favsCount: [Int] = statuses.map { $0.favouritesCount } + + var totalFavs: Int = 0 + favsCount.forEach { int in + totalFavs += int + } + + return totalFavs / favsCount.count + } + /// Data used for integer Metrics struct IntData: GraphData { let date: Date