From 68acc3aca34e31f799e915dea4f6fdd1cb8a4fa6 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Sat, 12 Nov 2016 13:02:50 +0100 Subject: [PATCH 1/2] deltas per 5 minutes --- .../info/nightscout/androidaps/db/DatabaseHelper.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index e929cb56e8..cadb957e1d 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -291,7 +291,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return null; } - int minutes = 5; + long minutes = 5; double change; double avg; @@ -301,13 +301,13 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { BgReading last1 = bgReadings.get(sizeRecords - 2); BgReading last2 = bgReadings.get(sizeRecords - 1); if (last2.value > 30) { - minutes = 3 * 5; + minutes = (now.timeIndex - last2.timeIndex)/(60*1000); change = now.value - last2.value; } else if (last1.value > 30) { - minutes = 2 * 5; + minutes = (now.timeIndex - last1.timeIndex)/(60*1000);; change = now.value - last1.value; } else if (last.value > 30) { - minutes = 5; + minutes = (now.timeIndex - last.timeIndex)/(60*1000); change = now.value - last.value; } else { change = 0; @@ -316,7 +316,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { avg = change / minutes * 5; result.glucose = now.value; - result.delta = now.value - last.value; + result.delta = (now.value - last.value)*5*60*1000/(now.getTimeIndex() - last.getTimeIndex()); result.avgdelta = avg; } } catch (SQLException e) { From 12fc454fe16e2016d58e267b7e4d22189eaa0ff2 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Sat, 12 Nov 2016 13:10:19 +0100 Subject: [PATCH 2/2] divisions with doubles to not do whole minute jumps --- .../info/nightscout/androidaps/db/DatabaseHelper.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index cadb957e1d..b32592b594 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -291,7 +291,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return null; } - long minutes = 5; + double minutes = 5; double change; double avg; @@ -301,13 +301,13 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { BgReading last1 = bgReadings.get(sizeRecords - 2); BgReading last2 = bgReadings.get(sizeRecords - 1); if (last2.value > 30) { - minutes = (now.timeIndex - last2.timeIndex)/(60*1000); + minutes = (now.timeIndex - last2.timeIndex)/(60d*1000); change = now.value - last2.value; } else if (last1.value > 30) { - minutes = (now.timeIndex - last1.timeIndex)/(60*1000);; + minutes = (now.timeIndex - last1.timeIndex)/(60d*1000);; change = now.value - last1.value; } else if (last.value > 30) { - minutes = (now.timeIndex - last.timeIndex)/(60*1000); + minutes = (now.timeIndex - last.timeIndex)/(60d*1000); change = now.value - last.value; } else { change = 0;