Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Loop/Managers/AnalyticsServicesManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ final class AnalyticsServicesManager {
identify("Dosing Strategy", value: state.dosingStrategy)
identify("Integral Retrospective Correction", value: state.integralRetrospectiveCorrection ? "On" : "Off")
identify("Glucose Based Partial Application", value: state.glucoseBasedPartialApplication ? "On" : "Off")
identify("Guard + Runway", value: state.guardAndRunway ? "On" : "Off")
lastState = state
}

Expand Down Expand Up @@ -274,6 +275,9 @@ final class AnalyticsServicesManager {
if newState.glucoseBasedPartialApplication != oldState.glucoseBasedPartialApplication {
logEvent("Algorithm experiment change", withProperties: ["experiment": "Glucose Based Partial Application", "enabled": newState.glucoseBasedPartialApplication])
}
if newState.guardAndRunway != oldState.guardAndRunway {
logEvent("Algorithm experiment change", withProperties: ["experiment": "Guard + Runway", "enabled": newState.guardAndRunway])
}
}

func didDisplayAlert(identifier: String, interruptionLevel: Alert.InterruptionLevel, scheduled: Bool) {
Expand Down Expand Up @@ -333,6 +337,25 @@ struct AnalyticsState: Codable, Equatable {
var dosingStrategy: String
var integralRetrospectiveCorrection: Bool
var glucoseBasedPartialApplication: Bool
var guardAndRunway: Bool

init(closedLoop: Bool, dosingStrategy: String, integralRetrospectiveCorrection: Bool, glucoseBasedPartialApplication: Bool, guardAndRunway: Bool) {
self.closedLoop = closedLoop
self.dosingStrategy = dosingStrategy
self.integralRetrospectiveCorrection = integralRetrospectiveCorrection
self.glucoseBasedPartialApplication = glucoseBasedPartialApplication
self.guardAndRunway = guardAndRunway
}

// Summaries stored before guardAndRunway was added lack it
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
closedLoop = try container.decode(Bool.self, forKey: .closedLoop)
dosingStrategy = try container.decode(String.self, forKey: .dosingStrategy)
integralRetrospectiveCorrection = try container.decode(Bool.self, forKey: .integralRetrospectiveCorrection)
glucoseBasedPartialApplication = try container.decode(Bool.self, forKey: .glucoseBasedPartialApplication)
guardAndRunway = try container.decodeIfPresent(Bool.self, forKey: .guardAndRunway) ?? false
}
}

struct AnalyticsDailySummary: Codable, Equatable {
Expand Down Expand Up @@ -365,6 +388,7 @@ struct AnalyticsDailySummary: Codable, Equatable {
properties["dosingStrategy"] = state.dosingStrategy
properties["integralRetrospectiveCorrection"] = state.integralRetrospectiveCorrection
properties["glucoseBasedPartialApplication"] = state.glucoseBasedPartialApplication
properties["guardAndRunway"] = state.guardAndRunway
}
return properties
}
Expand Down
3 changes: 2 additions & 1 deletion Loop/Managers/LoopAppManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,8 @@ class LoopAppManager: NSObject {
closedLoop: settingsManager.dosingEnabled,
dosingStrategy: settingsManager.loopSettings.automaticDosingStrategy.analyticsValue,
integralRetrospectiveCorrection: UserDefaults.standard.integralRetrospectiveCorrectionEnabled,
glucoseBasedPartialApplication: UserDefaults.standard.glucoseBasedApplicationFactorEnabled
glucoseBasedPartialApplication: UserDefaults.standard.glucoseBasedApplicationFactorEnabled,
guardAndRunway: UserDefaults.standard.guardAndRunwayEnabled
)
}
analyticsServicesManager.identifyState()
Expand Down