Przeglądaj źródła

Move TDD and Dynamic ratios to oref0

Jon Mårtensson 4 lat temu
rodzic
commit
017c8de0c4

+ 4 - 0
FreeAPS.xcodeproj/project.pbxproj

@@ -17,6 +17,7 @@
 		19795118275953E50044850D /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 198377D4266BFFF6004DE65E /* Localizable.strings */; };
 		198377D2266BFFF6004DE65E /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 198377D4266BFFF6004DE65E /* Localizable.strings */; };
 		199561C1275E61A50077B976 /* HealthKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 199561C0275E61A50077B976 /* HealthKit.framework */; };
+		19F79FA9283AE7E000646323 /* TDD.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19F79FA8283AE7E000646323 /* TDD.swift */; };
 		1BBB001DAD60F3B8CEA4B1C7 /* ISFEditorStateModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 505E09DC17A0C3D0AF4B66FE /* ISFEditorStateModel.swift */; };
 		1D845DF2E3324130E1D95E67 /* DataTableProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60744C3E9BB3652895C908CC /* DataTableProvider.swift */; };
 		23888883D4EA091C88480FF2 /* BolusProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = C19984D62EFC0035A9E9644D /* BolusProvider.swift */; };
@@ -437,6 +438,7 @@
 		199732B5271B9EE900129A3F /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/Localizable.strings"; sourceTree = "<group>"; };
 		19C166682756EFBD00ED12E3 /* sk */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sk; path = sk.lproj/InfoPlist.strings; sourceTree = "<group>"; };
 		19C166692756EFBD00ED12E3 /* sk */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sk; path = sk.lproj/Localizable.strings; sourceTree = "<group>"; };
+		19F79FA8283AE7E000646323 /* TDD.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TDD.swift; sourceTree = "<group>"; };
 		1CAE81192B118804DCD23034 /* SnoozeProvider.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = SnoozeProvider.swift; sourceTree = "<group>"; };
 		212E8BFE6D66EE65AA26A114 /* CalibrationsProvider.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = CalibrationsProvider.swift; sourceTree = "<group>"; };
 		223EC0494F55A91E3EA69EF4 /* BolusStateModel.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = BolusStateModel.swift; sourceTree = "<group>"; };
@@ -1283,6 +1285,7 @@
 				3871F39B25ED892B0013ECB5 /* TempTarget.swift */,
 				3811DE8E25C9D80400A708ED /* User.swift */,
 				E0D4F80427513ECF00BDF1FE /* HealthKitSample.swift */,
+				19F79FA8283AE7E000646323 /* TDD.swift */,
 			);
 			path = Models;
 			sourceTree = "<group>";
@@ -2256,6 +2259,7 @@
 				9702FF92A09C53942F20D7EA /* TargetsEditorRootView.swift in Sources */,
 				38E8754F275556FA00975559 /* WatchManager.swift in Sources */,
 				A228DF96647338139F152B15 /* PreferencesEditorDataFlow.swift in Sources */,
+				19F79FA9283AE7E000646323 /* TDD.swift in Sources */,
 				389ECE052601144100D86C4F /* ConcurrentMap.swift in Sources */,
 				E4984C5262A90469788754BB /* PreferencesEditorProvider.swift in Sources */,
 				DD399FB31EACB9343C944C4C /* PreferencesEditorStateModel.swift in Sources */,

Plik diff jest za duży
+ 1 - 1
FreeAPS/Resources/javascript/bundle/determine-basal.js


+ 4 - 419
FreeAPS/Resources/javascript/middleware/determine_basal.js

