Interface ITimeStatistics
- All Known Implementing Classes:
AdaptiveTimeStatistics,SparseTimeStatistics,TimeStatistics
Typical uses of this class include:
- Collecting daily inventory statistics in supply chain or manufacturing models
- Collecting truck runs count statistics by months
- Collecting amount of material transported by hours
This class makes difference between empty time buckets and time buckets with
zero values. So, explicitly adding zero value to a time bucket may result in
changes of the overall statistics output, such as a different result of
totalStatistics() method.

- Author:
- Andrey Malykhanov
-
Method Summary
Modifier and TypeMethodDescriptionvoidadd(double time, double value) Adds the specified value to the time bucket corresponding to the specified time.copy()Returns a copy of thisITimeStatisticsinstance.Returns the data for plotting the cumulative sum of the content of thisTimeStatisticsinstance on a line chart.intdataSize()Returns the number of data points stored inside thisITimeStatisticsinstance.default ITimeStatisticsgetInterpolatedSum(ITimeStatistics otherTimeStatistics) Returns a new instance ofITimeStatisticswhich is the interpolated sum of this instance and the other specified instance.default ITimeStatisticsgetSum(ITimeStatistics otherTimeStatistics) Returns a new instance ofITimeStatisticswhich is the sum of this instance and the other specified instance.static ITimeStatisticsgetSum(List<ITimeStatistics> elements, double granularity) static ITimeStatisticsgetSum(Stream<ITimeStatistics> elements, double granularity) doubleReturns the granularity of this time statistics.interpolatedStatistics(double beginTime, double endTime) Returns aDoubleSummaryStatisticsinstance that contains the statistics across all time buckets between the buckets containing the specified begin and end times.interpolatedStatistics(double beginTime, double endTime, boolean includeZeros) Returns aDoubleSummaryStatisticsinstance that contains the statistics across all time buckets between the buckets containing the specified begin and end times.doubleinterpolatedValueAt(double time) Returns the value in the bucket containing the specified time.doublelastTime()Returns the last time that was set by callingadd(double, double)orreplace(double, double)method, orDouble.NEGATIVE_INFINITYif none of these methods have yet been called.doubleReturns the value in the time bucket that corresponds tolastTime(), or 0 iflastTime()is equal toDouble.NEGATIVE_INFINITY, i.e.doublemaxTime()Returns the time corresponding to the right border of a non-empty bucket with the biggest argument.doubleminTime()Returns zero, which is the minimum argument for a typical time series statistics.plotData()Returns the data for plotting the content of thisITimeStatisticsinstance on a line chart.voidreplace(double time, double value) Replaces the value in the time bucket corresponding to the specified time with the specified value.doublesumBetween(double beginTime, double endTime) Returns the sum of values in all non-empty buckets the buckets containing the specified begin and end times.default StringReturns aDoubleSummaryStatisticsinstance that contains the statistics across all existing time buckets.doublevalueAt(double time) Returns the value in the bucket containing the specified time.
-
Method Details
-
replace
void replace(double time, double value) Replaces the value in the time bucket corresponding to the specified time with the specified value. Makes the bucket containing the specified time non-empty.- Parameters:
time- specified time, used to determine the time bucketvalue- specified value, can be both positive and negative. This value is set to the corresponding time bucketThe figure below illustrates the result of calling this method:

-
add
void add(double time, double value) Adds the specified value to the time bucket corresponding to the specified time. Makes the bucket containing the specified time non-empty.- Parameters:
time- specified time, used to determine the time bucketvalue- specified value, can be both positive and negativeThe figure below illustrates the result of calling this method:

-
lastTime
double lastTime()Returns the last time that was set by callingadd(double, double)orreplace(double, double)method, orDouble.NEGATIVE_INFINITYif none of these methods have yet been called.- Returns:
- last time that was set by calling
add(double, double)orreplace(double, double)method, orDouble.NEGATIVE_INFINITY
-
lastValue
double lastValue()Returns the value in the time bucket that corresponds tolastTime(), or 0 iflastTime()is equal toDouble.NEGATIVE_INFINITY, i.e. if none of these methods have yet been called.- Returns:
- value in the time bucket that corresponds to
lastTime(), or 0
-
totalStatistics
DoubleSummaryStatistics totalStatistics()Returns aDoubleSummaryStatisticsinstance that contains the statistics across all existing time buckets.- Returns:
DoubleSummaryStatisticsinstance that contains the statistics across all values in the existing time bucketsThe figure below illustrates the result of calling this method:

