1-Wire Weather Service for Java -- Server API

wxservice.sensor.data
Class Precipitation

java.lang.Object
  extended by wxservice.sensor.data.SensorData
      extended by wxservice.sensor.data.Precipitation
All Implemented Interfaces:
ISensorData

public class Precipitation
extends SensorData

Processes data posted by the precipitation task. This data processor converts rain gauge events from bucket tip count or drip count to user-configurable standard units (e.g., inches or cm). The rate is the sum over the "averaging interval" (usually one hour). Also records total accumulation since the last time the reference count was saved to persistent storage. The reference can be configured to update automatically based on the day of the year, day of the month, day of the week, or daily. Stores the file in the current user's home directory, specified by user.home in the Java system.properties.

Configuration

Refer to this internal default resource file for property keys and default values used to configure this data processor. To receive data, the variable sensor-name must map to the name of a sensor task running on Service. Default units 0.01 inch.

Author:
Copyright © 2005 - 2007 Karl Uppiano.

Nested Class Summary
(package private) static class Precipitation.Interval
          Enumeration of rainfall accumulation udpate intervals.
 
Field Summary
static java.lang.String CFG_FILE_LOCATION_KEY
          Reference update schedule name.key suffix.
static java.lang.String CFG_UPDATE_INTERVAL_DAY
          Reference daily update interval configuration value.
static java.lang.String CFG_UPDATE_INTERVAL_DOM
          Reference day of month update interval configuration value.
static java.lang.String CFG_UPDATE_INTERVAL_DOW
          Reference day of week update interval configuration value.
static java.lang.String CFG_UPDATE_INTERVAL_DOY
          Reference day of year update interval configuration value.
static java.lang.String CFG_UPDATE_INTERVAL_KEY
          Reference update interval name.key suffix.
static java.lang.String CFG_UPDATE_INTERVAL_MAN
          Reference manual update interval configuration value.
static java.lang.String CFG_UPDATE_TRIGGER_KEY
          Reference update schedule name.key suffix.
(package private)  double m_accum
          Current value (accumulation).
(package private)  int m_extrap
          Extrapolates rainfall rate to a full hour.
(package private)  java.lang.String m_fileName
          Name of the file.
(package private)  Precipitation.Interval m_interval
          Sample interval enum has all of the update parameters.
(package private)  double m_reference
          Rain gauge count.
(package private)  double m_scale
          Multiplier for calibrating precipitation units.
(package private)  boolean m_update
          Update requested.
(package private) static long MILLIS_DAY
          Number of milliseconds in 24 hours.
 
Fields inherited from class wxservice.sensor.data.SensorData
CFG_AVERAGING_INTERVAL_KEY, CFG_OFFSET_KEY, CFG_SCALE_KEY, m_constant, m_dataAvailable, m_index, m_logger, m_maximumValue, m_minimumValue, m_name, m_reset, m_sensorName, m_values
 
Constructor Summary
Precipitation(java.lang.String name, java.lang.String sensorName, java.util.Properties config)
          Creates a new instance of Precipitation.
 
Method Summary
 java.lang.Number currentValue()
          Modifies the standard way of calculating the current value.
private  boolean isFileValid(java.io.File file, java.util.Calendar calendar)
          Determines if the file exists, and is still valid.
private  boolean isFirstInterval(java.util.Calendar calendar)
          Checks if the current time is within the first sample interval of the day.
private  boolean isTrigger(java.util.Calendar calendar)
          Determines if the current time triggers a reference update.
 java.lang.Number maximumValue(boolean reset)
          Modifies the standard way of calculating maximumValue.
 java.lang.Number minimumValue(boolean reset)
          Modifies the standard way of calculating minimumValue.
protected  void processValue(double value)
          Converts the number of bucket tips into a precipitation rate per hour, converted to units.
private  double readReference(double count, java.util.Calendar calendar)
          Deserializes the reference count from persistent storage.
 java.lang.Number sigmaValue()
          Modifies the standard way of calculating the sigma value.
private  double updateReference(double value)
          Calculates precipitation since the last reference update from the new value.
private  double writeReference(double count)
          Serializes the count to persistent storage for reference.
 
Methods inherited from class wxservice.sensor.data.SensorData
addValue, averageValue, dataAvailable, getConstant, getName, getSensorName, isReset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CFG_UPDATE_INTERVAL_KEY

public static final java.lang.String CFG_UPDATE_INTERVAL_KEY
Reference update interval name.key suffix.

See Also:
Constant Field Values

CFG_UPDATE_INTERVAL_DOY

public static final java.lang.String CFG_UPDATE_INTERVAL_DOY
Reference day of year update interval configuration value.

See Also:
Constant Field Values

CFG_UPDATE_INTERVAL_DOM

public static final java.lang.String CFG_UPDATE_INTERVAL_DOM
Reference day of month update interval configuration value.

See Also:
Constant Field Values

CFG_UPDATE_INTERVAL_DOW

public static final java.lang.String CFG_UPDATE_INTERVAL_DOW
Reference day of week update interval configuration value.

