Package com.pervasivecode.utils.stats
Class SimpleDurationEstimator
- java.lang.Object
-
- com.pervasivecode.utils.stats.SimpleDurationEstimator
-
- All Implemented Interfaces:
DurationEstimator
public class SimpleDurationEstimator extends Object implements DurationEstimator
This is a trivial DurationEstimator that just uses the total amount processed divided by the total time elapsed to estimate the rate (that is, it's blind to any short-term fluctuations in rate that may occur, and only examines the entire process).Example: If an instance was created 4 seconds ago according to the TimeSource passed to the constructor, and recordAmountSoFar has been called once per second with values {0, 0, 0, 1000}, the estimated rate returned after each recordAmountSoFar call would be {0.0f, 0.0f, 0.0f, 250.0f}.
Time values are internally limited to milliseconds precision.
-
-
Constructor Summary
Constructors Constructor Description SimpleDurationEstimator(com.pervasivecode.utils.time.api.TimeSource timeSource)
Create and start a SimpleDurationEstimator, with an initial progress value of zero.SimpleDurationEstimator(com.pervasivecode.utils.time.api.TimeSource timeSource, long initialProgressValue)
Create and start a SimpleDurationEstimator, with an initial progress value specified by the caller.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description float
estimatedRateAsAmountPerSecond()
Get an estimate of the rate of change of the progress amount per second.Optional<Duration>
estimateTimeToProcessAmount(long amountLeft)
Using the current estimatedRateAsAmountPerSecond, predict how much time would be needed to process a specified amount starting now.void
recordAmountSoFar(long newAmount)
Replace the existing progress amount value with a new one.
-
-
-
Constructor Detail
-
SimpleDurationEstimator
public SimpleDurationEstimator(com.pervasivecode.utils.time.api.TimeSource timeSource)
Create and start a SimpleDurationEstimator, with an initial progress value of zero.- Parameters:
timeSource
- The source of time to be used to determine how much time has elapsed.
-
SimpleDurationEstimator
public SimpleDurationEstimator(com.pervasivecode.utils.time.api.TimeSource timeSource, long initialProgressValue)
Create and start a SimpleDurationEstimator, with an initial progress value specified by the caller.- Parameters:
timeSource
- The source of time to be used to determine how much time has elapsed.initialProgressValue
- The initial value to be used when estimating progress.
-
-
Method Detail
-
recordAmountSoFar
public void recordAmountSoFar(long newAmount)
Replace the existing progress amount value with a new one.- Specified by:
recordAmountSoFar
in interfaceDurationEstimator
- Parameters:
newAmount
- The new progress amount.
-
estimatedRateAsAmountPerSecond
public float estimatedRateAsAmountPerSecond()
Get an estimate of the rate of change of the progress amount per second.- Specified by:
estimatedRateAsAmountPerSecond
in interfaceDurationEstimator
- Returns:
- The estimated rate.
-
estimateTimeToProcessAmount
public Optional<Duration> estimateTimeToProcessAmount(long amountLeft)
Using the current estimatedRateAsAmountPerSecond, predict how much time would be needed to process a specified amount starting now.- Specified by:
estimateTimeToProcessAmount
in interfaceDurationEstimator
- Parameters:
amountLeft
- The amount whose processing time is to be estimated.- Returns:
- The amount of time that would be required to process the specified amount, given the current estimated rate.
-
-