-
interpolatedStatistics
DoubleSummaryStatistics interpolatedStatistics(double beginTime, double endTime, boolean includeZeros) Returns aDoubleSummaryStatisticsinstance that contains the statistics across all time buckets between the buckets containing the specified begin and end times. Interpolates the data for empty time buckets: assumes the value in an empty time bucket is equal to the value in the previous non-empty time bucket, or 0 if there is no such bucket.Specifies whether to include zero values into the statistics or not.
- Parameters:
beginTime- begin time, points to the first time bucket of collecting the statisticsendTime- end time, points to the last time bucket of collecting the statisticsincludeZeros- whether or not to include zeroes while calculating statistics- Returns:
DoubleSummaryStatisticsinstance that contains the statistics across all time buckets between the specified begin and end timesThe figure below illustrates the result of calling this method:

-
interpolatedStatistics
Returns aDoubleSummaryStatisticsinstance that contains the statistics across all time buckets between the buckets containing the specified begin and end times. Interpolates the data for empty time buckets: assumes the value in an empty time bucket is equal to the value in the previous non-empty time bucket, or 0 if there is no such bucket.Includes zero values into the statistics.
- Parameters:
beginTime- begin time, points to the first time bucket of collecting the statisticsendTime- end time, points to the last time bucket of collecting the statistics- Returns:
DoubleSummaryStatisticsinstance that contains the statistics across all time buckets between the specified begin and end timesThe figure below illustrates the result of calling this method:

-
valueAt
double valueAt(double time) Returns the value in the bucket containing the specified time. If the specified time is associated with an empty bucket, zero is returned.- Parameters:
time- specified time- Returns:
- value in the bucket containing the specified time, or zero
-
interpolatedValueAt
double interpolatedValueAt(double time) Returns the value in the bucket containing the specified time. If no values were added to the bucket containing the specified time, then returns the value in the last non-empty preceding the current bucket.In other words, returns a linearly interpolated value at the specified time.
If there are no non-empty buckets at of before the specified time, returns zero.
- Parameters:
time- specified time- Returns:
- linearly interpolated value at the specified time
The figure below illustrates the result of interpolation:

-
sumBetween
double sumBetween(double beginTime, double endTime) Returns the sum of values in all non-empty buckets the buckets containing the specified begin and end times. Does not do interpolation, i.e. does not consider empty buckets.If the sum is needed with interpolated values, use
interpolatedStatistics(double, double)method.- Parameters:
beginTime- begin time, points to the first time bucket of summationendTime- end time, points to the last time bucket of summation- Returns:
- sum of values in all non-empty buckets between the specified begin and end times
-
minTime
double minTime()Returns zero, which is the minimum argument for a typical time series statistics.- Returns:
- always returns zero
-
maxTime
double maxTime()Returns the time corresponding to the right border of a non-empty bucket with the biggest argument.- Returns:
- time of a non-empty bucket with the biggest argument
-
granularity
double granularity()Returns the granularity of this time statistics. Granularity is the size of time buckets at which the values are accumulated and aggregated.- Returns:
- granularity of this time statistics
-
plotData
Returns the data for plotting the content of thisITimeStatisticsinstance on a line chart. The data is returned in the form ofListof argument-valuePairs. The returned list is sorted by arguments in ascending order. -
cumulativePlotData
Returns the data for plotting the cumulative sum of the content of thisTimeStatisticsinstance on a line chart. The data is returned in the form ofListof argument-valuePairs. The returned list is sorted by arguments in ascending order. -
copy
ITimeStatistics copy()Returns a copy of thisITimeStatisticsinstance.- Returns:
- copy of this
ITimeStatisticsinstance
-
dataSize
int dataSize()Returns the number of data points stored inside thisITimeStatisticsinstance.- Returns:
- number of data points stored inside this
ITimeStatisticsinstance
-
getSum
Returns a new instance ofITimeStatisticswhich is the sum of this instance and the other specified instance.Sum of two
ITimeStatisticsinstances is an bucket-wise sum of them without considering any interpolation.- Parameters:
otherTimeStatistics-ITimeStatisticswhich is summed with this one- Returns:
- new instance of
ITimeStatistics
-
getInterpolatedSum
Returns a new instance ofITimeStatisticswhich is the interpolated sum of this instance and the other specified instance.- Parameters:
otherTimeStatistics-ITimeStatisticswhich is summed with this one- Returns:
- new instance of
ITimeStatistics
-
getSum
-
getSum
-
nonEmptyBucketsStream
-
toCodeString
-