Package com.storedobject.iot
Class Data
java.lang.Object
com.storedobject.core.StoredObject
com.storedobject.iot.Data
- All Implemented Interfaces:
Displayable
,StringFiller
,DBTransaction.NoHistory
,HasId
Base class that represents data values that belong to a
Unit
.
It generally contains only "boolean" and "double" values.
When transacted singly, it doesn't maintain any history or audit trail.
This is not used for any direct data entry and is mostly created or updated by
IoT data capture processes. The StoredObject.directUpdate(TransactionManager)
method can be used to directly update
the data in the case of existing instances without even creating new transactions.- Author:
- Syam
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final record
Structure to hold time and value. -
Field Summary
Fields inherited from class com.storedobject.core.StoredObject
logger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Attributes.final long
Get the time at which this data is collected (GMT).static <IOT extends Data>
IOTGet the latest data record collected.getStateChanged
(Class<D> dataClass, Id unitId, String variable, long from, long to, boolean toTrue) Determines the number of state changes for a specified variable of a given data class for a specific unit within a specified time range.getStateChanged
(Class<D> dataClass, Id unitId, String variable, PeriodType periodType, int periodCount, boolean toTrue) Determines the state changes of a specific variable within a given period of time.final Timestamp
Get the time at which this data is collected (GMT) as a timestamp.final Unit
getUnit()
Get the unit to which this data belong to.Get the Unit's class for this data instance.getUnitClass
(Class<? extends Data> dataClass) Get the Unit's class for the given data class.final Id
Get theId
of the unit this IoT object belongs to.static <D extends Data>
Data.ValuegetValueAt
(Class<D> dataClass, Id unitId, String variable, long collectedAt, Duration timeSpan) Get the data value collected at the given instance.static <D extends Data>
intgetValueCount
(Class<D> dataClass, Id unitId, String variable, int value, long from, long to) Computes the number of occurrences of a specific variable with a specified value for a given data class and unit within a defined time range.static <D extends Data>
intgetValueCount
(Class<D> dataClass, Id unitId, String variable, int value, PeriodType periodType, int periodCount) Calculates the number of occurrences of a specific variable with a given value for a specified data class and unit within a defined time period.getValueDifference
(Class<D> dataClass, Id unitId, String variable, long from, long to) Get the difference in data value collected at 2 different time instances.getValueDifference
(Class<D> dataClass, Id unitId, String variable, PeriodType periodType, int periodCount) Calculates the difference in the values of a specified variable for a given data class and unit within a specified time period.static void
Indices.final void
setCollectedAt
(long collectedAt) Mandatory attribute - data collection time (GMT)void
Set the unitId
of this IoT object.final void
Set the unit of this IoT object.final void
setUnit
(BigDecimal idValue) Set the unitId
of this IoT object.void
This will be invoked by the system whenever the object is saved to the DB.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, toDisplay, toString, transacting, undelete, undelete, undeleted, updated, user, userId, validate, validateChildAttach, validateChildDetach, validateChildUpdate, validateDelete, validateInsert, validateParentAttach, validateParentDetach, validateParentUpdate, validateUndelete, validateUpdate, valueEquals
-
Constructor Details
-
Data
public Data()
-
-
Method Details
-
columns
-
indices
-
setCollectedAt
public final void setCollectedAt(long collectedAt) Mandatory attribute - data collection time (GMT)- Parameters:
collectedAt
- Data collection time.
-
getCollectedAt
public final long getCollectedAt()Get the time at which this data is collected (GMT).- Returns:
- Data collection time.
-
getTimestamp
Get the time at which this data is collected (GMT) as a timestamp.- Returns:
- Data collection time as a timestamp.
-
setUnit
Set the unitId
of this IoT object. Typically, every IoT object instance belongs to some unit (plant or equipment being monitored). There must be a "data class" for every such unit and theId
of that unit must be set here. An IoT object itself may be independent of any unit (for example, generic values like temperature/humidity of an environment etc.) and in such cases, a virtual unit (for example, Environment) must be defined.- Parameters:
unitId
- Id of the unit.
-
setUnit
Set the unitId
of this IoT object. Typically, every IoT object instance belongs to some unit (plant or equipment being monitored). There must be a "data class" for every such unit and theId
of that unit must be set here. An IoT object itself may be independent of any unit (for example, generic values like temperature/humidity of an environment etc.) and in such cases, a virtual unit (for example, Environment) must be defined.- Parameters:
idValue
- Id of the unit.
-
setUnit
Set the unit of this IoT object. Typically, every IoT object instance belongs to some unit (plant or equipment being monitored). There must be a "data class" for every such unit and that unit must be set here. An IoT object itself may be independent of any unit (for example, generic values like temperature/humidity of an environment etc.) and in such cases, a virtual unit (for example, Environment) must be defined.- Parameters:
unit
- Unit.
-
getUnitId
-
getUnit
Get the unit to which this data belong to. SeesetUnit(Unit)
.- Returns:
- Unit.
-
validateData
Description copied from class:StoredObject
This will be invoked by the system whenever the object is saved to the DB. It will be invoked in all cases, while creating new objects and updating/deleting/un-deleting existing objects. If any exception is raised by this method, the process of saving to the DB will be abandoned.
Note: This method is mainly used to validate the data of all attributes of the object, and it may be used by others for validating the object. For example, front-end data-entry systems can use this method for validating the object.
- Overrides:
validateData
in classStoredObject
- Parameters:
tm
- Current transaction manager.- Throws:
Exception
- If data is invalid.
-
getLatest
Get the latest data record collected.- Type Parameters:
IOT
- Type of object class.- Parameters:
objectClass
- IOT object class.unitId
-Id
of the unit (could be null).- Returns:
- Latest data record or null if not available.
-
getUnitClass
-
getUnitClass
-
getValueAt
public static <D extends Data> Data.Value getValueAt(Class<D> dataClass, Id unitId, String variable, long collectedAt, Duration timeSpan) Get the data value collected at the given instance.- Type Parameters:
D
- Data type.- Parameters:
dataClass
- Data class.unitId
- Unit Id.collectedAt
- Time of collection.timeSpan
- Time span. (Collected at +/- this time span is searched).- Returns:
- Data value if found.
-
getValueDifference
public static <D extends Data> Double getValueDifference(Class<D> dataClass, Id unitId, String variable, long from, long to) Get the difference in data value collected at 2 different time instances.- Type Parameters:
D
- Data type.- Parameters:
dataClass
- Data class.unitId
- Unit Id.from
- Time from.to
- Time to.- Returns:
- Data value if found.
-
getValueDifference
public static <D extends Data> Double getValueDifference(Class<D> dataClass, Id unitId, String variable, PeriodType periodType, int periodCount) Calculates the difference in the values of a specified variable for a given data class and unit within a specified time period.- Type Parameters:
D
- The type of the data class, which must extend theData
class.- Parameters:
dataClass
- The data class containing the variable whose value difference is to be calculated.unitId
- The identifier of the unit for which the value difference is being calculated.variable
- The name of the variable whose value difference is to be calculated.periodType
- The type of the time period (e.g., HOURLY, DAILY) for which the value difference is calculated.periodCount
- The number of periods to look back from the current time.- Returns:
- The calculated value difference of the variable over the specified period, or
null
if the calculation fails.
-
getStateChanged
public static <D extends Data> Integer getStateChanged(Class<D> dataClass, Id unitId, String variable, long from, long to, boolean toTrue) Determines the number of state changes for a specified variable of a given data class for a specific unit within a specified time range. A state change is counted when the variable transitions to the specified target state.- Type Parameters:
D
- Type of the data class that extendsData
.- Parameters:
dataClass
- The data class in which the state changes are being queried.unitId
- The identifier of the unit for which the state changes are being tracked.variable
- The variable name to monitor for state changes.from
- The starting time (exclusive) of the time range in milliseconds.to
- The ending time (inclusive) of the time range in milliseconds.toTrue
- Target state to track changes towards. Iftrue
, counts transitions totrue
. Iffalse
, counts transitions tofalse
.- Returns:
- The number of state changes to the target state between the specified time range,
or
null
if an error occurs during computation.
-
getStateChanged
public static <D extends Data> Integer getStateChanged(Class<D> dataClass, Id unitId, String variable, PeriodType periodType, int periodCount, boolean toTrue) Determines the state changes of a specific variable within a given period of time.- Parameters:
dataClass
- the class type of the dataunitId
- the unique identifier of the unitvariable
- the name of the variable to monitor for state changesperiodType
- the type of time period to consider (e.g., hours, days)periodCount
- the number of periods to look back from the current timetoTrue
- boolean indicating if the state change to be counted is towards true- Returns:
- the count of state changes for the specified variable within the given period
-
getValueCount
public static <D extends Data> int getValueCount(Class<D> dataClass, Id unitId, String variable, int value, long from, long to) Computes the number of occurrences of a specific variable with a specified value for a given data class and unit within a defined time range.- Type Parameters:
D
- The type of data class, which must extend theData
class.- Parameters:
dataClass
- The data class in which the count is being queried.unitId
- The identifier of the unit whose data is being queried.variable
- The name of the variable to query for.value
- The value of the variable to count occurrences of.from
- The start time (inclusive) of the time range in milliseconds.to
- The end time (inclusive) of the time range in milliseconds.- Returns:
- The number of occurrences of the specified value for the variable within the specified time range.
-
getValueCount
public static <D extends Data> int getValueCount(Class<D> dataClass, Id unitId, String variable, int value, PeriodType periodType, int periodCount) Calculates the number of occurrences of a specific variable with a given value for a specified data class and unit within a defined time period.- Type Parameters:
D
- The type of the data class, which must extend theData
class.- Parameters:
dataClass
- The data class in which the count is being queried.unitId
- The identifier of the unit whose data is being queried.variable
- The name of the variable to query for.value
- The value of the variable to count occurrences of.periodType
- The type of the time period (e.g., HOURLY, DAILY) for the query.periodCount
- The number
-