public class AverageSensor extends WeatherSensor implements SensorDepending
CumulativeSensor.KEY_AVERAGE) sensors and returns the average reading. Depending
on KEY_OFFSET all readings that are more than this value relatively
off the average are discarded. Additionally, readings below or equal
KEY_MINTHRESHOLD and readings above or equal
KEY_MAXTHRESHOLD are discarded.TimerTaskSensor.SensorReadPropertyResources.Load, PropertyResources.URLResource| Modifier and Type | Field and Description |
|---|---|
private BufferedWriter |
allsensors
Write out individual sensor readings.
|
private Map<Telemetering,Double> |
average
The list of registered sensors that are used for averaging.
|
private static int |
DEFREPORTLOGMS |
static String |
KEY_AVERAGEOF
The list of the sensor names that are used for averaging.
|
static String |
KEY_DEBUGHEAD
First line to write to debug log.
|
static String |
KEY_DEBUGLOG
The log file to write individual sensors, debugging mainly.
|
static String |
KEY_MAXTHRESHOLD
The maximum value that is considered valid of an individual sensor.
|
static String |
KEY_MINTHRESHOLD
The minimum value that is considered valid of an individual sensor.
|
static String |
KEY_OFFSET
The maximum offset allowed.
|
static String |
KEY_REPORTLOGMS
Re-report after this time-out.
|
static String |
KEY_TRUSTED
If variance test fails, only use trusted sensors.
|
static String |
KEY_VARIANCE
If the variance exceeds this sigma-value, use only trusted sensors.
|
static String |
MAXIMUM |
static String |
MINIMUM |
private List<String> |
names
The list of names of the sensors that should be averaged.
|
private double |
wasread
Caches the last valid value.
|
private Date |
wasreport
Reporting toggle.
|
private boolean |
wasvalid
Gets true after startup and a first successful average calculation.
|
KEY_DERIVATIVEINVALID, KEY_DERIVATIVEPARAMETER, KEY_INVERSE, KEY_INVERSEDERIVATIVE, KEY_JUDGEDERIVATIVE, KEY_JUDGEPREDICT, KEY_JUDGERAW, KEY_JUDGESMOOTH, KEY_PREDICTINVALID, KEY_PREDICTPARAMETER, KEY_RAWINVALID, KEY_RAWPARAMETER, KEY_RETARDBADDERIVATIVE, KEY_RETARDBADPREDICT, KEY_RETARDBADRAW, KEY_RETARDBADSMOOTH, KEY_RETARDGOODDERIVATIVE, KEY_RETARDGOODPREDICT, KEY_RETARDGOODRAW, KEY_RETARDGOODSMOOTH, KEY_SMOOTHINVALID, KEY_SMOOTHPARAMETERDEFRAWDERIVATIVE, derive, KEY_DERIVATIVEADVISE, KEY_DERIVE, KEY_PATH, KEY_RAWDERIVATIVE, zf, g, KEY_SMOOTH, KEY_SMOOTHADVISEKEY_CHI, KEY_EXTRAPOLATE, KEY_FUTURE, KEY_PREDICTADVISE, predictKEY_AVERAGE, KEY_MEMORY, KEY_PACKDEFRAWFORMAT, DEFREPORT, DEFSIGMAFORMAT, KEY_RAWFORMAT, KEY_REPORT, KEY_SIGMAFORMATKEY_LOGRAWABOVE, KEY_LOGRAWBELOW, KEY_LOGREADLAG, KEY_RESPAWNKEY_BIND, KEY_BINDNAME, KEY_CONVERT, KEY_DESCRIPTION, KEY_SENSORNAMEALTERNATEHOST, ALTERNATEPORT, KEY_EXPORTPORT, KEY_REGISTRYHOST, KEY_REGISTRYPORTKEY_NOINITONCREATE, POSTFIX_ALPHABET, POSTFIX_BYTES, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_MODTIME, POSTFIX_URLKEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATORNAMING_EXTENSIONCONFIG, KEY_CLASSKEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME| Constructor and Description |
|---|
AverageSensor(Map<String,String> prop)
Constructs a new averaging sensor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
exit()
Close the all-sensors log file if present.
|
private double |
getAverage()
Calculates the average of the values mapped in the look-up table in a
recursive way.
|
String |
getSensorInitInfo()
Returns the names of the sensors we use for averaging plus the super
information.
|
void |
init()
If we have a log file to append to, this is opened here.
|
private void |
openAverageLog()
Opens the average sensor log file in append mode.
|
protected double |
readSensor()
Reads the averaging sensor.
|
void |
registerSensor(Telemetering add)
Adds sensor to this averaging sensor.
|
private boolean |
removeMinMax() |
private boolean |
removeOffset(double av)
Removes all sensors that are above a certain offset.
|
private boolean |
removeVariance(double av,
double var) |
boolean |
validReading()
Returns true if the reading of this averaging sensor is true.
|
private void |
writeLog(List<String> sensors,
Map<Telemetering,Double> read)
For all named sensors in the sensors list, we write their current reading
into the open allsensor log file.
|
addWeatherListener, conductOneMeasure, currentlyClear, currentlyRetarding, generateDataEvent, getMinClearUpTime, goodFromDerivative, goodFromPredict, goodFromRaw, goodFromSmooth, isDerivativeRetard, isPredictRetard, isRawRetard, isSmoothRetard, judgeWeather, notifyWeatherListener, removeWeatherListener, statusderiveAt, getDerivativeFormat, getDerivativeToggleInfo, getDerivator, getLastDerivative, isDerivativeAdvise, isDeriving, newData, regetDerive, registerDerivatorgetLastSmooth, getSmoother, getSmoothToggleInfo, isSmoothAdvise, isSmoothing, regetSmooth, registerSmoother, smoothOnegetExtrapolation, getLastPredict, getPredictToggleInfo, isPredictAdvise, isPredicting, isReliable, predictFrom, regetPredictcumulateOne, getLastRaw, getLastTime, getMaxSize, getMemory, getSizeaddDataListener, addRmiDataListener, getRawFormat, getSigmaFormat, removeDataListener, removeRmiDataListener, reportcancel, equals, getRawToggleInfo, getReading, getRespawn, getTimeOfRead, hashCode, initSensorTimerTask, isReady, regetRaw, setTimeOfRead, validReadingaddRmiErrorListener, createSensor, getBindName, getConvert, getSensorDescription, getSensorName, notifyErrorListener, removeRmiErrorListener, setConvert, toStringbindToRegistry, bindToRegistry, bindToRegistry, bindToRegistry, bindToRegistry, bindToRegistry, casterExit, casterExit, getBindName, isValid, unbindFromRegistry, unbindFromRegistrycontainsRemoteProperty, getRemoteProperties, getRemoteProperty, setRemotePropertyclone, createFrom, createFrom, createFrom, createInstance, getApplet, getAsResources, getLocate, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, hasLocalURLs, initProperties, keyCreate, keyCreate, reload, setAppletaugment, augment, augment, augment, augment, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, isNew, parseObject, parseObject, reload, removeProperty, requires, rescanned, setObject, setProperties, setProperty, stringPropertiesfinalize, getClass, notify, notifyAll, wait, wait, waitcumulateOne, getLastRaw, getLastTime, getMaxSize, getSize, getTimeOfRead, regetRawbindToRegistry, isValid, unbindFromRegistrydefaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, parseObject, removeProperty, setObject, setProperty, stringPropertiespublic static final String MAXIMUM
public static final String MINIMUM
public static final String KEY_AVERAGEOF
public static final String KEY_OFFSET
public static final String KEY_VARIANCE
public static final String KEY_TRUSTED
public static final String KEY_MINTHRESHOLD
public static final String KEY_MAXTHRESHOLD
public static final String KEY_DEBUGLOG
public static final String KEY_DEBUGHEAD
public static final String KEY_REPORTLOGMS
private static final int DEFREPORTLOGMS
private final Map<Telemetering,Double> average
private boolean wasvalid
private double wasread
private Date wasreport
private BufferedWriter allsensors
public AverageSensor(Map<String,String> prop) throws RemoteException
KEY_OFFSET, the KEY_MINTHRESHOLD,
and the KEY_MAXTHRESHOLD are not defined, no exclusion of
readings is done.RemoteExceptionpublic void init()
throws InitException
init in interface Initializableinit in class PredictiveSensorInitExceptionpublic void exit()
exit in interface ExitCleaningexit in class DataSensorprivate void openAverageLog()
throws IOException
IOExceptionpublic void registerSensor(Telemetering add)
Telemetering
instance's name is found in the KEY_AVERAGEOF list, this sensor
is added to the sensors average map.registerSensor in interface SensorDependingpublic boolean validReading()
validReading in interface Telemeteringpublic String getSensorInitInfo()
getSensorInitInfo in interface TelemeteringgetSensorInitInfo in class WeatherSensorprotected double readSensor()
average, their readings are updated and used for averaging.readSensor in class TimerTaskSensorConvertToPhysicalprivate void writeLog(List<String> sensors, Map<Telemetering,Double> read)
sensors - read - private double getAverage()
KEY_OFFSET
key is given, all values are then again traversed and all values
outside the relative offset are discarded. If at least one value has
been discarded, the averaging is started again.private boolean removeOffset(double av)
av - private boolean removeVariance(double av,
double var)
private boolean removeMinMax()