Skip to content

Commit

Permalink
Merge branch 'dev' into Crowdin
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon-b-m committed Nov 11, 2023
2 parents 652ca7b + 3220f53 commit afbefc5
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 66 deletions.
1 change: 1 addition & 0 deletions Core_Data.xcdatamodeld/Core_Data.xcdatamodel/contents
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
</entity>
<entity name="Readings" representedClassName="Readings" syncable="YES" codeGenerationType="class">
<attribute name="date" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="direction" optional="YES" attributeType="String"/>
<attribute name="glucose" optional="YES" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="id" optional="YES" attributeType="String"/>
</entity>
Expand Down
4 changes: 4 additions & 0 deletions FreeAPS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
1927C8E62744606D00347C69 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 1927C8E82744606D00347C69 /* InfoPlist.strings */; };
1935364028496F7D001E0B16 /* Oref2_variables.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1935363F28496F7D001E0B16 /* Oref2_variables.swift */; };
193F6CDD2A512C8F001240FD /* Loops.swift in Sources */ = {isa = PBXBuildFile; fileRef = 193F6CDC2A512C8F001240FD /* Loops.swift */; };
1956FB212AFF79E200C7B4FF /* CoreDataStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1956FB202AFF79E200C7B4FF /* CoreDataStorage.swift */; };
195D80B42AF6973A00D25097 /* DynamicRootView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 195D80B32AF6973A00D25097 /* DynamicRootView.swift */; };
195D80B72AF697B800D25097 /* DynamicDataFlow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 195D80B62AF697B800D25097 /* DynamicDataFlow.swift */; };
195D80B92AF697F700D25097 /* DynamicProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 195D80B82AF697F700D25097 /* DynamicProvider.swift */; };
Expand Down Expand Up @@ -532,6 +533,7 @@
1927C8FE274489BA00347C69 /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/InfoPlist.strings; sourceTree = "<group>"; };
1935363F28496F7D001E0B16 /* Oref2_variables.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Oref2_variables.swift; sourceTree = "<group>"; };
193F6CDC2A512C8F001240FD /* Loops.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Loops.swift; sourceTree = "<group>"; };
1956FB202AFF79E200C7B4FF /* CoreDataStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataStorage.swift; sourceTree = "<group>"; };
195D80B32AF6973A00D25097 /* DynamicRootView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DynamicRootView.swift; sourceTree = "<group>"; };
195D80B62AF697B800D25097 /* DynamicDataFlow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DynamicDataFlow.swift; sourceTree = "<group>"; };
195D80B82AF697F700D25097 /* DynamicProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DynamicProvider.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1706,6 +1708,7 @@
38FCF3FC25E997A80078B0D1 /* PumpHistoryStorage.swift */,
38F3B2EE25ED8E2A005C48AA /* TempTargetsStorage.swift */,
CE82E02428E867BA00473A9C /* AlertStorage.swift */,
1956FB202AFF79E200C7B4FF /* CoreDataStorage.swift */,
);
path = Storage;
sourceTree = "<group>";
Expand Down Expand Up @@ -2905,6 +2908,7 @@
E25073BC86C11C3D6A42F5AC /* CalibrationsStateModel.swift in Sources */,
BA90041DC8991147E5C8C3AA /* CalibrationsRootView.swift in Sources */,
E3A08AAE59538BC8A8ABE477 /* NotificationsConfigDataFlow.swift in Sources */,
1956FB212AFF79E200C7B4FF /* CoreDataStorage.swift in Sources */,
0F7A65FBD2CD8D6477ED4539 /* NotificationsConfigProvider.swift in Sources */,
3171D2818C7C72CD1584BB5E /* NotificationsConfigStateModel.swift in Sources */,
CD78BB94E43B249D60CC1A1B /* NotificationsConfigRootView.swift in Sources */,
Expand Down
34 changes: 34 additions & 0 deletions FreeAPS/Sources/APS/Storage/CoreDataStorage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import CoreData
import Foundation
import SwiftDate
import Swinject

