stella.sensor
Class BadSensor

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
                                      extended by stella.sensor.PredictiveSensor
                                          extended by stella.sensor.SmoothingSensor
                                              extended by stella.sensor.DerivativeSensor
                                                  extended by stella.sensor.WeatherSensor
                                                      extended by stella.sensor.BadSensor
All Implemented Interfaces:
Cloneable, Remote, Caster, DataCaster, ParameterDepending, RmiDataCaster, RmiErrorCaster, Cumulating, Deriving, Predicting, Smoothing, Telemetering, WeatherJudging, WeatherCaster, ExitCleaning, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying, RmiCaster, RmiPropertyBearing

public class BadSensor
extends WeatherSensor
implements ParameterDepending

A bad sensor does not generate data events based on reading a true sensor, but generates it from evaluating a probability description. Three parameter govern the sensor

The sensor works as follows: We start with good weather and estimate a first bad-weather period by doing a gaussian-distributed randomization around the bad weather period with the KEY_GAUSSSIGMA gauss sigma. After the initial bad weather, we calculate the fraction of the accumulated bad to good weather phases. This fraction is compared to the target bad fraction and a normal random pick determines whether the weather changes or not. Any weather change will produce only sensor readings (KEY_GOODREADING or KEY_BADREADING) until the next change commences. To allow this sensor to work seamless

Default mappings are for a typical humidity sensor at a bad level of 0.2, and a good period of 4 days, a bad period of one day, if started with the default respawn rate of 1 second.


Nested Class Summary
static class BadSensor.Randomize
          Class for testing.
 
Nested classes/interfaces inherited from class stella.sensor.TimerTaskSensor
TimerTaskSensor.SensorRead
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private  long badcount
          Cumulated bad period.
private static double DEFBADFRACTION
          The default bad weather period.
private static long DEFBADPERIOD
          The default bad weather period.
private static double DEFBADREADING
          The default good reading.
private static double DEFGAUSSSIGMA
          The default sigma.
private static long DEFGOODPERIOD
          The default good weather period.
private static double DEFGOODREADING
          The default good reading.
private static long DEFMAXPERIOD
          The default maximum period.
private static long DEFMINPERIOD
          The default minimum period.
private static String DEFTIME
          The default time parameter.
private  long goodcount
          Cumulated good period.
static String KEY_BADFRACTION
          The key to standard bad weather fraction.
static String KEY_BADPERIOD
          The key to standard bad weather period.
static String KEY_BADREADING
          The key to standard bad reading.
static String KEY_GAUSSSIGMA
          The key to the standard deviation of the weather periods.
static String KEY_GOODPERIOD
          The key to standard good weather period.
static String KEY_GOODREADING
          The key to standard good reading.
static String KEY_MAXPERIOD
          The key to maximum weather period.
static String KEY_MINPERIOD
          The key to minimum weather period.
static String KEY_TIME
          The key giving the name of the time parameter.
private  long period
          Current active period.
private static Random random
          My random number generator.
private  Time time
          A special time grabbed from the parameter cluster.
private  long toggled
          Last time of weather change.
private  boolean weather
          Current active weather.
 
Fields inherited from class stella.sensor.WeatherSensor
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_SMOOTHPARAMETER
 
Fields inherited from class stella.sensor.DerivativeSensor
DEFRAWDERIVATIVE, derive, KEY_DERIVATIVEADVISE, KEY_DERIVE, KEY_PATH, KEY_RAWDERIVATIVE, z
 
Fields inherited from class stella.sensor.SmoothingSensor
f, g, KEY_SMOOTH, KEY_SMOOTHADVISE
 
Fields inherited from class stella.sensor.PredictiveSensor
KEY_BASE, KEY_CHI, KEY_EXTRAPOLATE, KEY_FUTURE, KEY_PREDICTADVISE, predict
 
Fields inherited from class stella.sensor.CumulativeSensor
KEY_AVERAGE, KEY_MEMORY, KEY_PACK
 
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
BadSensor(Map prop)
          Constructs a new fake sensor.
 
Method Summary
private  long getWeatherPeriod(long stdperiod, double sigma)
          Returns a new weather period.
 TimerTask initSensorTimerTask()
          Starts the sensor.
protected  double readSensor()
          Returns the current weather depending reading.
 void registerParameter(Parameter systime)
          If we have a time, use it.
 boolean validReading()
          A bad sensor is always valid.
 
Methods inherited from class stella.sensor.WeatherSensor
addWeatherListener, conductOneMeasure, currentlyClear, currentlyRetarding, generateDataEvent, getMinClearUpTime, getSensorInitInfo, goodFromDerivative, goodFromPredict, goodFromRaw, goodFromSmooth, isDerivativeRetard, isPredictRetard, isRawRetard, isSmoothRetard, judgeWeather, notifyWeatherListener, removeWeatherListener, status
 
Methods inherited from class stella.sensor.DerivativeSensor
deriveAt, getDerivativeFormat, getDerivativeToggleInfo, getDerivator, getLastDerivative, isDerivativeAdvise, isDeriving, newData, regetDerive, registerDerivator
 
Methods inherited from class stella.sensor.SmoothingSensor
getLastSmooth, getSmoother, getSmoothToggleInfo, isSmoothAdvise, isSmoothing, regetSmooth, registerSmoother, smoothOne
 
