Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrub Stats Upload #150

Merged
merged 2 commits into from
May 10, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"overrideHbA1cUnit" : false,
"high" : 145,
"low" : 70,
"uploadStats" : true,
"hours" : 6,
"xGridLines" : true,
"yGridLines" : true,
Expand Down
302 changes: 0 additions & 302 deletions FreeAPS/Sources/APS/APSManager.swift

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions FreeAPS/Sources/Models/FreeAPSSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ struct FreeAPSSettings: JSON, Equatable {
var overrideHbA1cUnit: Bool = false
var high: Decimal = 145
var low: Decimal = 70
var uploadStats: Bool = true
var hours: Int = 6
var xGridLines: Bool = true
var yGridLines: Bool = true
Expand Down Expand Up @@ -191,10 +190,6 @@ extension FreeAPSSettings: Decodable {
settings.high = high
}

if let uploadStats = try? container.decode(Bool.self, forKey: .uploadStats) {
settings.uploadStats = uploadStats
}

if let hours = try? container.decode(Int.self, forKey: .hours) {
settings.hours = hours
}
Expand Down
3 changes: 0 additions & 3 deletions FreeAPS/Sources/Modules/Home/HomeStateModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ extension Home {
private(set) var filteredHours = 24
@Published var glucose: [BloodGlucose] = []
@Published var suggestion: Suggestion?
@Published var uploadStats = false
@Published var enactedSuggestion: Suggestion?
@Published var recentGlucose: BloodGlucose?
@Published var glucoseDelta: Int?
Expand Down Expand Up @@ -76,7 +75,6 @@ extension Home {
setupReservoir()

suggestion = provider.suggestion
uploadStats = settingsManager.settings.uploadStats
enactedSuggestion = provider.enactedSuggestion
units = settingsManager.settings.units
allowManualTemp = !settingsManager.settings.closedLoop
Expand Down Expand Up @@ -392,7 +390,6 @@ extension Home.StateModel:

func settingsDidChange(_ settings: FreeAPSSettings) {
allowManualTemp = !settings.closedLoop
uploadStats = settingsManager.settings.uploadStats
closedLoop = settingsManager.settings.closedLoop
units = settingsManager.settings.units
animatedBackground = settingsManager.settings.animatedBackground
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ extension NightscoutConfig {
@Published var connecting = false
@Published var backfilling = false
@Published var isUploadEnabled = false // Allow uploads
@Published var uploadStats = false // Upload Statistics
@Published var uploadGlucose = true // Upload Glucose
@Published var changeUploadGlucose = true // if plugin, need to be change in CGM configuration
@Published var useLocalSource = false
Expand All @@ -46,7 +45,6 @@ extension NightscoutConfig {
subscribeSetting(\.isUploadEnabled, on: $isUploadEnabled) { isUploadEnabled = $0 }
subscribeSetting(\.useLocalGlucoseSource, on: $useLocalSource) { useLocalSource = $0 }
subscribeSetting(\.localGlucosePort, on: $localPort.map(Int.init)) { localPort = Decimal($0) }
subscribeSetting(\.uploadStats, on: $uploadStats) { uploadStats = $0 }
subscribeSetting(\.uploadGlucose, on: $uploadGlucose, initial: { uploadGlucose = $0 })
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ extension NightscoutConfig {
Section {
Toggle("Upload", isOn: $state.isUploadEnabled)
if state.isUploadEnabled {
Toggle("Statistics", isOn: $state.uploadStats)
Toggle("Glucose", isOn: $state.uploadGlucose).disabled(!state.changeUploadGlucose)
}
} header: {
Expand Down
24 changes: 0 additions & 24 deletions FreeAPS/Sources/Services/Network/NightscoutAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -326,30 +326,6 @@ extension NightscoutAPI {
.eraseToAnyPublisher()
}

func uploadStats(_ stats: NightscoutStatistics) -> AnyPublisher<Void, Swift.Error> {
var components = URLComponents()
components.scheme = url.scheme
components.host = url.host
components.port = url.port
components.path = Config.statusPath

var request = URLRequest(url: components.url!)
request.allowsConstrainedNetworkAccess = false
request.timeoutInterval = Config.timeout
request.addValue("application/json", forHTTPHeaderField: "Content-Type")

if let secret = secret {
request.addValue(secret.sha1(), forHTTPHeaderField: "api-secret")
}
request.httpBody = try! JSONCoding.encoder.encode(stats)
request.httpMethod = "POST"

return service.run(request)
.retry(Config.retryCount)
.map { _ in () }
.eraseToAnyPublisher()
}

func uploadStatus(_ status: NightscoutStatus) -> AnyPublisher<Void, Swift.Error> {
var components = URLComponents()
components.scheme = url.scheme
Expand Down
24 changes: 0 additions & 24 deletions FreeAPS/Sources/Services/Network/NightscoutManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ protocol NightscoutManager: GlucoseSource {
func deleteInsulin(at date: Date)
func uploadStatus()
func uploadGlucose()
func uploadStatistics(dailystat: Statistics)
func uploadPreferences(_ preferences: Preferences)
func uploadProfileAndSettings(_: Bool)
var cgmURL: URL? { get }
Expand Down Expand Up @@ -249,29 +248,6 @@ final class BaseNightscoutManager: NightscoutManager, Injectable {
.store(in: &lifetime)
}

func uploadStatistics(dailystat: Statistics) {
let stats = NightscoutStatistics(
dailystats: dailystat
)

guard let nightscout = nightscoutAPI, isUploadEnabled else {
return
}

processQueue.async {
nightscout.uploadStats(stats)
.sink { completion in
switch completion {
case .finished:
debug(.nightscout, "Statistics uploaded")
case let .failure(error):
debug(.nightscout, error.localizedDescription)
}
} receiveValue: {}
.store(in: &self.lifetime)
}
}

func uploadPreferences(_ preferences: Preferences) {
let prefs = NightscoutPreferences(
preferences: settingsManager.preferences
Expand Down
1 change: 0 additions & 1 deletion FreeAPS/Sources/Services/Network/TidepoolManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ protocol TidePoolManager {
// func uploadStatus()
func uploadGlucose(device: HKDevice?)
func forceUploadData(device: HKDevice?)
// func uploadStatistics(dailystat: Statistics)
// func uploadPreferences(_ preferences: Preferences)
// func uploadProfileAndSettings(_: Bool)
}
Expand Down