final class CoreDataStorage {
let coredataContext = CoreDataStack.shared.persistentContainer.viewContext // newBackgroundContext()

func fetchGlucose(interval: NSDate) -> [Readings] {
var fetchGlucose = [Readings]()
coredataContext.performAndWait {
let requestReadings = Readings.fetchRequest() as NSFetchRequest<Readings>
let sort = NSSortDescriptor(key: "date", ascending: false)
requestReadings.sortDescriptors = [sort]
requestReadings.predicate = NSPredicate(
format: "glucose > 0 AND date > %@", interval
)
try? fetchGlucose = self.coredataContext.fetch(requestReadings)
}
return fetchGlucose
}

func fetchLatestOverride() -> [Override] {
var overrideArray = [Override]()
coredataContext.performAndWait {
let requestOverrides = Override.fetchRequest() as NSFetchRequest<Override>
let sortOverride = NSSortDescriptor(key: "date", ascending: false)
requestOverrides.sortDescriptors = [sortOverride]
requestOverrides.fetchLimit = 1
try? overrideArray = self.coredataContext.fetch(requestOverrides)
}
return overrideArray
}
}
3 changes: 3 additions & 0 deletions FreeAPS/Sources/APS/Storage/GlucoseStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ final class BaseGlucoseStorage: GlucoseStorage, Injectable {
var bg_ = 0
var bgDate = Date()
var id = ""
var direction = ""

if glucose.isNotEmpty {
bg_ = glucose[0].glucose ?? 0
bgDate = glucose[0].dateString
id = glucose[0].id
direction = glucose[0].direction?.symbol ?? "↔︎"
}

if bg_ != 0 {
Expand All @@ -84,6 +86,7 @@ final class BaseGlucoseStorage: GlucoseStorage, Injectable {
dataForForStats.date = bgDate
dataForForStats.glucose = Int16(bg_)
dataForForStats.id = id
dataForForStats.direction = direction
try? self.coredataContext.save()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,9 @@ Enact a temp Basal or a temp target */
/* */
"Predictions" = "Predictions";

/* Watch Config Option */
"Display Protein & Fat" = "Display Protein & Fat";

/* ----------------------- New Bolus Calculator ---------------------------*/

/* Warning about bolus recommendation. Title */
Expand Down
1 change: 1 addition & 0 deletions FreeAPS/Sources/Models/DateFilter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import Foundation

struct DateFilter {
var twoHours = Date().addingTimeInterval(-2.hours.timeInterval) as NSDate
var today = Calendar.current.startOfDay(for: Date()) as NSDate
var day = Date().addingTimeInterval(-24.hours.timeInterval) as NSDate
var week = Date().addingTimeInterval(-7.days.timeInterval) as NSDate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ extension AddTempTarget {
}

if state.viewPercantage {
Section(
header: Text("")
) {
Section {
VStack {
Text("\(state.percentage.formatted(.number)) % Insulin")
.foregroundColor(isEditing ? .orange : .blue)
.font(.largeTitle)
.padding(.vertical)
Slider(
value: $state.percentage,
in: 15 ...
Expand All @@ -54,33 +56,27 @@ extension AddTempTarget {
isEditing = editing
}
)
HStack {
Text("\(state.percentage.formatted(.number)) % Insulin")
.foregroundColor(isEditing ? .orange : .blue)
.font(.largeTitle)
}
// Only display target slider when not 100 %
if state.percentage != 100 {
Spacer()
Divider()
Text(
(
state
.units == .mmolL ?
"\(state.computeTarget().asMmolL.formatted(.number.grouping(.never).rounded().precision(.fractionLength(1)))) mmol/L" :
"\(state.computeTarget().formatted(.number.grouping(.never).rounded().precision(.fractionLength(0)))) mg/dl"
)
+ NSLocalizedString(" Target Glucose", comment: "")
)
.foregroundColor(.green)
.padding(.vertical)

Slider(
value: $state.hbt,
in: 101 ... 295,
step: 1
).accentColor(.green)

HStack {
Text(
(
state
.units == .mmolL ?
"\(state.computeTarget().asMmolL.formatted(.number.grouping(.never).rounded().precision(.fractionLength(1)))) mmol/L" :
"\(state.computeTarget().formatted(.number.grouping(.never).rounded().precision(.fractionLength(0)))) mg/dl"
)
+ NSLocalizedString(" Target Glucose", comment: "")
)
.foregroundColor(.green)
}
}
}
}
Expand Down
16 changes: 2 additions & 14 deletions FreeAPS/Sources/Modules/Bolus/BolusProvider.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import CoreData

extension Bolus {
final class Provider: BaseProvider, BolusProvider {
let coredataContext = CoreDataStack.shared.persistentContainer.viewContext
let coreDataStorage = CoreDataStorage()

var suggestion: Suggestion? {
storage.retrieve(OpenAPS.Enact.suggested, as: Suggestion.self)
Expand All @@ -15,17 +13,7 @@ extension Bolus {
}

func fetchGlucose() -> [Readings] {
var fetchGlucose = [Readings]()
coredataContext.performAndWait {
let requestReadings = Readings.fetchRequest() as NSFetchRequest<Readings>
let sort = NSSortDescriptor(key: "date", ascending: true)
requestReadings.sortDescriptors = [sort]
requestReadings.predicate = NSPredicate(
format: "glucose > 0 AND date > %@",
Date().addingTimeInterval(-1.hours.timeInterval) as NSDate
)
try? fetchGlucose = self.coredataContext.fetch(requestReadings)
}
let fetchGlucose = coreDataStorage.fetchGlucose(interval: DateFilter().twoHours)
return fetchGlucose
}
}
Expand Down
5 changes: 2 additions & 3 deletions FreeAPS/Sources/Modules/Bolus/BolusStateModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,14 @@ extension Bolus {
func getDeltaBG() {
let glucose = provider.fetchGlucose()
guard glucose.count >= 3 else { return }
let lastGlucose = glucose.last?.glucose ?? 0
let thirdLastGlucose = glucose[glucose.count - 3]
let lastGlucose = glucose.first?.glucose ?? 0
let thirdLastGlucose = glucose[2]
let delta = Decimal(lastGlucose) - Decimal(thirdLastGlucose.glucose)
deltaBG = delta
}

// CALCULATIONS FOR THE BOLUS CALCULATOR
func calculateInsulin() -> Decimal {
// for mmol conversion
var conversion: Decimal = 1.0
if units == .mmolL {
conversion = 0.0555
Expand Down
Loading

0 comments on commit afbefc5

Please sign in to comment.