stella.sensor
Class CumulativeSensor

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by util.rmi.RmiPropertyContainer
                  extended by util.rmi.AbstractRmiCaster
                      extended by stella.sensor.AbstractSensor
                          extended by stella.sensor.TimerTaskSensor
                              extended by stella.sensor.DataSensor
                                  extended by stella.sensor.CumulativeSensor
All Implemented Interfaces:
Cloneable, Remote, Caster, DataCaster, RmiDataCaster, RmiErrorCaster, Cumulating, Telemetering, ExitCleaning, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying, RmiCaster, RmiPropertyBearing
Direct Known Subclasses:
PredictiveSensor

public abstract class CumulativeSensor
extends DataSensor
implements Cumulating

A cumulative sensor cumulates readings. It uses a Shelf Shelf to store a predefined number of measurements. Further subclasses may use this history to either conduct smoothing, predicting, or judging tasks.
A normal sensor outputs only doubles, at approximately fixed intervalls. To store this in a Shelf, the measurements are converted into Doubles. Additionally, for the sake of completeness, the individual Dates are also stored in a Shelf.

This sensor adds the following properties if they are not set already:

See Also:
Shelf

Nested Class Summary
 
Nested classes/interfaces inherited from class stella.sensor.TimerTaskSensor
TimerTaskSensor.SensorRead
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private static boolean DEFAVERAGE
          Act on average per default.
private static int DEFMEMORY
          The default number of readings to keep, if property is not given.
private static int DEFPACK
          The default number of readings to pack, if property is not given.
static String KEY_AVERAGE
          The name of the key that points to true on average, median if false.
static String KEY_MEMORY
          The key in the Map list referring to the number of measurements to keep.
static String KEY_PACK
          The name of the key for the pack rate in this sensors properties.
private  Shelf<Double> raw
          Stores the raw readings of this sensor.
private  Shelf<Date> time
          Stores the times of the readings.
 
Fields inherited from class stella.sensor.DataSensor
DEFRAWFORMAT, DEFREPORT, DEFSIGMAFORMAT, KEY_RAWFORMAT, KEY_REPORT, KEY_SIGMAFORMAT
 
Fields inherited from class stella.sensor.TimerTaskSensor
KEY_RESPAWN
 
Fields inherited from class stella.sensor.AbstractSensor
KEY_BIND, KEY_BINDNAME, KEY_CONVERT, KEY_DESCRIPTION, KEY_SENSORNAME
 
Fields inherited from class util.rmi.AbstractRmiCaster
ALTERNATEHOST, ALTERNATEPORT, KEY_EXPORTPORT, KEY_REGISTRYHOST, KEY_REGISTRYPORT
 
Fields inherited from class util.PropertyBundles
KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_RESOURCEBUNDLES
 
Fields inherited from class util.PropertyResources
KEY_NOINITONCREATE, localurl, locate, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_URL, urlset
 
Fields inherited from class util.PropertyContainer
KEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR
 
Fields inherited from interface stella.rmi.RmiDataCaster
NAMING_EXTENSION
 
Fields inherited from interface util.PropertySupplying
CONFIG, KEY_CLASS
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Constructor Summary
protected CumulativeSensor(Map<String,String> qualify)
          Constructs a fully-qualified cumulative sensor, with a given size of measurements to keep.
Use of this constructor guarantees that the Map key memory is always set.
 
Method Summary
 void cumulateOne(double r, Date when)
          The interface method for storing one raw data point and its time of measure.
protected  DataEvent generateDataEvent()
          Takes the last sensor reading and produces a CumulativeDataEvent out of it.
 List<Double> getLastRaw(int nr)
          The interface method for retrieving the last nr raw measures.
 List<Date> getLastTime(int nr)
          The interface method for retrieving the last nr measurement times.
 int getMaxSize()
          Returns the maximum number of datas in the data buffer.
 int getMemory()
          Returns the memory property as an Integer.
 int getSize()
          Returns the number of datas in the data buffer.
protected  void newData(double raw, Date time)
          Called as new data is available.
 
Methods inherited from class stella.sensor.DataSensor
addDataListener, addRmiDataListener, conductOneMeasure, exit, getRawFormat, getSigmaFormat, removeDataListener, removeRmiDataListener, report
 
Methods inherited from class stella.sensor.TimerTaskSensor
cancel, equals, getRawToggleInfo, getReading, getRespawn, getTimeOfRead, hashCode, initSensorTimerTask, isReady, readSensor, regetRaw, setTimeOfRead, validReading
 
Methods inherited from class stella.sensor.AbstractSensor
addRmiErrorListener, createSensor, getBindName, getConvert, getSensorDescription, getSensorInitInfo, getSensorName, init, notifyErrorListener, removeRmiErrorListener, setConvert, status, toString
 
