From 61cc02cc7fe064c0b6ecd13b17379aef1cde19d8 Mon Sep 17 00:00:00 2001 From: Patrick McDonagh Date: Fri, 10 Feb 2017 13:45:44 -0600 Subject: [PATCH] Fixes Measurement class to gauge-off correctly --- .../java/com/henrypump/poc/Measurement.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/henrypump/poc/Measurement.java b/src/main/java/com/henrypump/poc/Measurement.java index 07230a3..e2f6fdb 100644 --- a/src/main/java/com/henrypump/poc/Measurement.java +++ b/src/main/java/com/henrypump/poc/Measurement.java @@ -107,7 +107,7 @@ public class Measurement { return dailyMin; } - public static boolean isToday(ZonedDateTime inpZDT){ + private static boolean isToday(ZonedDateTime inpZDT){ ZonedDateTime now = ZonedDateTime.now(); if (now.toLocalDate().equals(inpZDT.toLocalDate())){ return true; @@ -115,7 +115,7 @@ public class Measurement { return false; }; - public void update(double value) + void update(double value) { long currentTimestamp = ZonedDateTime.now().toEpochSecond(); lastValue = currentValue; @@ -138,14 +138,13 @@ public class Measurement { } } - public void endOfDay(){ + void endOfDay(){ if (storeInDatabase){ db.newDailyTotal(this); } - for(int i = 28; i >= 0; i--){ - totalHistory[i] = totalHistory[i+1]; - averageHistory[i] = averageHistory[i+1]; - } + + System.arraycopy(totalHistory, 0, totalHistory, 1, totalHistory.length-1); + System.arraycopy(averageHistory, 0, averageHistory, 1, averageHistory.length-1); totalHistory[0] = total; averageHistory[0] = average; @@ -154,8 +153,6 @@ public class Measurement { average = 0; dailyMax = Double.MIN_VALUE; dailyMin = Double.MAX_VALUE; + numMeasurements = 0; } - - - }