Package com.storedobject.iot
Class Statistics<P extends PeriodType>
java.lang.Object
com.storedobject.core.StoredObject
com.storedobject.iot.Statistics<P>
- Type Parameters:
P
- Period type
- All Implemented Interfaces:
Displayable
,StringFiller
,DBTransaction.NoHistory
,HasId
- Direct Known Subclasses:
DailyStatistics
,HourlyStatistics
,MonthlyStatistics
,WeeklyStatistics
,YearlyStatistics
public abstract class Statistics<P extends PeriodType>
extends StoredObject
implements DBTransaction.NoHistory
Represents statistical data pertaining to units and periods.
This class provides methods for calculating and updating statistics,
including minimum, maximum, mean, standard deviation, and count for a dataset.
It is designed to handle various periods such as hourly, daily, weekly, monthly, and yearly.
Concrete subclasses must define the specific period-related methods and data fields.
- Author:
- Syam
-
Field Summary
Fields inherited from class com.storedobject.core.StoredObject
logger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(double value) Adds a value to the statistics and updates the minimum, maximum, mean, standard deviation, and the count of values accordingly.void
add
(Statistics<?> another) Adds the statistical data from another `Statistics` object to this one.static void
Configures the column definitions for a given Columns object.int
getCount()
Retrieves the count associated with the statistics.double
getMax()
Retrieves the maximum value among the recorded statistics.double
getMean()
Retrieves the mean value of the statistical data.double
getMin()
Retrieves the minimum value from the statistical data.getName()
Retrieves the name associated with this instance.abstract int
Retrieves the period value associated with the statistics object.abstract String
Retrieves the detailed description of the period associated with this statistics object.Retrieves the period name associated with the instance of the class.abstract PeriodType
Retrieves the period type associated with the statistics instance.double
getSD()
Retrieves the standard deviation (SD) for the associated statistical data.getUnit()
Retrieves the unit associated with this instance based on theunitId
.Retrieves the unique identifier for the unit associated with the statistics.int
getYear()
Retrieves the year associated with this instance.abstract Statistics
<P> next()
Retrieves the next instance of statistics in a sequence or ordered collection.abstract Statistics
<P> previous()
Retrieves the previous instance of statistics in a sequence or ordered collection.void
setCount
(int count) Sets the count value for the Statistics object.void
setMax
(double max) Sets the maximum value for this Statistics object.void
setMean
(double mean) Sets the mean value for this instance.void
setMin
(double min) Sets the minimum value for the statistical data field.void
Sets the name of the statistics instance.void
setSD
(double sd) Sets the standard deviation (SD) value for this instance.void
Sets the unit associated with the Statistics object.void
Assigns the given Unit to this Statistics instance by extracting its identifier.void
setUnit
(BigDecimal idValue) Sets the unit using the provided BigDecimal value.void
setYear
(int year) Sets the year for this statistics object.Converts the statistics object into a formatted display string including its name, unit, count, minimum value, maximum value, mean value, standard deviation, and year.void
Validates the data of the current object.Methods inherited from class com.storedobject.core.StoredObject
addLink, addLink, addLink, addLink, addLink, addLink, addLink, addLink, checkCurrency, checkCurrency, checkForDuplicate, checkForDuplicate, checkTimeZone, checkTransaction, clearObjectLinks, contemporary, copy, copy, count, count, count, count, count, count, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, create, created, delete, delete, delete, deleted, directUpdate, equals, exists, exists, exists, exists, exists, existsFileData, existsLink, existsLink, existsLink, existsLink, existsLink, existsLink, existsLink, existsLink, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsMaster, existsMaster, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, family, family, family, fill, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, getAttachment, getAttachmentId, getChildren, getDeleted, getDeleted, getExistsCondition, getExistsCondition, getFileData, getFileData, getHistorical, getId, getKeyIndex, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getNotExistsCondition, getNotExistsCondition, getParent, getParent, getParent, getParentId, getParentId, getParentId, getRelated, getRelated, getTransaction, getTransactionId, getTransactionIP, getUnique, getUniqueCondition, hashCode, inserted, isModified, isVirtual, list, list, list, list, list, list, list, list, list, list, list, list, list, listFileData, listFileData, listHistory, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listTree, listTree, listTree, listTree, listViaQuery, listViaQuery, load, load, load, load, loaded, loading, makeNew, makeVirtual, migrate, moduleName, nextVersion, objectLink, objectLink, objectLink, objectLinks, objectLinks, old, person, previousVersion, previousVersion, query, query, query, query, query, query, query, query, query, query, query, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, reload, reload, reloaded, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeReverseLinks, removeReverseLinks, save, save, save, save, save, save, save, save, save, save, save, save, save, save, saved, saving, setMaster, setRawValue, setTransaction, stringify, tableName, timestamp, toCode, toString, transacting, undelete, undelete, undeleted, updated, user, userId, validate, validateChildAttach, validateChildDetach, validateChildUpdate, validateDelete, validateInsert, validateParentAttach, validateParentDetach, validateParentUpdate, validateUndelete, validateUpdate, valueEquals
-
Constructor Details
-
Statistics
public Statistics()Default constructor for the Statistics class. Initializes a Statistics object with default values. This serves as the default instantiation mechanism for creating a basic Statistics instance without setting specific attributes during initialization.
-
-
Method Details
-
columns
Configures the column definitions for a given Columns object. This method defines various statistical columns with their respective names and data types.- Parameters:
columns
- The Columns object to which the column definitions are added. It must not be null and should be capable of accepting column definitions.
-
setUnit
Sets the unit associated with the Statistics object. This method modifies the unitId field if the object is not in a loading state and the provided unitId differs from the current unitId. If these conditions are not met, it throws a Set_Not_Allowed exception.- Parameters:
unitId
- The unique identifier of the unit to associate with the Statistics object. This identifier must be valid and not violate the conditions for modification.- Throws:
Set_Not_Allowed
- if the object is not in a loading state or the provided unitId tries to alter the current unitId while modification is restricted.
-
setUnit
Sets the unit using the provided BigDecimal value. The BigDecimal value is used to create anId
object, which is then set as the unit.- Parameters:
idValue
- The BigDecimal value representing the ID of the unit.
-
setUnit
Assigns the given Unit to this Statistics instance by extracting its identifier.- Parameters:
unit
- The Unit object to set for this Statistics instance. If null, the unit will be set to null.
-
getUnitId
Retrieves the unique identifier for the unit associated with the statistics.- Returns:
- the unit's unique identifier as an
Id
.
-
getUnit
Retrieves the unit associated with this instance based on theunitId
.- Returns:
- The associated
Unit
object, ornull
if no unit is found.
-
setName
Sets the name of the statistics instance.- Parameters:
name
- the name to set
-
getName
-
setYear
public void setYear(int year) Sets the year for this statistics object.- Parameters:
year
- the year to set
-
getYear
-
setCount
public void setCount(int count) Sets the count value for the Statistics object.- Parameters:
count
- The count value to be set.
-
getCount
-
setMin
public void setMin(double min) Sets the minimum value for the statistical data field.- Parameters:
min
- The minimum value to be set.
-
getMin
-
setMax
public void setMax(double max) Sets the maximum value for this Statistics object.- Parameters:
max
- The maximum value to be set.
-
getMax
-
setMean
public void setMean(double mean) Sets the mean value for this instance.- Parameters:
mean
- The mean value to set.
-
getMean
-
setSD
public void setSD(double sd) Sets the standard deviation (SD) value for this instance.- Parameters:
sd
- The standard deviation value to set.
-
getSD
-
validateData
Validates the data of the current object. This method ensures that the required fields have valid values and performs additional checks using the provided transaction manager.- Overrides:
validateData
in classStoredObject
- Parameters:
tm
- The TransactionManager object used for data validation and type checking.- Throws:
Exception
- If any validation criteria are not met, such as missing or invalid values, or if an error occurs during type checking.
-
getPeriodName
Retrieves the period name associated with the instance of the class. If the instance belongs to theDailyStatistics
class, the period name returned will be "Day". For other subclasses derived from theStatistics
class, this method infers the period name based on the class name by trimming certain suffixes.- Returns:
- A string representing the period name derived from the class type.
-
getPeriod
public abstract int getPeriod()Retrieves the period value associated with the statistics object.- Returns:
- the period value as an integer
-
getPeriodDetail
Retrieves the detailed description of the period associated with this statistics object.- Returns:
- A String representing the specific details of the period.
-
toDisplay
Converts the statistics object into a formatted display string including its name, unit, count, minimum value, maximum value, mean value, standard deviation, and year. If not a yearly statistic, also includes period name and period value.- Specified by:
toDisplay
in interfaceDisplayable
- Overrides:
toDisplay
in classStoredObject
- Returns:
- A human-readable string format of the statistics object with detailed attributes.
-
add
public void add(double value) Adds a value to the statistics and updates the minimum, maximum, mean, standard deviation, and the count of values accordingly.- Parameters:
value
- The value to be added to the statistical data.
-
add
Adds the statistical data from another `Statistics` object to this one.- Parameters:
another
- Another `Statistics` object whose data will be added to this object. If the passed `Statistics` object is null or has no data (count is 0), the method returns without making any changes.
-
previous
Retrieves the previous instance of statistics in a sequence or ordered collection.- Returns:
- A statistics object representing the previous instance in the sequence.
-
next
Retrieves the next instance of statistics in a sequence or ordered collection.- Returns:
- A statistics object representing the next instance in the sequence.
-
getPeriodType
Retrieves the period type associated with the statistics instance. The period type provides an abstraction for the categorization or granularity of the period this statistics object refers to.- Returns:
- The
PeriodType
representing the type of period associated with the statistics.
-