Methods inherited from class util.rmi.AbstractRmiCaster
bindAlternate, bindToRegistry, bindToRegistry, bindToRegistry, casterExit, casterExit, getBindName, isValid, unbindFromRegistry, unbindFromRegistry
 
Methods inherited from class util.rmi.RmiPropertyContainer
containsRemoteProperty, getRemoteProperties, getRemoteProperty, setRemoteProperty
 
Methods inherited from class util.PropertyBundles
clone, getLocalized, getLocalized, getLocalizedString, getLocalizedString, loadResource
 
Methods inherited from class util.PropertyResources
createFrom, createFrom, createFrom, getApplet, getAsResources, getLocalClassLoader, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, keyCreate, keyCreate, reload, setApplet
 
Methods inherited from class util.PropertyContainer
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, reload, removeProperty, rescanned, setObject, setProperties, setProperty, stringProperties
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface stella.sensor.Cumulating
getTimeOfRead, regetRaw
 
Methods inherited from interface util.rmi.RmiCaster
bindToRegistry, isValid, unbindFromRegistry
 
Methods inherited from interface stella.sensor.Telemetering
validReading
 
Methods inherited from interface util.PropertySupplying
defaultBoolean, 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, stringProperties
 
Methods inherited from interface util.ResourceSupplying
getResource, getResourceAsStream, getResources
 

Field Detail

KEY_MEMORY

public static final String KEY_MEMORY
The key in the Map list referring to the number of measurements to keep.

See Also:
Constant Field Values

KEY_PACK

public static final String KEY_PACK
The name of the key for the pack rate in this sensors properties.

See Also:
Constant Field Values

KEY_AVERAGE

public static final String KEY_AVERAGE
The name of the key that points to true on average, median if false.

See Also:
Constant Field Values

DEFMEMORY

private static final int DEFMEMORY
The default number of readings to keep, if property is not given.

See Also:
Constant Field Values

DEFPACK

private static final int DEFPACK
The default number of readings to pack, if property is not given.

See Also:
Constant Field Values

DEFAVERAGE

private static final boolean DEFAVERAGE
Act on average per default.

See Also:
Constant Field Values

raw

private Shelf<Double> raw
Stores the raw readings of this sensor.


time

private Shelf<Date> time
Stores the times of the readings.

Constructor Detail

CumulativeSensor

protected CumulativeSensor(Map<String,String> qualify)
Constructs a fully-qualified cumulative sensor, with a given size of measurements to keep.
Use of this constructor guarantees that the Map key memory is always set.

Parameters:
group - The ThreadGroup this thread belongs to.
name - The name of this thread (sensor).
qualify - The Map object describing this sensor.
Method Detail

newData

protected void newData(double raw,
                       Date time)
Called as new data is available. For a cumulative sensor this method directly forks into the cumulateOne(double, java.util.Date) method.

Overrides:
newData in class TimerTaskSensor

cumulateOne

public void cumulateOne(double r,
                        Date when)
The interface method for storing one raw data point and its time of measure. Relies on Sensor methods. Called from newData(double, java.util.Date).

Specified by:
cumulateOne in interface Cumulating
Parameters:
raw - The raw measured value.
See Also:
Cumulating

getLastRaw

public List<Double> getLastRaw(int nr)
The interface method for retrieving the last nr raw measures.

Specified by:
getLastRaw in interface Cumulating
See Also:
Cumulating

getLastTime

public List<Date> getLastTime(int nr)
The interface method for retrieving the last nr measurement times.

Specified by:
getLastTime in interface Cumulating
See Also:
Cumulating

getSize

public int getSize()
Returns the number of datas in the data buffer.

Specified by:
getSize in interface Cumulating
See Also:
Cumulating

getMaxSize

public int getMaxSize()
Returns the maximum number of datas in the data buffer.

Specified by:
getMaxSize in interface Cumulating
See Also:
Cumulating

getMemory

public int getMemory()
Returns the memory property as an Integer. Use of this classes constructors guarantes that this property is a parsable integer.

Returns:
The number of measurements this sensor keeps in memory.

generateDataEvent

protected DataEvent generateDataEvent()
Takes the last sensor reading and produces a CumulativeDataEvent out of it. If the KEY_PACK property points to a value greater than one, the data event produced is the average of the last measurments. If the DataSensor.KEY_REPORT and the KEY_PACK keys both point to the same integer, all data produced is somehow used. However, if KEY_PACK is bigger than DataSensor.KEY_REPORT, some data point are used twice, so care should be taken in handling those keys.
Note that the time of the measure is not calculated as the average of the individual measurements, but is set equal to the central measurement time. This is sufficient because timer task sensors are scheduled for fixed delay executions.

Overrides:
generateDataEvent in class DataSensor
Returns:
A CumulativeDataEvent