Skip to content

Commit

Permalink
Release 5.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon-b-m authored Oct 23, 2024
1 parent 07ce9f0 commit 6b62dfd
Show file tree
Hide file tree
Showing 35 changed files with 798 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Config.xcconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
APP_DISPLAY_NAME = iAPS
APP_VERSION = 5.2.2
APP_VERSION = 5.4.0
APP_BUILD_NUMBER = 1
COPYRIGHT_NOTICE =
DEVELOPER_TEAM = ##TEAM_ID##
Expand Down
27 changes: 4 additions & 23 deletions Core_Data.xcdatamodeld/Core_Data.xcdatamodel/contents
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="22758" systemVersion="23G93" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="23231" systemVersion="23G93" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="ActiveProfile" representedClassName="ActiveProfile" syncable="YES" codeGenerationType="class">
<attribute name="active" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="date" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="name" optional="YES" attributeType="String"/>
</entity>
<entity name="BGaverages" representedClassName="BGaverages" syncable="YES" codeGenerationType="class">
<attribute name="average" optional="YES" attributeType="Decimal" defaultValueString="0.0"/>
<attribute name="average_1" optional="YES" attributeType="Decimal" defaultValueString="0.0"/>
<attribute name="average_7" optional="YES" attributeType="Decimal" defaultValueString="0.0"/>
<attribute name="average_30" optional="YES" attributeType="Decimal" defaultValueString="0.0"/>
<attribute name="date" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
</entity>
<entity name="BGmedian" representedClassName="BGmedian" syncable="YES" codeGenerationType="class">
<attribute name="date" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="median" optional="YES" attributeType="Decimal" defaultValueString="0.0"/>
<attribute name="median_1" optional="YES" attributeType="Decimal" defaultValueString="0.0"/>
<attribute name="median_7" optional="YES" attributeType="Decimal" defaultValueString="0.0"/>
<attribute name="median_30" optional="YES" attributeType="Decimal" defaultValueString="0.0"/>
</entity>
<entity name="Carbohydrates" representedClassName="Carbohydrates" syncable="YES" codeGenerationType="class">
<attribute name="carbs" optional="YES" attributeType="Decimal" defaultValueString="0"/>
<attribute name="date" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
Expand All @@ -29,13 +15,6 @@
<attribute name="enteredBy" optional="YES" attributeType="String"/>
<attribute name="fat" optional="YES" attributeType="Decimal" defaultValueString="0.0"/>
</entity>
<entity name="HbA1c" representedClassName="HbA1c" syncable="YES" codeGenerationType="class">
<attribute name="date" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="hba1c" optional="YES" attributeType="Decimal" defaultValueString="0.0"/>
<attribute name="hba1c_1" optional="YES" attributeType="Decimal" defaultValueString="0.0"/>
<attribute name="hba1c_7" optional="YES" attributeType="Decimal" defaultValueString="0.0"/>
<attribute name="hba1c_30" optional="YES" attributeType="Decimal" defaultValueString="0.0"/>
</entity>
<entity name="Identifier" representedClassName="Identifier" syncable="YES" codeGenerationType="class">
<attribute name="id" optional="YES" attributeType="String"/>
</entity>
Expand All @@ -57,6 +36,7 @@
<entity name="LoopStatRecord" representedClassName="LoopStatRecord" syncable="YES" codeGenerationType="class">
<attribute name="duration" optional="YES" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES"/>
<attribute name="end" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="error" optional="YES" attributeType="String"/>
<attribute name="interval" optional="YES" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES"/>
<attribute name="loopStatus" optional="YES" attributeType="String"/>
<attribute name="start" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
Expand Down Expand Up @@ -164,6 +144,7 @@
<attribute name="iob" optional="YES" attributeType="Decimal" defaultValueString="0.0"/>
<attribute name="isf" optional="YES" attributeType="Decimal" defaultValueString="0.0"/>
<attribute name="minPredBG" optional="YES" attributeType="Decimal" defaultValueString="0.0"/>
<attribute name="mmol" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="target" optional="YES" attributeType="Decimal" defaultValueString="0.0"/>
</entity>
<entity name="StatsData" representedClassName="StatsData" syncable="YES" codeGenerationType="class">
Expand Down Expand Up @@ -199,4 +180,4 @@
<attribute name="dev" optional="YES" attributeType="String"/>
<attribute name="nr" optional="YES" attributeType="String"/>
</entity>
</model>
</model>
54 changes: 33 additions & 21 deletions FreeAPS/Sources/APS/APSManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -279,21 +279,21 @@ final class BaseAPSManager: APSManager, Injectable {
private func loopCompleted(error: Error? = nil, loopStatRecord: LoopStats) {
isLooping.send(false)

if let error = error {
warning(.apsManager, "Loop failed with error: \(error.localizedDescription)")
if let apsError = error {
warning(.apsManager, "Loop failed with error: \(apsError.localizedDescription)")
if let backgroundTask = backGroundTaskID {
UIApplication.shared.endBackgroundTask(backgroundTask)
backGroundTaskID = .invalid
}
processError(error)
processError(apsError)
loopStats(loopStatRecord: loopStatRecord, error: apsError)
} else {
debug(.apsManager, "Loop succeeded")
lastLoopDate = Date()
lastError.send(nil)
loopStats(loopStatRecord: loopStatRecord, error: nil)
}

loopStats(loopStatRecord: loopStatRecord)

if settings.closedLoop {
reportEnacted(received: error == nil)
}
Expand Down Expand Up @@ -885,8 +885,8 @@ final class BaseAPSManager: APSManager, Injectable {
let glucose = array
let justGlucoseArray = glucose.compactMap({ each in Int(each.glucose as Int16) })
let totalReadings = justGlucoseArray.count
let highLimit = settingsManager.settings.high
let lowLimit = settingsManager.settings.low
let highLimit = settings.high
let lowLimit = settings.low
let hyperArray = glucose.filter({ $0.glucose >= Int(highLimit) })
let hyperReadings = hyperArray.compactMap({ each in each.glucose as Int16 }).count
let hyperPercentage = Double(hyperReadings) / Double(totalReadings) * 100
Expand Down Expand Up @@ -942,7 +942,7 @@ final class BaseAPSManager: APSManager, Injectable {
cv = sd / Double(glucoseAverage) * 100
}
let conversionFactor = 0.0555
let units = settingsManager.settings.units
let units = settings.units

var output: (ifcc: Double, ngsp: Double, average: Double, median: Double, sd: Double, cv: Double, readings: Double)
output = (
Expand Down Expand Up @@ -982,10 +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: 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 @@ -1009,8 +1015,8 @@ final class BaseAPSManager: APSManager, Injectable {
return
}

if settingsManager.settings.uploadStats {
let units = settingsManager.settings.units
if settings.uploadStats {
let units = settings.units
let preferences = settingsManager.preferences

// Carbs
Expand Down Expand Up @@ -1049,7 +1055,7 @@ final class BaseAPSManager: APSManager, Injectable {
let branch = branch()
let copyrightNotice_ = Bundle.main.infoDictionary?["NSHumanReadableCopyright"] as? String ?? ""
let pump_ = pumpManager?.localizedTitle ?? ""
let cgm = settingsManager.settings.cgm
let cgm = settings.cgm
let file = OpenAPS.Monitor.statistics
var iPa: Decimal = 75
if preferences.useCustomPeakTime {
Expand Down Expand Up @@ -1085,7 +1091,7 @@ final class BaseAPSManager: APSManager, Injectable {
total: roundDecimal(Decimal(totalDaysGlucose.median), 1)
)

let overrideHbA1cUnit = settingsManager.settings.overrideHbA1cUnit
let overrideHbA1cUnit = settings.overrideHbA1cUnit

let hbs = Durations(
day: ((units == .mmolL && !overrideHbA1cUnit) || (units == .mgdL && overrideHbA1cUnit)) ?
Expand Down Expand Up @@ -1133,10 +1139,10 @@ final class BaseAPSManager: APSManager, Injectable {
total: Decimal(totalDays_.normal_)
)
let range = Threshold(
low: units == .mmolL ? roundDecimal(settingsManager.settings.low.asMmolL, 1) :
roundDecimal(settingsManager.settings.low, 0),
high: units == .mmolL ? roundDecimal(settingsManager.settings.high.asMmolL, 1) :
roundDecimal(settingsManager.settings.high, 0)
low: units == .mmolL ? roundDecimal(settings.low.asMmolL, 1) :
roundDecimal(settings.low, 0),
high: units == .mmolL ? roundDecimal(settings.high.asMmolL, 1) :
roundDecimal(settings.high, 0)
)
let TimeInRange = TIRs(
TIR: tir,
Expand Down Expand Up @@ -1183,6 +1189,8 @@ final class BaseAPSManager: APSManager, Injectable {
let loopstat = LoopCycles(
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 All @@ -1191,7 +1199,7 @@ final class BaseAPSManager: APSManager, Injectable {
max_interval: oneDayLoops.max_interval,
avg_duration: oneDayLoops.avg_duration,
median_duration: oneDayLoops.median_duration,
min_duration: oneDayLoops.max_duration,
min_duration: oneDayLoops.min_duration,
max_duration: oneDayLoops.max_duration
)

Expand Down Expand Up @@ -1242,8 +1250,8 @@ final class BaseAPSManager: APSManager, Injectable {
Variance: variance
),
id: getIdentifier(),
dob: settingsManager.settings.birthDate,
sex: settingsManager.settings.sexSetting
dob: settings.birthDate,
sex: settings.sexSetting
)
storage.save(dailystat, as: file)
nightscout.uploadStatistics(dailystat: dailystat)
Expand Down Expand Up @@ -1304,7 +1312,7 @@ final class BaseAPSManager: APSManager, Injectable {
return branch
}

private func loopStats(loopStatRecord: LoopStats) {
private func loopStats(loopStatRecord: LoopStats, error: Error?) {
coredataContext.perform {
let nLS = LoopStatRecord(context: self.coredataContext)

Expand All @@ -1314,6 +1322,10 @@ final class BaseAPSManager: APSManager, Injectable {
nLS.duration = loopStatRecord.duration ?? 0.0
nLS.interval = loopStatRecord.interval ?? 0.0

if let error = error {
nLS.error = error.localizedDescription.string
}

try? self.coredataContext.save()
}
}
Expand Down
6 changes: 6 additions & 0 deletions FreeAPS/Sources/APS/OpenAPS/OpenAPS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,12 @@ final class OpenAPS {
saveSuggestion.eventualBG = Decimal(suggestion.eventualBG ?? 100) as NSDecimalNumber
saveSuggestion.date = Date.now

if let units = readJSON(json: profile, variable: "out_units"), units.contains("mmol/L") {
saveSuggestion.mmol = true
} else {
saveSuggestion.mmol = false
}

try? coredataContext.save()
} else {
debug(.dynamic, "Couldn't save suggestion to CoreData")
Expand Down
6 changes: 2 additions & 4 deletions FreeAPS/Sources/Helpers/CoreDataStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class CoreDataStack: ObservableObject {

container.loadPersistentStores(completionHandler: { _, error in
guard let error = error as NSError? else { return }
fatalError("Unresolved error: \(error), \(error.userInfo)")
debug(.apsManager, "Unresolved error: \(error), \(error.userInfo)")
})

return container
Expand All @@ -25,10 +25,8 @@ class CoreDataStack: ObservableObject {
do {
try context.save()
} catch {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
let nserror = error as NSError
fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
debug(.apsManager, "Unresolved error \(nserror), \(nserror.userInfo)")
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions FreeAPS/Sources/Localizations/Main/ar.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,15 @@ Enact a temp Basal or a temp target */
/* Loop Errors in statPanel */
"Errors" = "Errors";

/* Loop Statistics pop-up description */
"Success = Started / Completed (loops)" = "Success = Started / Completed (loops)";

/* Loop Statistics pop-up */
"Most Frequent Error" = "Most Frequent Error";

/* Loop Statistics pop-up */
"Non-completed Loops" = "Non-completed Loops";

/* Average loop interval */
"Interval" = "Interval";

Expand Down Expand Up @@ -2460,6 +2469,21 @@ Enact a temp Basal or a temp target */
/* Threshold Table Columns Title */
"Threshold" = "Threshold";

/* Dynamic settings View */
"Averages" = "Averages";

/* Dynamic settings View */
"Average ISF" = "Average ISF";

/* Dynamic settings View */
"Average CR" = "Average CR";

/* Dynamic settings View */
"Average CSF" = "Average CSF";

/* Dynamic settings View */
"ISF: Insulin Sensitivity, CR: Carb Ratio,\nCSF: Carb Sensitivity = ISF/CR" = "ISF: Insulin Sensitivity, CR: Carb Ratio,\nCSF: Carb Sensitivity = ISF/CR";

/* Header */
"Calculator settings" = "Calculator settings";

Expand Down
24 changes: 24 additions & 0 deletions FreeAPS/Sources/Localizations/Main/da.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,15 @@ Enact a temp Basal or a temp target */
/* Loop Errors in statPanel */
"Errors" = "Fejl";

/* Loop Statistics pop-up description */
"Success = Started / Completed (loops)" = "Success = Started / Completed (loops)";

/* Loop Statistics pop-up */
"Most Frequent Error" = "Most Frequent Error";

/* Loop Statistics pop-up */
"Non-completed Loops" = "Non-completed Loops";

/* Average loop interval */
"Interval" = "Interval";

Expand Down Expand Up @@ -2459,6 +2468,21 @@ Enact a temp Basal or a temp target */
/* Threshold Table Columns Title */
"Threshold" = "Grænseværdi";

/* Dynamic settings View */
"Averages" = "Averages";

/* Dynamic settings View */
"Average ISF" = "Average ISF";

/* Dynamic settings View */
"Average CR" = "Average CR";

/* Dynamic settings View */
"Average CSF" = "Average CSF";

/* Dynamic settings View */
"ISF: Insulin Sensitivity, CR: Carb Ratio,\nCSF: Carb Sensitivity = ISF/CR" = "ISF: Insulin Sensitivity, CR: Carb Ratio,\nCSF: Carb Sensitivity = ISF/CR";

/* Header */
"Calculator settings" = "Lommeregner indstillinger";

Expand Down
24 changes: 24 additions & 0 deletions FreeAPS/Sources/Localizations/Main/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,15 @@ Enact a temp Basal or a temp target */
/* Loop Errors in statPanel */
"Errors" = "Fehler";

/* Loop Statistics pop-up description */
"Success = Started / Completed (loops)" = "Success = Started / Completed (loops)";

/* Loop Statistics pop-up */
"Most Frequent Error" = "Most Frequent Error";

/* Loop Statistics pop-up */
"Non-completed Loops" = "Non-completed Loops";

/* Average loop interval */
"Interval" = "Intervall";

Expand Down Expand Up @@ -2459,6 +2468,21 @@ Enact a temp Basal or a temp target */
/* Threshold Table Columns Title */
"Threshold" = "Grenzwert";

/* Dynamic settings View */
"Averages" = "Averages";

/* Dynamic settings View */
"Average ISF" = "Average ISF";

/* Dynamic settings View */
"Average CR" = "Average CR";

/* Dynamic settings View */
"Average CSF" = "Average CSF";

/* Dynamic settings View */
"ISF: Insulin Sensitivity, CR: Carb Ratio,\nCSF: Carb Sensitivity = ISF/CR" = "ISF: Insulin Sensitivity, CR: Carb Ratio,\nCSF: Carb Sensitivity = ISF/CR";

/* Header */
"Calculator settings" = "Berechnungseinstellungen";

Expand Down
Loading

0 comments on commit 6b62dfd

Please sign in to comment.