@@ -1,420 +1,5 @@
-function middleware(iob, currenttemp, glucose, profile, autosens, meal, reservoir, clock, pumphistory, preferences, basalProfile) {
-     
-    // Dynamic ratios and TDD calculation
-    const BG = glucose[0].glucose;
-    var chrisFormula = preferences.enableChris;
-    var useDynamicCR = preferences.enableDynamicCR;
-    const minLimitChris = profile.autosens_min;
-    const maxLimitChris = profile.autosens_max;
-    const adjustmentFactor = preferences.adjustmentFactor;
-    const currentMinTarget = profile.min_bg;
-    var exerciseSetting = false;
-    var pumpData = 0;
-    var log = "";
-    var logTDD = "";
-    var logBasal = "";
-    var logBolus = "";
-    var logTempBasal = "";
-    var dataLog = "";
-    var logOutPut = "";
-    var current = 0;
-    var TDD = 0;
-    var insulin = 0;
-    var tempInsulin = 0;
-    var bolusInsulin = 0;
-    var scheduledBasalInsulin = 0;
-    var quota = 0;
-    
-    function round(value, precision) {
-        var multiplier = Math.pow(10, precision || 0);
-        return Math.round(value * multiplier) / multiplier;
-    }
-    
-    function addTimeToDate(objDate, _hours) {
-        var ms = objDate.getTime();
-        var add_ms = _hours * 36e5;
-        var newDateObj = new Date(ms + add_ms);
-        return newDateObj;
-    }
-      
-    function subtractTimeFromDate(date, hours_) {
-        var ms_ = date.getTime();
-        var add_ms_ = hours_ * 36e5;
-        var new_date = new Date(ms_ - add_ms_);
-        return new_date;
-    }
-    
-    function accountForIncrements(insulin) {
-        // If you have not set this to 0.05 in FAX settings (Omnipod), this will be set to 0.1 (Medtronic) in code.
-        var minimalDose = profile.bolus_increment;
-        if (minimalDose != 0.05) {
-            minimalDose = 0.1;
-        }
-        var incrementsRaw = insulin / minimalDose;
-        if (incrementsRaw >= 1) {
-            var incrementsRounded = Math.floor(incrementsRaw);
-            return round(incrementsRounded * minimalDose, 5);
-        } else { return 0; }
-    }
-
-    function makeBaseString(base_timeStamp) {
-        function addZero(i) {
-            if (i < 10) {i = "0" + i}
-            return i;
-        }
-        let hour = addZero(base_timeStamp.getHours());
-        let minutes = addZero(base_timeStamp.getMinutes());
-        let seconds = "00";
-        let string = hour + ":" + minutes + ":" + seconds;
-        return string;
-    }
-       
-    function timeDifferenceOfString(string1, string2) {
-        //Base time strings are in "00:00:00" format
-        var time1 = new Date("1/1/1999 " + string1);
-        var time2 = new Date("1/1/1999 " + string2);
-        var ms1 = time1.getTime();
-        var ms2 = time2.getTime();
-        var difference = (ms1 - ms2) / 36e5;
-        return difference;
-    }
-
-    function calcScheduledBasalInsulin(lastRealTempTime, addedLastTempTime) {
-        var totalInsulin = 0;
-        var old = addedLastTempTime;
-        var totalDuration = (lastRealTempTime - addedLastTempTime) / 36e5;
-        var basDuration = 0;
-        var totalDurationCheck = totalDuration;
-        var durationCurrentSchedule = 0;
-        
-        do {
-
-            if (totalDuration > 0) {
-                
-                var baseTime_ = makeBaseString(old);
-                
-                //Default basalrate in case none is found...
-                var basalScheduledRate_ = basalProfile[0].start;
-                for (let m = 0; m < basalProfile.length; m++) {
-                    
-                    var timeToTest = basalProfile[m].start;
-                    
-                    if (baseTime_ == timeToTest) {
-                        
-                        if (m + 1 < basalProfile.length) {
-                            let end = basalProfile[m+1].start;
-                            let start = basalProfile[m].start;
-                                                        
-                            durationCurrentSchedule = timeDifferenceOfString(end, start);
-                            
-                            if (totalDuration >= durationCurrentSchedule) {
-                                basDuration = durationCurrentSchedule;
-                            } else if (totalDuration < durationCurrentSchedule) {
-                                basDuration = totalDuration;
-                            }
-                            
-                        }
-                        else if (m + 1 == basalProfile.length) {
-                            let end = basalProfile[0].start;
-                            let start = basalProfile[m].start;
-                            // First schedule is 00:00:00. Changed places of start and end here.
-                            durationCurrentSchedule = 24 - (timeDifferenceOfString(start, end));
-                            
-                            if (totalDuration >= durationCurrentSchedule) {
-                                basDuration = durationCurrentSchedule;
-                            } else if (totalDuration < durationCurrentSchedule) {
-                                basDuration = totalDuration;
-                            }
-                        
-                        }
-                        basalScheduledRate_ = basalProfile[m].rate;
-                        totalInsulin += accountForIncrements(basalScheduledRate_ * basDuration);
-                        totalDuration -= basDuration;
-                        console.log("Dynamic ratios log: scheduled insulin added: " + accountForIncrements(basalScheduledRate_ * basDuration) + " U. Bas duration: " + basDuration.toPrecision(3) + " h. Base Rate: " + basalScheduledRate_ + " U/h" + ". Time :" + baseTime_);
-                        // Move clock to new date
-                        old = addTimeToDate(old, basDuration);
-                    }
-                    
-                    else if (baseTime_ > timeToTest) {
-
-                        if (m + 1 < basalProfile.length) {
-                            var timeToTest2 = basalProfile[m+1].start
-                         
-                            if (baseTime_ < timeToTest2) {
-                                
-                               //  durationCurrentSchedule = timeDifferenceOfString(end, start);
-                               durationCurrentSchedule = timeDifferenceOfString(timeToTest2, baseTime_);
-                            
-                                if (totalDuration >= durationCurrentSchedule) {
-                                    basDuration = durationCurrentSchedule;
-                                } else if (totalDuration < durationCurrentSchedule) {
-                                    basDuration = totalDuration;
-                                }
-                                 
-                                basalScheduledRate_ = basalProfile[m].rate;
-                                totalInsulin += accountForIncrements(basalScheduledRate_ * basDuration);
-                                totalDuration -= basDuration;
-                                console.log("Dynamic ratios log: scheduled insulin added: " + accountForIncrements(basalScheduledRate_ * basDuration) + " U. Bas duration: " + basDuration.toPrecision(3) + " h. Base Rate: " + basalScheduledRate_ + " U/h" + ". Time :" + baseTime_);
-                                // Move clock to new date
-                                old = addTimeToDate(old, basDuration);
-                            }
-                        }
-                    
-                        else if (m == basalProfile.length - 1) {
-                            // let start = basalProfile[m].start;
-                            let start = baseTime_;
-                            // First schedule is 00:00:00. Changed places of start and end here.
-                            durationCurrentSchedule = timeDifferenceOfString("23:59:59", start);
-                            
-                            if (totalDuration >= durationCurrentSchedule) {
-                                basDuration = durationCurrentSchedule;
-                            } else if (totalDuration < durationCurrentSchedule) {
-                                basDuration = totalDuration;
-                            }
-                            
-                            basalScheduledRate_ = basalProfile[m].rate;
-                            totalInsulin += accountForIncrements(basalScheduledRate_ * basDuration);
-                            totalDuration -= basDuration;
-                            console.log("Dynamic ratios log: scheduled insulin added: " + accountForIncrements(basalScheduledRate_ * basDuration) + " U. Bas duration: " + basDuration.toPrecision(3) + " h. Base Rate: " + basalScheduledRate_ + " U/h" + ". Time :" + baseTime_);
-                            // Move clock to new date
-                            old = addTimeToDate(old, basDuration);
-                        }
-                    }
-                }
-            }
-            //totalDurationCheck to avoid infinite loop
-        } while (totalDuration > 0 && totalDuration < totalDurationCheck);
-        
-        // amount of insulin according to pump basal rate schedules
-        return totalInsulin;
-    }
-    //------------- End of added functions ----------------------------------------------------
-    
-    if (profile.high_temptarget_raises_sensitivity == true || profile.exercise_mode == true) {
-        exerciseSetting = true;
-    }
-    
-    // Turns off Auto-ISF when using Dynamic ISF.
-    if (profile.use_autoisf == true && chrisFormula == true) {
-        profile.use_autoisf = false;
-    }
-    
-    // Turn off Chris' formula (and AutoISF) when using a temp target >= 118 (6.5 mol/l) and if an exercise setting is enabled.
-    if (currentMinTarget >= 118 && exerciseSetting == true) {
-        profile.use_autoisf = false;
-        chrisFormula = false;
-        log = "Dynamic ISF temporarily off due to a high temp target/exercising. Current min target: " + currentMinTarget;
-    }
-    
-    // Check that there is enough pump history data (>23.5 hours) for TDD calculation, else estimate a TDD using using missing hours with scheduled basal rates.
-    if (chrisFormula == true) {
-        let ph_length = pumphistory.length;
-        var endDate = new Date(pumphistory[ph_length-1].timestamp);
-        var startDate = new Date(pumphistory[0].timestamp);
-        // If latest pump event is a temp basal
-        if (pumphistory[0]._type == "TempBasalDuration") {
-            startDate = new Date();
-        }
-        pumpData = (startDate - endDate) / 36e5;
-        
-        if (pumpData < 23.5) {
-            var missingHours = 24 - pumpData;
-            // Makes new end date for a total time duration of exakt 24 hour.
-            var endDate_ = subtractTimeFromDate(endDate, missingHours);
-            // endDate - endDate_ = missingHours
-            scheduledBasalInsulin = calcScheduledBasalInsulin(endDate, endDate_);
-            dataLog = "24 hours of data is required for an accurate TDD calculation. Currently only " + pumpData.toPrecision(3) + " hours of pump history data are available. Using your pump scheduled basals to fill in the missing hours. Scheduled basals added: " + scheduledBasalInsulin.toPrecision(5) + " U. ";
-        } else { dataLog = ""; }
-    }
-    
-    // Calculate TDD --------------------------------------
-    //Bolus:
-    for (let i = 0; i < pumphistory.length; i++) {
-        if (pumphistory[i]._type == "Bolus") {
-            bolusInsulin += pumphistory[i].amount;
-        }
-    }
-    
-    // Temp basals:
-    for (let j = 1; j < pumphistory.length; j++) {
-        if (pumphistory[j]._type == "TempBasal" && pumphistory[j].rate > 0) {
-            current = j;
-            quota = pumphistory[j].rate;
-            var duration = pumphistory[j-1]['duration (min)'] / 60;
-            var origDur = duration;
-            var pastTime = new Date(pumphistory[j-1].timestamp);
-            // If temp basal hasn't yet ended, use now as end date for calculation
-            do {
-                j--;
-                if (j <= 0) {
-                    morePresentTime =  new Date();
-                    break;
-                } else if (pumphistory[j]._type == "TempBasal" || pumphistory[j]._type == "PumpSuspend") {
-                        morePresentTime = new Date(pumphistory[j].timestamp);
-                        break;
-                  }
-            }
-            while (j >= 0);
-            
-            var diff = (morePresentTime - pastTime) / 36e5;
-            if (diff < origDur) {
-                duration = diff;
-            }
-            
-            insulin = quota * duration;
-            tempInsulin += accountForIncrements(insulin);
-            j = current;
-        }
-    }
-    //  Check and count for when basals are delivered with a scheduled basal rate or an Autotuned basal rate.
-    //  1. Check for 0 temp basals with 0 min duration. This is for when ending a manual temp basal and (perhaps) continuing in open loop for a while.
-    //  2. Check for temp basals that completes. This is for when disconnected from link/iphone, or when in open loop.
-    //  3. Account for a punp suspension. This is for when pod screams or when MDT or pod is manually suspended.
-    //  4. Account for a pump resume (in case pump/cgm is disconnected before next loop).
-    //  To do: are there more circumstances when scheduled basal rates are used?
-    //
-    for (let k = 0; k < pumphistory.length; k++) {
-        // Check for 0 temp basals with 0 min duration.
-        insulin = 0;
-        if (pumphistory[k]['duration (min)'] == 0 || pumphistory[k]._type == "PumpResume") {
-            let time1 = new Date(pumphistory[k].timestamp);
-            let time2 = time1;
-            let l = k;
-            do {
-                --l;
-                if (pumphistory[l]._type == "TempBasal" && l >= 0) {
-                    time2 = new Date(pumphistory[l].timestamp);
-                    break;
-                }
-            } while (l > 0);
-            // duration of current scheduled basal in h
-            let basDuration = (time2 - time1) / 36e5;
-           
-            if (basDuration > 0) {
-                scheduledBasalInsulin += calcScheduledBasalInsulin(time2, time1);
-            }
-        }
-    }
-    
-    // Check for temp basals that completes
-    for (let n = pumphistory.length -1; n > 0; n--) {
-        if (pumphistory[n]._type == "TempBasalDuration") {
-            // duration in hours
-            let oldBasalDuration = pumphistory[n]['duration (min)'] / 60;
-            // time of old temp basal
-            let oldTime = new Date(pumphistory[n].timestamp);
-                        
-            var newTime = oldTime;
-            let o = n;
-            do {
-                --o;
-                if (o >= 0) {
-                    if (pumphistory[o]._type == "TempBasal" || pumphistory[o]._type == "PumpSuspend") {
-                        // time of next (new) temp basal or a pump suspension
-                        newTime = new Date(pumphistory[o].timestamp);
-                        break;
-                    }
-                }
-            } while (o > 0);
-            
-            // When latest temp basal is index 0 in pump history
-            if (n == 0 && pumphistory[0]._type == "TempBasalDuration") {
-                newTime = new Date();
-                oldBasalDuration = pumphistory[n]['duration (min)'] / 60;
-            }
-            
-            let tempBasalTimeDifference = (newTime - oldTime) / 36e5;
-            let timeOfbasal = tempBasalTimeDifference - oldBasalDuration;
-            
-            // if duration of scheduled basal is more than 0
-            if (timeOfbasal > 0) {
-
-                // Timestamp after completed temp basal
-                let timeOfScheduledBasal =  addTimeToDate(oldTime, oldBasalDuration);
-                scheduledBasalInsulin += calcScheduledBasalInsulin(newTime, timeOfScheduledBasal);
-            }
-        }
-    }
-    
-    // ----------------------------------------------------
-
-    TDD = bolusInsulin + tempInsulin + scheduledBasalInsulin;
-    logBolus = ". Bolus insulin: " + bolusInsulin.toPrecision(5) + " U";
-    logTempBasal = ". Temporary basal insulin: " + tempInsulin.toPrecision(5) + " U";
-    logBasal = ". Insulin with scheduled basal rate: " + scheduledBasalInsulin.toPrecision(5) + " U";
-    logTDD = ". TDD past 24h is: " + TDD.toPrecision(5) + " U";
-    
-    var startLog = "Dynamic ratios log: ";
-    var afLog = "AF: " + adjustmentFactor + ". ";
-    var bgLog = "BG: " + BG + " mg/dl (" + (BG * 0.0555).toPrecision(2) + " mmol/l). ";
-    var formula = "";
-
-    // Insulin curve
-    const curve = preferences.curve;
-    const ipt = preferences.insulinPeakTime;
-    const ucpk = preferences.useCustomPeakTime;
-    var insulinFactor = 55;
-    switch (curve) {
-        case "rapid-acting":
-            insulinFactor = 55;
-            break;
-        case "ultra-rapid":
-            if (ipt < 75 && ucpk == true) {
-                insulinFactor = 120 - ipt;
-            } else { insulinFactor = 70; }
-            break;
-    }
-
-    // Modified Chris Wilson's' formula with added adjustmentFactor for tuning and to use instead of autosens.ratio:
-    // var newRatio = profile.sens * adjustmentFactor * TDD * BG / 277700;
-    //
-    // New logarithmic formula : var newRatio = profile.sens * adjustmentFactor * TDD * ln(( BG/insulinFactor) + 1 )) / 1800
-    //
-    if (preferences.useNewFormula == true) {
-        var newRatio = profile.sens * adjustmentFactor * TDD * Math.log(BG/insulinFactor+1) / 1800;
-        formula = "Logarithmic formula. InsulinFactor: " + insulinFactor + ". ";
-
-    }
-    else {
-        var newRatio = profile.sens * adjustmentFactor * TDD * BG / 277700;
-        formula = "Original formula. ";
-    }
-            
-    var cr = profile.carb_ratio;
-    
-    if (chrisFormula == true && TDD > 0) {
-       
-        // Respect autosens.max and autosens.min limits
-        if (newRatio > maxLimitChris) {
-            log = "Dynamic ISF hit limit by autosens_max setting: " + maxLimitChris + " (" +  newRatio.toPrecision(3) + "), ";
-            newRatio = maxLimitChris;
-        } else if (newRatio < minLimitChris) {
-            log = "Dynamic ISF hit limit by autosens_min setting: " + minLimitChris + " (" +  newRatio.toPrecision(3) + "). ";
-            newRatio = minLimitChris;
-        }
-        
-        // Dynamic CR (Test)
-        if (useDynamicCR == true) {
-            cr = round(cr/newRatio, 2);
-            profile.carb_ratio = cr;
-            var logCR = " Dynamic CR: " + cr + " g/U";
-        } else { var logCR = " CR: " + cr + " g/U"; }
-
-        var isf = profile.sens / newRatio;
-
-        log += "Dynamic autosens.ratio set to " + newRatio.toPrecision(3) + " with ISF: " + isf.toPrecision(3) + " mg/dl/U (" + (isf * 0.0555).toPrecision(3) + " mmol/l/U) and" + logCR;
-
-        // Set the new ratio
-        autosens.ratio = newRatio;
-
-        
-        logOutPut = startLog + dataLog + bgLog + afLog + formula + log + logTDD + logBolus + logTempBasal + logBasal;
-    } else if (chrisFormula == false && useDynamicCR == true) {
-        logOutPut = startLog + bgLog + afLog + formula + "Dynamic ISF is off." + logCR;
-    } else {
-        logOutPut = startLog + "Dynamic ISF is off. Dynamic CR is off." ;
-    }
-
-    return logOutPut;
-
+function middleware(iob, currenttemp, glucose, profile, autosens, meal, reservoir, clock) {
+    // modify anything
+    // return any reason what has changed.
+    return "Nothing changed";
 }

+ 14 - 2
FreeAPS/Resources/javascript/prepare/determine-basal.js

@@ -16,6 +16,7 @@ function generate(iob, currenttemp, glucose, profile, autosens = null, meal = nu
     if (autosens) {
         autosens_data = autosens;
     }
+    
 
     var reservoir_data = null;
     if (reservoir) {
@@ -26,6 +27,17 @@ function generate(iob, currenttemp, glucose, profile, autosens = null, meal = nu
     if (meal) {
         meal_data = meal;
     }
-
-    return freeaps_determineBasal(glucose_status, currenttemp, iob, profile, autosens_data, meal_data, freeaps_basalSetTemp, microbolusAllowed, reservoir_data, clock);
+    
+    var pumphistory = {};
+    if (pump_history) {
+        pumphistory = pump_history;
+    }
+    
+    var basalprofile = {};
+    if (basalProfile) {
+        basalprofile = basalProfile;
+    }
+    
+    
+    return freeaps_determineBasal(glucose_status, currenttemp, iob, profile, autosens_data, meal_data, freeaps_basalSetTemp, microbolusAllowed, reservoir_data, clock, pumphistory, preferences, basalprofile);
 }

+ 1 - 0
FreeAPS/Sources/APS/OpenAPS/Constants.swift

@@ -54,6 +54,7 @@ extension OpenAPS {
         static let iob = "monitor/iob.json"
         static let cgmState = "monitor/cgm-state.json"
         static let podAge = "monitor/pod-age.json"
+        static let tdd = "monitor/tdd.json"
     }
 
     enum Enact {

+ 1 - 0
FreeAPS/Sources/APS/OpenAPS/OpenAPS.swift

@@ -75,6 +75,7 @@ final class OpenAPS {
                 if var suggestion = Suggestion(from: suggested) {
                     suggestion.timestamp = suggestion.deliverAt ?? clock
                     self.storage.save(suggestion, as: Enact.suggested)
+
                     promise(.success(suggestion))
                 } else {
                     promise(.success(nil))

+ 1 - 1
FreeAPS/Sources/Models/Suggestion.swift

@@ -49,7 +49,7 @@ extension Suggestion {
         case timestamp
         case recieved
         case isf = "ISF"
-        case tdd
+        case tdd = "TDD"
     }
 }
 

+ 6 - 0
FreeAPS/Sources/Models/TDD.swift

@@ -0,0 +1,6 @@
+import Foundation
+
+struct TDD: JSON {
+    let tdd: Decimal
+    var timestamp: Date
+}

+ 3 - 2
FreeAPS/Sources/Views/TagCloudView.swift

@@ -63,9 +63,10 @@ struct TagCloudView: View {
             case textTag where textTag.contains("Parabolic Fit"):
                 return .loopRed
             case textTag where textTag.contains("TDD:"),
-                 textTag where textTag.contains("Formula:"),
+                 textTag where textTag.contains("Original formula"),
+                 textTag where textTag.contains("Logarithmic formula"),
                  textTag where textTag.contains("AF:"),
-                 textTag where textTag.contains("Dynamic "):
+                 textTag where textTag.contains("Dynamic ISF/CR"):
                 return .zt
             default:
                 return .insulin