|
@@ -4,7 +4,7 @@ import SwiftDate
|
|
|
import SwiftUI
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct ChartsView: View {
|
|
struct ChartsView: View {
|
|
|
- @FetchRequest var fetchRequest: FetchedResults<Readings>
|
|
|
|
|
|
|
+ @FetchRequest var glucose: FetchedResults<GlucoseStored>
|
|
|
|
|
|
|
|
@Binding var highLimit: Decimal
|
|
@Binding var highLimit: Decimal
|
|
|
@Binding var lowLimit: Decimal
|
|
@Binding var lowLimit: Decimal
|
|
@@ -40,7 +40,7 @@ struct ChartsView: View {
|
|
|
_ units: Binding<GlucoseUnits>,
|
|
_ units: Binding<GlucoseUnits>,
|
|
|
_ overrideUnit: Binding<Bool>,
|
|
_ overrideUnit: Binding<Bool>,
|
|
|
_ standing: Binding<Bool>
|
|
_ standing: Binding<Bool>
|
|
|
- ) { _fetchRequest = FetchRequest<Readings>(
|
|
|
|
|
|
|
+ ) { _glucose = FetchRequest<GlucoseStored>(
|
|
|
sortDescriptors: [NSSortDescriptor(key: "date", ascending: false)],
|
|
sortDescriptors: [NSSortDescriptor(key: "date", ascending: false)],
|
|
|
predicate: NSPredicate(format: "glucose > 0 AND date > %@", filter)
|
|
predicate: NSPredicate(format: "glucose > 0 AND date > %@", filter)
|
|
|
)
|
|
)
|
|
@@ -55,13 +55,12 @@ struct ChartsView: View {
|
|
|
// Be aware of the low/lowLimit difference. lowLimit/highLimit is always in mg/dl, whereas low/high is configurable in settings
|
|
// Be aware of the low/lowLimit difference. lowLimit/highLimit is always in mg/dl, whereas low/high is configurable in settings
|
|
|
let low = lowLimit * (units == .mmolL ? Decimal(conversionFactor) : 1)
|
|
let low = lowLimit * (units == .mmolL ? Decimal(conversionFactor) : 1)
|
|
|
let high = highLimit * (units == .mmolL ? Decimal(conversionFactor) : 1)
|
|
let high = highLimit * (units == .mmolL ? Decimal(conversionFactor) : 1)
|
|
|
- let readings = fetchRequest
|
|
|
|
|
- let count = readings.count
|
|
|
|
|
|
|
+ let count = glucose.count
|
|
|
// The symbol size when fewer readings are larger
|
|
// The symbol size when fewer readings are larger
|
|
|
let sizeOfDataPoints: CGFloat = count < 20 ? 50 : count < 50 ? 35 : count > 2000 ? 5 : 15
|
|
let sizeOfDataPoints: CGFloat = count < 20 ? 50 : count < 50 ? 35 : count > 2000 ? 5 : 15
|
|
|
|
|
|
|
|
return Chart {
|
|
return Chart {
|
|
|
- ForEach(readings.filter({ $0.glucose > Int(highLimit) }), id: \.date) { item in
|
|
|
|
|
|
|
+ ForEach(glucose.filter({ $0.glucose > Int(highLimit) }), id: \.date) { item in
|
|
|
PointMark(
|
|
PointMark(
|
|
|
x: .value("Date", item.date ?? Date()),
|
|
x: .value("Date", item.date ?? Date()),
|
|
|
y: .value("High", Double(item.glucose) * (units == .mmolL ? self.conversionFactor : 1))
|
|
y: .value("High", Double(item.glucose) * (units == .mmolL ? self.conversionFactor : 1))
|
|
@@ -70,7 +69,7 @@ struct ChartsView: View {
|
|
|
.symbolSize(sizeOfDataPoints)
|
|
.symbolSize(sizeOfDataPoints)
|
|
|
}
|
|
}
|
|
|
ForEach(
|
|
ForEach(
|
|
|
- readings
|
|
|
|
|
|
|
+ glucose
|
|
|
.filter({
|
|
.filter({
|
|
|
$0.glucose >= Int(lowLimit) && $0
|
|
$0.glucose >= Int(lowLimit) && $0
|
|
|
.glucose <= Int(highLimit) }),
|
|
.glucose <= Int(highLimit) }),
|
|
@@ -83,7 +82,7 @@ struct ChartsView: View {
|
|
|
.foregroundStyle(.green)
|
|
.foregroundStyle(.green)
|
|
|
.symbolSize(sizeOfDataPoints)
|
|
.symbolSize(sizeOfDataPoints)
|
|
|
}
|
|
}
|
|
|
- ForEach(readings.filter({ $0.glucose < Int(lowLimit) }), id: \.date) { item in
|
|
|
|
|
|
|
+ ForEach(glucose.filter({ $0.glucose < Int(lowLimit) }), id: \.date) { item in
|
|
|
PointMark(
|
|
PointMark(
|
|
|
x: .value("Date", item.date ?? Date()),
|
|
x: .value("Date", item.date ?? Date()),
|
|
|
y: .value("Low", Double(item.glucose) * (units == .mmolL ? conversionFactor : 1))
|
|
y: .value("Low", Double(item.glucose) * (units == .mmolL ? conversionFactor : 1))
|
|
@@ -207,7 +206,6 @@ struct ChartsView: View {
|
|
|
|
|
|
|
|
var groupedGlucose: some View {
|
|
var groupedGlucose: some View {
|
|
|
VStack(alignment: .leading, spacing: 20) {
|
|
VStack(alignment: .leading, spacing: 20) {
|
|
|
- let glucose = fetchRequest
|
|
|
|
|
let mapGlucose = glucose.compactMap({ each in each.glucose })
|
|
let mapGlucose = glucose.compactMap({ each in each.glucose })
|
|
|
if !mapGlucose.isEmpty {
|
|
if !mapGlucose.isEmpty {
|
|
|
let mapGlucoseAcuteLow = mapGlucose.filter({ $0 < Int16(3.3 / 0.0555) })
|
|
let mapGlucoseAcuteLow = mapGlucose.filter({ $0 < Int16(3.3 / 0.0555) })
|
|
@@ -237,7 +235,6 @@ struct ChartsView: View {
|
|
|
|
|
|
|
|
var groupedGlucoseStatsLaying: some View {
|
|
var groupedGlucoseStatsLaying: some View {
|
|
|
HStack {
|
|
HStack {
|
|
|
- let glucose = fetchRequest
|
|
|
|
|
let mapGlucose = glucose.compactMap({ each in each.glucose })
|
|
let mapGlucose = glucose.compactMap({ each in each.glucose })
|
|
|
if !mapGlucose.isEmpty {
|
|
if !mapGlucose.isEmpty {
|
|
|
let mapGlucoseLow = mapGlucose.filter({ $0 < Int16(3.3 / 0.0555) })
|
|
let mapGlucoseLow = mapGlucose.filter({ $0 < Int16(3.3 / 0.0555) })
|
|
@@ -271,8 +268,6 @@ struct ChartsView: View {
|
|
|
let hypoLimit = Int(lowLimit)
|
|
let hypoLimit = Int(lowLimit)
|
|
|
let hyperLimit = Int(highLimit)
|
|
let hyperLimit = Int(highLimit)
|
|
|
|
|
|
|
|
- let glucose = fetchRequest
|
|
|
|
|
-
|
|
|
|
|
let justGlucoseArray = glucose.compactMap({ each in Int(each.glucose as Int16) })
|
|
let justGlucoseArray = glucose.compactMap({ each in Int(each.glucose as Int16) })
|
|
|
let totalReadings = justGlucoseArray.count
|
|
let totalReadings = justGlucoseArray.count
|
|
|
|
|
|