Skip to content

Commit

Permalink
Merge pull request #225 from bjornoleh/iAPS_prediction_colours
Browse files Browse the repository at this point in the history
Use iAPS colours for COB, IOB, UAM and ZT, refactor colouring
  • Loading branch information
marionbarker authored Oct 22, 2023
2 parents 15e1ffe + 09ba93e commit 14cc1d8
Show file tree
Hide file tree
Showing 21 changed files with 736 additions and 51 deletions.
2 changes: 1 addition & 1 deletion LoopFollow/Controllers/NightScout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,4 @@ extension MainViewController {
noteGraphData.removeAll()
updateNotes()
}
}
}
104 changes: 54 additions & 50 deletions LoopFollow/Controllers/Nightscout/DeviceStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,60 +219,64 @@ extension MainViewController {
var graphtype = ""
var predictioncolor = UIColor.systemGray
PredictionLabel.textColor = predictioncolor
if let enactdata = lastLoopRecord["enacted"] as? [String:AnyObject] {
if let predbgdata = enactdata["predBGs"] as? [String:AnyObject] {
if predbgdata["COB"] != nil {
graphtype="COB"
predictioncolor = UIColor.systemYellow
PredictionLabel.textColor = predictioncolor
}
else if predbgdata["UAM"] != nil {
graphtype="UAM"
predictioncolor = UIColor.systemOrange
PredictionLabel.textColor = predictioncolor
}
else if predbgdata["IOB"] != nil {
graphtype="IOB"
predictioncolor = UIColor.systemBlue
PredictionLabel.textColor = predictioncolor
}
else {
graphtype="ZT"
predictioncolor = UIColor.systemGreen
PredictionLabel.textColor = predictioncolor
}

let graphdata = predbgdata[graphtype] as! [Double]

if let eventualdata = lastLoopRecord["enacted"] as? [String:AnyObject] {
if let eventualBGValue = eventualdata["eventualBG"] as? NSNumber {
let eventualBGStringValue = String(describing: eventualBGValue)
PredictionLabel.text = bgUnits.toDisplayUnits(eventualBGStringValue)
}

if let enactdata = lastLoopRecord["enacted"] as? [String:AnyObject],
let predbgdata = enactdata["predBGs"] as? [String:AnyObject] {

if predbgdata["COB"] != nil {
graphtype = "COB"
} else if predbgdata["UAM"] != nil {
graphtype = "UAM"
} else if predbgdata["IOB"] != nil {
graphtype = "IOB"
} else {
graphtype = "ZT"
}

// Access the color based on graphtype
var colorName = ""
switch graphtype {
case "COB": colorName = "LoopYellow"
case "UAM": colorName = "UAM"
case "IOB": colorName = "Insulin"
case "ZT": colorName = "ZT"
default: break
}

if let selectedColor = UIColor(named: colorName) {
predictioncolor = selectedColor
PredictionLabel.textColor = predictioncolor
}

let graphdata = predbgdata[graphtype] as! [Double]

if let eventualdata = lastLoopRecord["enacted"] as? [String:AnyObject] {
if let eventualBGValue = eventualdata["eventualBG"] as? NSNumber {
let eventualBGStringValue = String(describing: eventualBGValue)
PredictionLabel.text = bgUnits.toDisplayUnits(eventualBGStringValue)
}

if UserDefaultsRepository.downloadPrediction.value && latestLoopTime < lastLoopTime {
predictionData.removeAll()
var predictionTime = lastLoopTime
let toLoad = Int(UserDefaultsRepository.predictionToLoad.value * 12)
var i = 0
while i <= toLoad {
if i < graphdata.count {
let prediction = ShareGlucoseData(sgv: Int(round(graphdata[i])), date: predictionTime, direction: "flat")
predictionData.append(prediction)
predictionTime += 300
}
i += 1
}

if UserDefaultsRepository.downloadPrediction.value && latestLoopTime < lastLoopTime {
predictionData.removeAll()
var predictionTime = lastLoopTime
let toLoad = Int(UserDefaultsRepository.predictionToLoad.value * 12)
var i = 0
while i <= toLoad {
if i < graphdata.count {
let prediction = ShareGlucoseData(sgv: Int(round(graphdata[i])), date: predictionTime, direction: "flat")
predictionData.append(prediction)
predictionTime += 300
}

i += 1
}

let predMin = graphdata.min()
let predMax = graphdata.max()
tableData[9].value = bgUnits.toDisplayUnits(String(predMin!)) + "/" + bgUnits.toDisplayUnits(String(predMax!))

updatePredictionGraph(color: predictioncolor)
}

let predMin = graphdata.min()
let predMax = graphdata.max()
tableData[9].value = bgUnits.toDisplayUnits(String(predMin!)) + "/" + bgUnits.toDisplayUnits(String(predMax!))

updatePredictionGraph(color: predictioncolor)
}

if let loopStatus = lastLoopRecord["recommendedTempBasal"] as? [String:AnyObject] {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "0.500",
"blue" : "0.988",
"green" : "0.588",
"red" : "0.118"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "0.500",
"blue" : "0.988",
"green" : "0.588",
"red" : "0.118"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions LoopFollow/Resources/Assets.xcassets/Colors/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "1.000",
"green" : "0.288",
"red" : "0.118"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "1.000",
"green" : "0.288",
"red" : "0.118"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.988",
"green" : "0.588",
"red" : "0.118"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.988",
"green" : "0.588",
"red" : "0.118"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.089",
"green" : "0.940",
"red" : "1.000"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.089",
"green" : "0.940",
"red" : "1.000"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.741",
"green" : "0.741",
"red" : "0.741"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.741",
"green" : "0.741",
"red" : "0.741"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.592",
"green" : "0.812",
"red" : "0.435"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.592",
"green" : "0.812",
"red" : "0.435"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading

0 comments on commit 14cc1d8

Please sign in to comment.