Fixes issue of measurements not storing
seconds to store were being multiplied by 1000
This commit is contained in:
@@ -22,14 +22,13 @@ public class Measurement {
|
||||
private double[] totalHistory = new double[30];
|
||||
private double[] averageHistory = new double[30];
|
||||
private long numMeasurements;
|
||||
private boolean storeInDatabase;
|
||||
private double lastSentValue;
|
||||
private double sendDelta;
|
||||
private Database db;
|
||||
private long lastSentTimestamp;
|
||||
private long sendTimeDelta;
|
||||
|
||||
Measurement(String tagName, boolean storeInDatabase, Database db, double sendDelta, long sendTimeDelta){
|
||||
Measurement(String tagName, Database db, double sendDelta, long sendTimeDelta){
|
||||
this.tagName = tagName;
|
||||
average = 0;
|
||||
total = 0;
|
||||
@@ -38,7 +37,6 @@ public class Measurement {
|
||||
dailyMin = Double.MAX_VALUE;
|
||||
|
||||
// Database code
|
||||
this.storeInDatabase = storeInDatabase;
|
||||
this.db = db;
|
||||
this.sendDelta = sendDelta;
|
||||
this.lastSentValue = 0.0;
|
||||
@@ -67,17 +65,17 @@ public class Measurement {
|
||||
|
||||
}
|
||||
|
||||
Measurement(String tagName, boolean storeInDatabase){
|
||||
this.tagName = tagName;
|
||||
average = 0;
|
||||
total = 0;
|
||||
numMeasurements = 0;
|
||||
dailyMax = Double.MIN_VALUE;
|
||||
dailyMin = Double.MAX_VALUE;
|
||||
|
||||
// Database code
|
||||
this.storeInDatabase = storeInDatabase;
|
||||
}
|
||||
// Measurement(String tagName, boolean storeInDatabase){
|
||||
// this.tagName = tagName;
|
||||
// average = 0;
|
||||
// total = 0;
|
||||
// numMeasurements = 0;
|
||||
// dailyMax = Double.MIN_VALUE;
|
||||
// dailyMin = Double.MAX_VALUE;
|
||||
//
|
||||
// // Database code
|
||||
// this.storeInDatabase = storeInDatabase;
|
||||
// }
|
||||
|
||||
public double getCurrentValue() {
|
||||
return currentValue;
|
||||
@@ -132,21 +130,15 @@ public class Measurement {
|
||||
dailyMax = Math.max(dailyMax, currentValue);
|
||||
dailyMin = Math.min(dailyMin, currentValue);
|
||||
|
||||
if(storeInDatabase){
|
||||
if(abs(currentValue - lastSentValue) > sendDelta ||
|
||||
currentTimestamp - lastSentTimestamp > (sendTimeDelta * 1000)){
|
||||
long l = db.newMeasurement(this);
|
||||
lastSentValue = currentValue;
|
||||
lastSentTimestamp = currentTimestamp;
|
||||
}
|
||||
if(abs(currentValue - lastSentValue) > sendDelta || (currentTimestamp - lastSentTimestamp) > (sendTimeDelta)){
|
||||
long l = db.newMeasurement(this);
|
||||
lastSentValue = currentValue;
|
||||
lastSentTimestamp = currentTimestamp;
|
||||
}
|
||||
}
|
||||
|
||||
void endOfDay(){
|
||||
if (storeInDatabase){
|
||||
db.newDailyTotal(this);
|
||||
}
|
||||
|
||||
db.newDailyTotal(this);
|
||||
System.arraycopy(totalHistory, 0, totalHistory, 1, totalHistory.length-1);
|
||||
System.arraycopy(averageHistory, 0, averageHistory, 1, averageHistory.length-1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user