Class TimeStatistics
- All Implemented Interfaces:
ITimeStatistics
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
- Author:
- Andrey Malykhanov
-
Constructor Summary
Constructors -
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.getSum(ITimeStatistics otherTimeStatistics) Returns a new instance ofITimeStatisticswhich is the sum of this instance and the other specified instance.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 callingITimeStatistics.add(double, double)orITimeStatistics.replace(double, double)method, orDouble.NEGATIVE_INFINITYif none of these methods have yet been called.doubleReturns the value in the time bucket that corresponds toITimeStatistics.lastTime(), or 0 ifITimeStatistics.lastTime()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.doubletimeOfCumulative(double cumulativeValue) Returns aDoubleSummaryStatisticsinstance that contains the statistics across all existing time buckets.doublevalueAt(double time) Returns the value in the bucket containing the specified time.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.amalgamasimulation.utils.ITimeStatistics
getInterpolatedSum, toCodeString
-
Constructor Details
-
TimeStatistics
public TimeStatistics(double granularity)
-
-
Method Details
-
replace
public void replace(double time, double value) Description copied from interface:ITimeStatisticsReplaces the value in the time bucket corresponding to the specified time with the specified value. Makes the bucket containing the specified time non-empty.- Specified by:
replacein interfaceITimeStatistics- 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
public void add(double time, double value) Description copied from interface:ITimeStatisticsAdds the specified value to the time bucket corresponding to the specified time. Makes the bucket containing the specified time non-empty.- Specified by:
addin interfaceITimeStatistics- 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
public double lastTime()Description copied from interface:ITimeStatisticsReturns the last time that was set by callingITimeStatistics.add(double, double)orITimeStatistics.replace(double, double)method, orDouble.NEGATIVE_INFINITYif none of these methods have yet been called.- Specified by:
lastTimein interfaceITimeStatistics- Returns:
- last time that was set by calling
ITimeStatistics.add(double, double)orITimeStatistics.replace(double, double)method, orDouble.NEGATIVE_INFINITY
-
lastValue
public double lastValue()Description copied from interface:ITimeStatisticsReturns the value in the time bucket that corresponds toITimeStatistics.lastTime(), or 0 ifITimeStatistics.lastTime()is equal toDouble.NEGATIVE_INFINITY, i.e. if none of these methods have yet been called.- Specified by:
lastValuein interfaceITimeStatistics- Returns:
- value in the time bucket that corresponds to
ITimeStatistics.lastTime(), or 0
-
totalStatistics
Description copied from interface:ITimeStatisticsReturns aDoubleSummaryStatisticsinstance that contains the statistics across all existing time buckets.- Specified by:
totalStatisticsin interfaceITimeStatistics- Returns:
DoubleSummaryStatisticsinstance that contains the statistics across all values in the existing time bucketsThe figure below illustrates the result of calling this method:

-
interpolatedStatistics
public DoubleSummaryStatistics interpolatedStatistics(double beginTime, double endTime, boolean includeZeros) Description copied from interface:ITimeStatisticsReturns 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.
- Specified by:
interpolatedStatisticsin interfaceITimeStatistics- 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
Description copied from interface:ITimeStatisticsReturns 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.
- Specified by:
interpolatedStatisticsin interfaceITimeStatistics- 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
public double valueAt(double time) Description copied from interface:ITimeStatisticsReturns the value in the bucket containing the specified time. If the specified time is associated with an empty bucket, zero is returned.- Specified by:
valueAtin interfaceITimeStatistics- Parameters:
time- specified time- Returns:
- value in the bucket containing the specified time, or zero
-
interpolatedValueAt
public double interpolatedValueAt(double time) Description copied from interface:ITimeStatisticsReturns 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.
- Specified by:
interpolatedValueAtin interfaceITimeStatistics- Parameters:
time- specified time- Returns:
- linearly interpolated value at the specified time
The figure below illustrates the result of interpolation:

-
sumBetween
public double sumBetween(double beginTime, double endTime) Description copied from interface:ITimeStatisticsReturns 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
ITimeStatistics.interpolatedStatistics(double, double)method.- Specified by:
sumBetweenin interfaceITimeStatistics- 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
-
getSum
Description copied from interface:ITimeStatisticsReturns 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.- Specified by:
getSumin interfaceITimeStatistics- Parameters:
otherTimeStatistics-ITimeStatisticswhich is summed with this one- Returns:
- new instance of
ITimeStatistics
-
minTime
public double minTime()Description copied from interface:ITimeStatisticsReturns zero, which is the minimum argument for a typical time series statistics.- Specified by:
minTimein interfaceITimeStatistics- Returns:
- always returns zero
-
maxTime
public double maxTime()Description copied from interface:ITimeStatisticsReturns the time corresponding to the right border of a non-empty bucket with the biggest argument.- Specified by:
maxTimein interfaceITimeStatistics- Returns:
- time of a non-empty bucket with the biggest argument
-
granularity
public double granularity()Description copied from interface:ITimeStatisticsReturns the granularity of this time statistics. Granularity is the size of time buckets at which the values are accumulated and aggregated.- Specified by:
granularityin interfaceITimeStatistics- Returns:
- granularity of this time statistics
-
plotData
Description copied from interface:ITimeStatisticsReturns 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.- Specified by:
plotDatain interfaceITimeStatistics- Returns:
Listof argument-valuePairs
-
cumulativePlotData
Description copied from interface:ITimeStatisticsReturns 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.- Specified by:
cumulativePlotDatain interfaceITimeStatistics- Returns:
Listof argument-valuePairs
-
timeOfCumulative
public double timeOfCumulative(double cumulativeValue) -
copy
Description copied from interface:ITimeStatisticsReturns a copy of thisITimeStatisticsinstance.- Specified by:
copyin interfaceITimeStatistics- Returns:
- copy of this
ITimeStatisticsinstance
-
dataSize
public int dataSize()Description copied from interface:ITimeStatisticsReturns the number of data points stored inside thisITimeStatisticsinstance.- Specified by:
dataSizein interfaceITimeStatistics- Returns:
- number of data points stored inside this
ITimeStatisticsinstance
-
nonEmptyBucketsStream
Description copied from interface:ITimeStatisticsReturns aStreamof argument-valuePairs. Each pair represents a non-empty (but potentially zero) bucket. Stream is ordered by time (the first element of a pair) in ascending order.- Specified by:
nonEmptyBucketsStreamin interfaceITimeStatistics- Returns:
Streamof argument-valuePairs
-