From e0c1f65b8b39fa8464a6656d13394a48d18bd2b7 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Mon, 17 Jul 2017 22:37:57 +0200 Subject: [PATCH] wear tdd weighted --- .../plugins/Wear/ActionStringHandler.java | 47 +++++++++++++++++-- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java index c88faad0da..f800d9d531 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java @@ -36,6 +36,7 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.ProfileCircadianPercentage.CircadianPercentageProfilePlugin; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes; import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin; @@ -329,16 +330,52 @@ public class ActionStringHandler { private static String generateTDDMessage(List historyList, List dummies) { DateFormat df = new SimpleDateFormat("dd.MM."); - String message = "TDD:\n"; + String message = ""; - //TODO: if CPP add weighted - message += "\n\n"; + CircadianPercentageProfilePlugin cpp = (CircadianPercentageProfilePlugin) MainApp.getSpecificPlugin(CircadianPercentageProfilePlugin.class); + boolean isCPP = (cpp!= null && cpp.isEnabled(PluginBase.PROFILE)); + double refTDD = 100; + if(isCPP) refTDD = cpp.baseBasalSum()*2; + int i = 0; + double sum = 0d; + double weighted03 = 0d; + double weighted05 = 0d; + double weighted07 = 0d; - //add TDDs: + Collections.reverse(historyList); for (DanaRHistoryRecord record : historyList) { double tdd = record.recordDailyBolus + record.recordDailyBasal; - message += df.format(new Date(record.recordDate)) + " " + DecimalFormatter.to2Decimal(tdd) +"U" + (dummies.contains(record)?"x":"") +"\n"; + if (i == 0) { + weighted03 = tdd; + weighted05 = tdd; + weighted07 = tdd; + + } else { + weighted07 = (weighted07 * 0.3 + tdd * 0.7); + weighted05 = (weighted05 * 0.5 + tdd * 0.5); + weighted03 = (weighted03 * 0.7 + tdd * 0.3); + } + i++; + } + message += "weighted:\n"; + message += "0.3: " + DecimalFormatter.to2Decimal(weighted03) + "U " + (isCPP?(DecimalFormatter.to0Decimal(100*weighted03/refTDD) + "%"):"") + "\n"; + message += "0.5: " + DecimalFormatter.to2Decimal(weighted05) + "U " + (isCPP?(DecimalFormatter.to0Decimal(100*weighted05/refTDD) + "%"):"") + "\n"; + message += "0.7: " + DecimalFormatter.to2Decimal(weighted07) + "U " + (isCPP?(DecimalFormatter.to0Decimal(100*weighted07/refTDD) + "%"):"") + "\n"; + message += "\n"; + + PumpInterface pump = MainApp.getConfigBuilder().getActivePump(); + if (pump != null && pump instanceof DanaRPlugin) { + double tdd = DanaRPump.getInstance().dailyTotalUnits; + message += "Today: " + DecimalFormatter.to2Decimal(tdd) + "U " + (isCPP?(DecimalFormatter.to0Decimal(100*tdd/refTDD) + "%"):"") + "\n"; + message += "\n"; + } + + //add TDDs: + Collections.reverse(historyList); + for (DanaRHistoryRecord record : historyList) { + double tdd = record.recordDailyBolus + record.recordDailyBasal; + message += df.format(new Date(record.recordDate)) + " " + DecimalFormatter.to2Decimal(tdd) +"U " + (isCPP?(DecimalFormatter.to0Decimal(100*tdd/refTDD) + "%"):"") + (dummies.contains(record)?"x":"") +"\n"; } return message; }