Methods inherited from class stella.sensor.PredictiveSensor
getExtrapolation, getLastPredict, getPredictToggleInfo, isPredictAdvise, isPredicting, isReliable, predictFrom, regetPredict
 
Methods inherited from class stella.sensor.CumulativeSensor
cumulateOne, getLastRaw, getLastTime, getMaxSize, getMemory, getSize
 
Methods inherited from class stella.sensor.DataSensor
addDataListener, addRmiDataListener, exit, getRawFormat, getSigmaFormat, removeDataListener, removeRmiDataListener, report
 
Methods inherited from class stella.sensor.TimerTaskSensor
cancel, equals, getRawToggleInfo, getReading, getRespawn, getTimeOfRead, hashCode, isReady, regetRaw, setTimeOfRead, validReading
 
Methods inherited from class stella.sensor.AbstractSensor
addRmiErrorListener, createSensor, getBindName, getConvert, getSensorDescription, getSensorName, init, notifyErrorListener, removeRmiErrorListener, setConvert, 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
cumulateOne, getLastRaw, getLastTime, getMaxSize, getSize, getTimeOfRead, regetRaw
 
Methods inherited from interface util.rmi.RmiCaster
bindToRegistry, isValid, unbindFromRegistry
 
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_MINPERIOD

public static final String KEY_MINPERIOD
The key to minimum weather period.

See Also:
Constant Field Values

KEY_MAXPERIOD

public static final String KEY_MAXPERIOD
The key to maximum weather period.

See Also:
Constant Field Values

KEY_GOODPERIOD

public static final String KEY_GOODPERIOD
The key to standard good weather period.

See Also:
Constant Field Values

KEY_BADPERIOD

public static final String KEY_BADPERIOD
The key to standard bad weather period.

See Also:
Constant Field Values

KEY_BADFRACTION

public static final String KEY_BADFRACTION
The key to standard bad weather fraction.

See Also:
Constant Field Values

KEY_GAUSSSIGMA

public static final String KEY_GAUSSSIGMA
The key to the standard deviation of the weather periods.

See Also:
Constant Field Values

KEY_GOODREADING

public static final String KEY_GOODREADING
The key to standard good reading.

See Also:
Constant Field Values

KEY_BADREADING

public static final String KEY_BADREADING
The key to standard bad reading.

See Also:
Constant Field Values

KEY_TIME

public static final String KEY_TIME
The key giving the name of the time parameter.

See Also:
Constant Field Values

DEFMINPERIOD

private static final long DEFMINPERIOD
The default minimum period.

See Also:
Constant Field Values

DEFMAXPERIOD

private static final long DEFMAXPERIOD
The default maximum period.

See Also:
Constant Field Values

DEFGOODPERIOD

private static final long DEFGOODPERIOD
The default good weather period.

See Also:
Constant Field Values

DEFBADPERIOD

private static final long DEFBADPERIOD
The default bad weather period.

See Also:
Constant Field Values

DEFBADFRACTION

private static final double DEFBADFRACTION
The default bad weather period.

See Also:
Constant Field Values

DEFGAUSSSIGMA

private static final double DEFGAUSSSIGMA
The default sigma.

See Also:
Constant Field Values

DEFGOODREADING

private static final double DEFGOODREADING
The default good reading.

See Also:
Constant Field Values

DEFBADREADING

private static final double DEFBADREADING
The default good reading.

See Also:
Constant Field Values

DEFTIME

private static final String DEFTIME
The default time parameter.

See Also:
Constant Field Values

goodcount

private long goodcount
Cumulated good period.


badcount

private long badcount
Cumulated bad period.


period

private long period
Current active period.


weather

private boolean weather
Current active weather.


toggled

private long toggled
Last time of weather change.


time

private Time time
A special time grabbed from the parameter cluster.


random

private static Random random
My random number generator.

Constructor Detail

BadSensor

public BadSensor(Map prop)
          throws RemoteException
Constructs a new fake sensor. The file found in in the properties is also opened here.

Throws:
RemoteException
Method Detail

initSensorTimerTask

public TimerTask initSensorTimerTask()
Starts the sensor. If we have a time parameter, we use this, otherwise system time is used. Here we start with a good weather period.

Specified by:
initSensorTimerTask in interface Telemetering
Overrides:
initSensorTimerTask in class TimerTaskSensor
Returns:
The ready-to-start timer-task of this sensor.
See Also:
Telemetering.getRespawn()

registerParameter

public void registerParameter(Parameter systime)
If we have a time, use it.

Specified by:
registerParameter in interface ParameterDepending

validReading

public boolean validReading()
A bad sensor is always valid.

Specified by:
validReading in interface Telemetering

readSensor

protected double readSensor()
Returns the current weather depending reading. If the weather should change, we calculate the accumulated fraction of good and bad weather times and may toggle the weather to a new value.

Specified by:
readSensor in class TimerTaskSensor
See Also:
ConvertToPhysical

getWeatherPeriod

private long getWeatherPeriod(long stdperiod,
                              double sigma)
Returns a new weather period. It delivers a gaussian distribution spread around the first argument with a sigma of the second argument.