Fixed issue 33 where confidence index was throwing off the average calculations

This commit is contained in:
Ziver Koc 2016-10-04 21:56:56 +02:00
parent e4ceb609be
commit 5df0bd1f28
3 changed files with 14 additions and 5 deletions

Binary file not shown.

View file

@ -205,13 +205,19 @@ public class SensorDataAggregatorDaemon implements HalDaemon {
}
private void saveData(PreparedStatement preparedInsertStmt, float confidenceSum, float sum, int samples, UTCTimePeriod currentPeriod, long sequenceId) throws SQLException{
float aggrConfidence = confidenceSum / (float)this.expectedSampleCount;
float aggrConfidence = -1;
float data = -1;
switch(aggrMethod){
case SUM: data = sum; break;
case AVERAGE: data = sum/samples; break;
case SUM:
data = sum;
aggrConfidence = confidenceSum / (float)this.expectedSampleCount;
break;
case AVERAGE:
data = sum/samples;
aggrConfidence = 1; // ignore confidence for average
break;
}
logger.finer("saved period: " + currentPeriod + ", data: " + sum + ", confidence: " + aggrConfidence + ", samples: " + samples + ", aggrMethod: " + aggrMethod);
logger.finer("saved period: " + currentPeriod + ", data: " + data + ", confidence: " + aggrConfidence + ", samples: " + samples + ", aggrMethod: " + aggrMethod);
preparedInsertStmt.setLong(1, sensorId);
preparedInsertStmt.setLong(2, sequenceId);

View file

@ -2,6 +2,7 @@ package se.hal.util;
import se.hal.deamon.SensorDataAggregatorDaemon.AggregationPeriodLength;
import se.hal.struct.Sensor;
import se.hal.struct.devicedata.PowerConsumptionSensorData;
import zutil.db.DBConnection;
import zutil.db.SQLResultHandler;
@ -93,7 +94,9 @@ public class AggregateDataListSqlResult implements SQLResultHandler<ArrayList<Ag
list.add(new AggregateData(id, previousTimestampEnd + 1, null /*Float.NaN*/, username));
}
list.add(new AggregateData(id, timestampEnd, (estimatedData/1000f), username)); //add this data point to list
if (sensor.getDeviceConfig().getSensorDataClass() == PowerConsumptionSensorData.class)
estimatedData = (estimatedData/1000f);
list.add(new AggregateData(id, timestampEnd, estimatedData, username)); //add this data point to list
// Update previous end timestamp
previousTimestampEnd = timestampEnd;