removed check on activeSensor start date for Libre, now the processing will stop as soon as sensor is expired. Still need to add warning, see enhancement nr 120

This commit is contained in:
Johan Degraeve 2020-06-30 22:36:50 +02:00
parent 93e64fe092
commit 7447a5d00d
3 changed files with 6 additions and 25 deletions

View File

@ -152,7 +152,7 @@ class LibreDataParser {
handleGlucoseData(result: (parsedResult.libreRawGlucoseData.map { $0 as GlucoseData }, parsedResult.sensorTimeInMinutes, parsedResult.sensorState, nil), cgmTransmitterDelegate: cgmTransmitterDelegate, libreSensorSerialNumber: libreSensorSerialNumber, completionHandler: completionHandler)
}
todo
case .libre2:
LibreOOPClient.getLibreRawGlucoseOOPData(libreData: libreData, libreSensorSerialNumber: libreSensorSerialNumber, patchInfo: patchInfo, oopWebSite: oopWebSite, oopWebToken: oopWebToken) { (libreRawGlucoseOOPData) in
@ -348,14 +348,17 @@ fileprivate func historyToLibreGlucose(_ measurements: [LibreMeasurement]) -> [L
/// - array of libreRawGlucoseData, first is the most recent. Only returns recent readings, ie not the ones that are older than timeStampLastBgReading. 30 seconds are added here, meaning, new reading should be at least 30 seconds more recent than timeStampLastBgReading
/// - sensorState: status of the sensor
/// - sensorTimeInMinutes: age of sensor in minutes
fileprivate func parseLibre1DataWithOOPWebCalibration(libreData: Data, libre1DerivedAlgorithmParameters: Libre1DerivedAlgorithmParameters, timeStampLastBgReading: Date) -> (libreRawGlucoseData:[LibreRawGlucoseData], sensorState:LibreSensorState, sensorTimeInMinutes:Int) {
fileprivate func parseLibre1DataWithOOPWebCalibration(libreData: Data, libre1DerivedAlgorithmParameters: Libre1DerivedAlgorithmParameters, timeStampLastBgReading: Date) -> (libreRawGlucoseData:[LibreRawGlucoseData], sensorState:LibreSensorState, sensorTimeInMinutes:Int?) {
// initialise returnvalue, array of LibreRawGlucoseData
var finalResult:[LibreRawGlucoseData] = []
// calculate sensorState
let sensorState = LibreSensorState(stateByte: libreData[4])
// if sensorState is not .ready, then return empty array
if sensorState != .ready { return (finalResult, sensorState, nil) }
let sensorTimeInMinutes:Int = 256 * (Int)(libreData.uint8(position: 317) & 0xFF) + (Int)(libreData.uint8(position: 316) & 0xFF)
// iterates through glucoseData, compares timestamp, if still higher than timeStampLastBgReading (+ 30 seconds) then adds it to finalResult

View File

@ -13,9 +13,4 @@ enum ConstantsLibre {
/// calibration parameters will be stored locally on disk, this is the path
static let filePathForParameterStorage = "/Documents/LibreSensorParameters"
/// maximum age Libre 1
///
/// taking one hour spare. To avoid that there's a wrong value used eg in case the user manually starts the sensor and doesn't set the time correctly
static let maximumAgeLibre1InMinutes: Double = 20880.0 - 60.0
}

View File

@ -507,23 +507,6 @@ final class RootViewController: UIViewController {
// also for cases where calibration is not needed, we go through this code
if let activeSensor = activeSensor, let calibrator = calibrator, let bgReadingsAccessor = bgReadingsAccessor {
// TODO : check on sensorage should be done in another way, because 10 day sensors will now also be supported
// assuming it's a 14 day sensor (as 10 day sensor is not supported), if it's a Libre sensor and age > 14.5 days, then don't process the readings
if cgmTransmitter.cgmTransmitterType().sensorType() == .Libre{
guard abs(activeSensor.startDate.timeIntervalSinceNow) < ConstantsLibre.maximumAgeLibre1InMinutes * 60 else {
trace("sensor older than %{public}@ minutes. Readings will not be processed.", log: log, category: ConstantsLog.categoryRootView, type: .info, ConstantsLibre.maximumAgeLibre1InMinutes.description)
self.present(UIAlertController(title: Texts_Common.warning, message: Texts_HomeView.sensorAge14Days, actionHandler: nil), animated: true, completion: nil)
return
}
}
// initialize help variables
var latest3BgReadings = bgReadingsAccessor.getLatestBgReadings(limit: 3, howOld: nil, forSensor: activeSensor, ignoreRawData: false, ignoreCalculatedValue: false)
var lastCalibrationsForActiveSensorInLastXDays = calibrationsAccessor.getLatestCalibrations(howManyDays: 4, forSensor: activeSensor)