org.jlf.vitals
Class VitalStatistics

java.lang.Object
  |
  +--org.jlf.vitals.VitalStatistics

public class VitalStatistics
extends java.lang.Object

VitalStatistics holds a set of statistics for a particular vital sign throughout the useful life of the vital sign.


Field Summary
protected  AbstractVitalMeasurement highestRecordedMeasurement
          Holds the highest recorded measurement.
protected  AbstractVitalMeasurement latestRecordedMeasurement
          Holds the lowest recorded measurement.
protected  AbstractVitalMeasurement lowestRecordedMeasurement
          Holds the lowest recorded measurement.
protected  long measurementsTaken
          Holds the count of all measurements taken.
protected  java.util.LinkedList recentlyRecordedAlerts
          Holds a collection of the most recently-recorded alerts.
protected  java.util.LinkedList recentlyRecordedMeasurements
          Holds a collection of the most recently-recorded measurements.
protected  AbstractVitalMeasurement summationOfMeasurements
          Holds the sum of all recorded measurements.
protected  long timeLastAlertDetected
          Holds the date/time an alert was found (but not necessarily logged).
protected  long timeLastAlertLogged
          Holds the date/time of the last alert logged measurement for the statistic.
protected  long timeLastStatisticLogged
          Holds the date/time of the last logged measurement for the statistic.
protected  VitalSign vitalSign
          Holds the vital sign the statistics are being collected for.
 
Constructor Summary
VitalStatistics(VitalSign vitalSign)
          Creates a vital statistics set for a vital sign.
 
Method Summary
protected  void addRecentlyRecordedAlert(AbstractVitalMeasurement newMeasurement)
          Helper method to track the history for recently recorded alerts.
protected  void addRecentlyRecordedMeasurement(AbstractVitalMeasurement newMeasurement)
          Helper method to track the history for recently recorded measurements.
protected  void checkRecentlyRecordedMeasurementForAlerts(AbstractVitalMeasurement newMeasurement, boolean newHighFlag)
          Checks a measurement to see if it generates an alert, and if so, records the alert.
 AbstractVitalMeasurement getAverageOfMeasurements()
          Returns the average across all measurements taken.
 AbstractVitalMeasurement getHighestRecordedMeasurement()
          Returns the highest recorded measurement.
 double getHistoryMeasurementsTakenPerSecond()
          Returns the average number of measurements taken per second, from all measurements recorded in the history collection.
 AbstractVitalMeasurement getLatestRecordedMeasurement()
          Returns the most recently-recorded measurement.
 AbstractVitalMeasurement getLowestRecordedMeasurement()
          Returns the lowest recorded measurement.
 long getMeasurementsTaken()
          Returns the number of measurements taken.
 java.util.Collection getRecentlyRecordedAlerts()
          Returns the recentlyRecordedAlerts list.
 java.util.Collection getRecentlyRecordedMeasurements()
          Returns the recentlyRecordedMeasurements list.
 java.util.Date getTimeLastAlertWasDetected()
          Returns the date the last alert has been detected, or null if no alert has been detected.
 VitalSign getVitalSign()
          Returns the vital sign the statistics are for.
 boolean hasAlertBeenDetectedInRecentMinutes(long minutes)
          Detects whether an alert has been detected within the input number of minutes from the current time.
protected  void logAlert(AbstractVitalMeasurement newMeasurement, java.lang.String alertReason)
          Helper method to see if the measurement needs to be logged and if so, logs it.
protected  void logMeasurement(AbstractVitalMeasurement newMeasurement)
          Helper method to see if the measurement needs to be logged and if so, logs it.
 void registerMeasurement(AbstractVitalMeasurement newMeasurement)
          Adds a measurement to the set of statistics kept.
 boolean shouldAlertBeLogged()
          Checks to see if a measurement generating an alert should be logged, given its frequency defined in the property file.
 boolean shouldMeasurementBeLogged()
          Checks to see if a measurement should be logged, given its frequency defined in the property file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

vitalSign

protected VitalSign vitalSign
Holds the vital sign the statistics are being collected for.


highestRecordedMeasurement

protected AbstractVitalMeasurement highestRecordedMeasurement
Holds the highest recorded measurement.


lowestRecordedMeasurement

protected AbstractVitalMeasurement lowestRecordedMeasurement
Holds the lowest recorded measurement.


latestRecordedMeasurement

protected AbstractVitalMeasurement latestRecordedMeasurement
Holds the lowest recorded measurement.


summationOfMeasurements

protected AbstractVitalMeasurement summationOfMeasurements
Holds the sum of all recorded measurements.


recentlyRecordedMeasurements

protected java.util.LinkedList recentlyRecordedMeasurements
Holds a collection of the most recently-recorded measurements.


recentlyRecordedAlerts

protected java.util.LinkedList recentlyRecordedAlerts
Holds a collection of the most recently-recorded alerts.


measurementsTaken

protected long measurementsTaken
Holds the count of all measurements taken.


timeLastStatisticLogged

protected long timeLastStatisticLogged
Holds the date/time of the last logged measurement for the statistic.


timeLastAlertLogged

protected long timeLastAlertLogged
Holds the date/time of the last alert logged measurement for the statistic.


timeLastAlertDetected

protected long timeLastAlertDetected
Holds the date/time an alert was found (but not necessarily logged). If the value is zero, no alert has been found.

Constructor Detail

VitalStatistics

public VitalStatistics(VitalSign vitalSign)
Creates a vital statistics set for a vital sign.

Method Detail

getVitalSign

public VitalSign getVitalSign()
Returns the vital sign the statistics are for.


getRecentlyRecordedMeasurements

public java.util.Collection getRecentlyRecordedMeasurements()
Returns the recentlyRecordedMeasurements list.

Returns:
A collection of recently-recorded measurements

shouldMeasurementBeLogged

public boolean shouldMeasurementBeLogged()
Checks to see if a measurement should be logged, given its frequency defined in the property file.


logMeasurement

protected void logMeasurement(AbstractVitalMeasurement newMeasurement)
Helper method to see if the measurement needs to be logged and if so, logs it.


addRecentlyRecordedMeasurement

protected void addRecentlyRecordedMeasurement(AbstractVitalMeasurement newMeasurement)
Helper method to track the history for recently recorded measurements.

Parameters:
newMeasurement -

getRecentlyRecordedAlerts

public java.util.Collection getRecentlyRecordedAlerts()
Returns the recentlyRecordedAlerts list.

Returns:
A collection of recently-recorded alerts

addRecentlyRecordedAlert

protected void addRecentlyRecordedAlert(AbstractVitalMeasurement newMeasurement)
Helper method to track the history for recently recorded alerts. Makes sure the alert history doesn't get too large, as defined by the property file.

Parameters:
newMeasurement -

shouldAlertBeLogged

public boolean shouldAlertBeLogged()
Checks to see if a measurement generating an alert should be logged, given its frequency defined in the property file.


logAlert

protected void logAlert(AbstractVitalMeasurement newMeasurement,
                        java.lang.String alertReason)
Helper method to see if the measurement needs to be logged and if so, logs it.


checkRecentlyRecordedMeasurementForAlerts

protected void checkRecentlyRecordedMeasurementForAlerts(AbstractVitalMeasurement newMeasurement,
                                                         boolean newHighFlag)
Checks a measurement to see if it generates an alert, and if so, records the alert.

Parameters:
newMeasurement - The measurement about to be added to the collection of measurements recorded
newHighFlag - Flag telling whether the measurement is a new high, so the check previously done in the code doesn't have to be performed again.

hasAlertBeenDetectedInRecentMinutes

public boolean hasAlertBeenDetectedInRecentMinutes(long minutes)
Detects whether an alert has been detected within the input number of minutes from the current time.

Parameters:
minutes - The number of minutes you want to check

getTimeLastAlertWasDetected

public java.util.Date getTimeLastAlertWasDetected()
Returns the date the last alert has been detected, or null if no alert has been detected.


registerMeasurement

public void registerMeasurement(AbstractVitalMeasurement newMeasurement)
Adds a measurement to the set of statistics kept.


getHighestRecordedMeasurement

public AbstractVitalMeasurement getHighestRecordedMeasurement()
Returns the highest recorded measurement.


getLowestRecordedMeasurement

public AbstractVitalMeasurement getLowestRecordedMeasurement()
Returns the lowest recorded measurement.


getMeasurementsTaken

public long getMeasurementsTaken()
Returns the number of measurements taken.


getAverageOfMeasurements

public AbstractVitalMeasurement getAverageOfMeasurements()
Returns the average across all measurements taken.


getLatestRecordedMeasurement

public AbstractVitalMeasurement getLatestRecordedMeasurement()
Returns the most recently-recorded measurement.

Returns:
AbstractVitalMeasurement

getHistoryMeasurementsTakenPerSecond

public double getHistoryMeasurementsTakenPerSecond()
Returns the average number of measurements taken per second, from all measurements recorded in the history collection. If you don't have a history collection size defined, then this method will always return zero.