forked from loopandlearn/LoopFollow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding iage, including some debug prints
- Loading branch information
Showing
10 changed files
with
184 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// | ||
// IAge.swift | ||
// LoopFollow | ||
// | ||
// Created by Jonas Björkert on 2024-08-05. | ||
// Copyright © 2024 Jon Fawcett. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
extension MainViewController { | ||
// NS Iage Web Call | ||
func webLoadNSIage() { | ||
let lastDateString = dateTimeUtils.getDateTimeString(addingDays: -60) | ||
let currentTimeString = dateTimeUtils.getDateTimeString() | ||
|
||
let parameters: [String: String] = [ | ||
"find[eventType]": NightscoutUtils.EventType.iage.rawValue, | ||
"find[created_at][$gte]": lastDateString, | ||
"find[created_at][$lte]": currentTimeString, | ||
"count": "1" | ||
] | ||
|
||
NightscoutUtils.executeRequest(eventType: .iage, parameters: parameters) { (result: Result<[iageData], Error>) in | ||
switch result { | ||
case .success(let data): | ||
DispatchQueue.main.async { | ||
self.updateIage(data: data) | ||
} | ||
case .failure(let error): | ||
print("Failed to fetch data: \(error.localizedDescription)") | ||
} | ||
} | ||
} | ||
|
||
// NS Sage Response Processor | ||
func updateIage(data: [iageData]) { | ||
infoManager.clearInfoData(type: .iage) | ||
|
||
if data.count == 0 { | ||
return | ||
} | ||
currentIage = data[0] | ||
let lastIageString = data[0].created_at | ||
|
||
let formatter = ISO8601DateFormatter() | ||
formatter.formatOptions = [.withFullDate, | ||
.withTime, | ||
.withDashSeparatorInDate, | ||
.withColonSeparatorInTime] | ||
|
||
if let iageTime = formatter.date(from: (lastIageString as! String))?.timeIntervalSince1970 { | ||
let now = dateTimeUtils.getNowTimeIntervalUTC() | ||
let secondsAgo = now - iageTime | ||
|
||
let formatter = DateComponentsFormatter() | ||
formatter.unitsStyle = .positional | ||
formatter.allowedUnits = [ .day, .hour] | ||
formatter.zeroFormattingBehavior = [ .pad ] | ||
|
||
if let formattedDuration = formatter.string(from: secondsAgo) { | ||
infoManager.updateInfoData(type: .iage, value: formattedDuration) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
LoopFollow/Controllers/Nightscout/Treatments/InsulinCartridgeChange.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// InsulinCartridgeChange.swift | ||
// LoopFollow | ||
// | ||
// Created by Jonas Björkert on 2024-08-05. | ||
// Copyright © 2024 Jon Fawcett. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
extension MainViewController { | ||
func processIage(entries: [iageData]) { | ||
if !entries.isEmpty { | ||
updateIage(data: entries) | ||
} else if let iage = currentIage { | ||
updateIage(data: [iage]) | ||
} else { | ||
webLoadNSIage() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters