Skip to content

Commit

Permalink
Upload the number of most frequent error type, not just the error typ…
Browse files Browse the repository at this point in the history
…e. (#910)
  • Loading branch information
Jon-b-m authored Oct 22, 2024
1 parent c88454d commit 8cb6877
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
14 changes: 10 additions & 4 deletions FreeAPS/Sources/APS/APSManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -982,11 +982,16 @@ final class BaseAPSManager: APSManager, Injectable {
let intervalAverage = intervalArray.reduce(0, +) / Double(count)
let maximumInterval = intervalArray.max()
let minimumInterval = intervalArray.min()
//

// Loop errors
let errorArray = loops.compactMap(\.error)
let mostFrequentString = errorArray.mostFrequent()?.description ?? ""

let output = Loops(
loops: Int(loopNr),
errors: errorNR,
mostFrequentErrorType: loops.compactMap(\.error).mostFrequent()?.description ?? "",
mostFrequentErrorType: errorArray.mostFrequent()?.description ?? "",
mostFrequentErrorAmount: errorArray.filter({ $0 == mostFrequentString }).count,
success_rate: roundDecimal(Decimal(successRate ?? 0), 1),
avg_interval: roundDecimal(Decimal(intervalAverage), 1),
median_interval: roundDecimal(Decimal(median_interval), 1),
Expand All @@ -1007,8 +1012,8 @@ final class BaseAPSManager: APSManager, Injectable {
let newVersion = UserDefaults.standard.bool(forKey: IAPSconfig.newVersion)
// Only save and upload twice per day
guard ((-1 * (stats.first?.lastrun ?? .distantPast).timeIntervalSinceNow.hours) > 10) || newVersion else {
return
}
return
}

if settingsManager.settings.uploadStats {
let units = settingsManager.settings.units
Expand Down Expand Up @@ -1185,6 +1190,7 @@ final class BaseAPSManager: APSManager, Injectable {
loops: oneDayLoops.loops,
errors: oneDayLoops.errors,
mostFrequentErrorType: oneDayLoops.mostFrequentErrorType,
mostFrequentErrorAmount: oneDayLoops.mostFrequentErrorAmount,
readings: Int(oneDayGlucose.readings),
success_rate: oneDayLoops.success_rate,
avg_interval: oneDayLoops.avg_interval,
Expand Down
1 change: 1 addition & 0 deletions FreeAPS/Sources/Models/Loops.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ struct Loops: JSON, Equatable {
var loops: Int
var errors: Int
var mostFrequentErrorType: String
var mostFrequentErrorAmount: Int
var success_rate: Decimal
var avg_interval: Decimal
var median_interval: Decimal
Expand Down
2 changes: 2 additions & 0 deletions FreeAPS/Sources/Models/Statistics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ struct LoopCycles: JSON, Equatable {
var loops: Int
var errors: Int
var mostFrequentErrorType: String
var mostFrequentErrorAmount: Int
var readings: Int
var success_rate: Decimal
var avg_interval: Decimal
Expand Down Expand Up @@ -174,6 +175,7 @@ extension LoopCycles {
case loops
case errors
case mostFrequentErrorType
case mostFrequentErrorAmount
case readings
case success_rate
case avg_interval
Expand Down

0 comments on commit 8cb6877

Please sign in to comment.