See Also:
Constant Field Values

CFG_UPDATE_INTERVAL_DAY

public static final java.lang.String CFG_UPDATE_INTERVAL_DAY
Reference daily update interval configuration value.

See Also:
Constant Field Values

CFG_UPDATE_INTERVAL_MAN

public static final java.lang.String CFG_UPDATE_INTERVAL_MAN
Reference manual update interval configuration value.

See Also:
Constant Field Values

CFG_UPDATE_TRIGGER_KEY

public static final java.lang.String CFG_UPDATE_TRIGGER_KEY
Reference update schedule name.key suffix.

See Also:
Constant Field Values

CFG_FILE_LOCATION_KEY

public static final java.lang.String CFG_FILE_LOCATION_KEY
Reference update schedule name.key suffix.

See Also:
Constant Field Values

MILLIS_DAY

static final long MILLIS_DAY
Number of milliseconds in 24 hours.

See Also:
Constant Field Values

m_scale

double m_scale
Multiplier for calibrating precipitation units.


m_extrap

int m_extrap
Extrapolates rainfall rate to a full hour.


m_reference

double m_reference
Rain gauge count.


m_accum

double m_accum
Current value (accumulation).


m_interval

Precipitation.Interval m_interval
Sample interval enum has all of the update parameters.


m_update

boolean m_update
Update requested.


m_fileName

java.lang.String m_fileName
Name of the file.

Constructor Detail

Precipitation

public Precipitation(java.lang.String name,
                     java.lang.String sensorName,
                     java.util.Properties config)
Creates a new instance of Precipitation.

Parameters:
name - of this data processor.
sensorName - of the sensor associated with this data.
config - properties for configuring this data.
Method Detail

sigmaValue

public java.lang.Number sigmaValue()
Modifies the standard way of calculating the sigma value. Extrapolates the sigma value rainfall rate to a full hour.

Specified by:
sigmaValue in interface ISensorData
Overrides:
sigmaValue in class SensorData
Returns:
weighted sigma value.

currentValue

public java.lang.Number currentValue()
Modifies the standard way of calculating the current value. The current value is the rainfall accumulated since the last reference update.

Specified by:
currentValue in interface ISensorData
Overrides:
currentValue in class SensorData
Returns:
stored current value for this sensor data.

maximumValue

public java.lang.Number maximumValue(boolean reset)
Modifies the standard way of calculating maximumValue. Calculates the highest value since the last reset.

Specified by:
maximumValue in interface ISensorData
Overrides:
maximumValue in class SensorData
Parameters:
reset - if true, resets to the next sigma value.
Returns:
highest value recorded since the last reset, or null if no data is available.

minimumValue

public java.lang.Number minimumValue(boolean reset)
Modifies the standard way of calculating minimumValue. Calculates the lowest value since the last reset.

Specified by:
minimumValue in interface ISensorData
Overrides:
minimumValue in class SensorData
Parameters:
reset - if true, resets to the next sigma value.
Returns:
lowest value recorded since the last reset, or null if no data is available.

processValue

protected void processValue(double value)
Converts the number of bucket tips into a precipitation rate per hour, converted to units. The current value represents the accumulated rainfall. Average, minimum and maximum represents the rate.

Overrides:
processValue in class SensorData
Parameters:
value - absolute number of bucket tips in the rain gauge.

updateReference

private double updateReference(double value)
Calculates precipitation since the last reference update from the new value. If reference is zero, initializes reference from persistent storage, using the value parameter as a default if persistent storage does not exist. When the update interval triggers, updates the reference to the new value and serializes it to persistent storage.

Parameters:
value - the new count from the rain gauge.
Returns:
rainfall accumulation since the last update.

isTrigger

private boolean isTrigger(java.util.Calendar calendar)
Determines if the current time triggers a reference update.

Parameters:
calendar - representing the current time.
Returns:
true if the current time triggers a reference update.

isFirstInterval

private boolean isFirstInterval(java.util.Calendar calendar)
Checks if the current time is within the first sample interval of the day.

Parameters:
calendar - representing the current time.
Returns:
true if the current time is within the first sample interval of the day.

writeReference

private double writeReference(double count)
Serializes the count to persistent storage for reference.

Parameters:
count - value to serialize.
Returns:
count parameter pass-through.

readReference

private double readReference(double count,
                             java.util.Calendar calendar)
Deserializes the reference count from persistent storage. If the file is expired or does not exist, creates a new file using the default count.

Parameters:
count - default value to use if the file does not exist.
calendar - representing the current time.
Returns:
the stored count or the default if the file is expired or does not exist.

isFileValid

private boolean isFileValid(java.io.File file,
                            java.util.Calendar calendar)
Determines if the file exists, and is still valid.

Parameters:
file - to check for validity.
calendar - representing the current time.
Returns:
true if current time is less than file last modified + lifetime and the file exists. Last modified returns 0L if the file does not exist.

Copyright © 2005-2007 Karl Uppiano