Fixed issue 33 where confidence index was throwing off the average calculations
This commit is contained in:
parent
e4ceb609be
commit
5df0bd1f28
3 changed files with 14 additions and 5 deletions
BIN
hal-default.db
BIN
hal-default.db
Binary file not shown.
|
|
@ -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{
|
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;
|
float data = -1;
|
||||||
switch(aggrMethod){
|
switch(aggrMethod){
|
||||||
case SUM: data = sum; break;
|
case SUM:
|
||||||
case AVERAGE: data = sum/samples; break;
|
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(1, sensorId);
|
||||||
preparedInsertStmt.setLong(2, sequenceId);
|
preparedInsertStmt.setLong(2, sequenceId);
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package se.hal.util;
|
||||||
|
|
||||||
import se.hal.deamon.SensorDataAggregatorDaemon.AggregationPeriodLength;
|
import se.hal.deamon.SensorDataAggregatorDaemon.AggregationPeriodLength;
|
||||||
import se.hal.struct.Sensor;
|
import se.hal.struct.Sensor;
|
||||||
|
import se.hal.struct.devicedata.PowerConsumptionSensorData;
|
||||||
import zutil.db.DBConnection;
|
import zutil.db.DBConnection;
|
||||||
import zutil.db.SQLResultHandler;
|
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, 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
|
// Update previous end timestamp
|
||||||
previousTimestampEnd = timestampEnd;
|
previousTimestampEnd = timestampEnd;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue