From 26102848f5304875df88aec7d80fb535c70e7f11 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 4 Jan 2017 23:03:13 +0100 Subject: [PATCH] refactor MealData --- .../nightscout/androidaps/data/MealData.java | 23 +++++++++++++++++++ .../plugins/Treatments/TreatmentsPlugin.java | 15 +----------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/data/MealData.java b/app/src/main/java/info/nightscout/androidaps/data/MealData.java index 02db574a54..9b258dda0e 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/MealData.java +++ b/app/src/main/java/info/nightscout/androidaps/data/MealData.java @@ -1,5 +1,11 @@ package info.nightscout.androidaps.data; +import java.util.Date; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.db.Treatment; +import info.nightscout.client.data.NSProfile; + /** * Created by mike on 04.01.2017. */ @@ -7,4 +13,21 @@ public class MealData { public double boluses = 0d; public double carbs = 0d; public double mealCOB = 0.0d; // TODO: add calculation for AMA + + public void addTreatment(Treatment treatment) { + NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile(); + if (profile == null) return; + + long now = new Date().getTime(); + long dia_ago = now - (new Double(profile.getDia() * 60 * 60 * 1000l)).longValue(); + long t = treatment.created_at.getTime(); + if (t > dia_ago && t <= now) { + if (treatment.carbs >= 1) { + carbs += treatment.carbs; + } + if (treatment.insulin > 0 && treatment.mealBolus) { + boluses += treatment.insulin; + } + } + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java index 874c19820d..9a29cc837b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java @@ -142,22 +142,9 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface { @Override public MealData getMealData() { MealData result = new MealData(); - NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile(); - if (profile == null) - return result; for (Treatment treatment : treatments) { - long now = new Date().getTime(); - long dia_ago = now - (new Double(profile.getDia() * 60 * 60 * 1000l)).longValue(); - long t = treatment.created_at.getTime(); - if (t > dia_ago && t <= now) { - if (treatment.carbs >= 1) { - result.carbs += treatment.carbs; - } - if (treatment.insulin >= 0.1 && treatment.mealBolus) { - result.boluses += treatment.insulin; - } - } + result.addTreatment(treatment); } return result; }