Class StatisticsCalculator
java.lang.Object
de.cuioss.benchmarking.common.report.StatisticsCalculator
Provides pure statistical computation utilities for benchmark metrics.
This class is responsible for all statistical calculations including:
- Basic statistics (min, max, mean, median)
- Moving averages
- Percentage changes and trends
- Standard deviation and variance
Use this class when you need to perform mathematical/statistical operations on benchmark data.
For metric-specific calculations (performance scores, grades), use MetricsComputer.
For time-series analysis and trend detection, use TrendDataProcessor.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classStatistical summary containing basic statistics for a dataset. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic doublecalculateEWMA(List<Double> values, double lambda) Calculates an Exponentially Weighted Moving Average (EWMA) baseline from historical values.static doublecalculateMean(Collection<Double> values) Calculates the arithmetic mean (average) of a collection of values.static doublecalculateMedian(Collection<Double> values) Calculates the median value of a collection.static doublecalculateMovingAverage(List<Double> values, int windowSize) Calculates a simple moving average for the most recent N values.static doublecalculatePercentageChange(double oldValue, double newValue) Calculates the percentage change between two values.static doublecalculateStandardDeviation(Collection<Double> values) Calculates the standard deviation of a collection of values.computeStatistics(Collection<Double> values) Computes comprehensive statistics for a dataset.static StringdetermineTrendDirection(double percentageChange, double stabilityThreshold) Determines the trend direction based on percentage change and a stability threshold.static doublefindMax(Collection<Double> values) Finds the maximum value in a collection.static doublefindMin(Collection<Double> values) Finds the minimum value in a collection.
-
Field Details
-
COLLECTION_CANNOT_BE_NULL
- See Also:
-
-
Method Details
-
calculateMean
Calculates the arithmetic mean (average) of a collection of values.- Parameters:
values- collection of numeric values- Returns:
- the mean value, or 0.0 if the collection is empty
- Throws:
NullPointerException- if values is null
-
findMin
Finds the minimum value in a collection.- Parameters:
values- collection of numeric values- Returns:
- the minimum value, or Double.MAX_VALUE if the collection is empty
- Throws:
NullPointerException- if values is null
-
findMax
Finds the maximum value in a collection.- Parameters:
values- collection of numeric values- Returns:
- the maximum value, or Double.MIN_VALUE if the collection is empty
- Throws:
NullPointerException- if values is null
-
calculateMedian
Calculates the median value of a collection.- Parameters:
values- collection of numeric values- Returns:
- the median value, or 0.0 if the collection is empty
- Throws:
NullPointerException- if values is null
-
calculatePercentageChange
Calculates the percentage change between two values.Formula: ((newValue - oldValue) / oldValue) * 100
- Parameters:
oldValue- the original valuenewValue- the new value- Returns:
- the percentage change
-
calculateMovingAverage
Calculates a simple moving average for the most recent N values.- Parameters:
values- list of values (assumed to be in chronological order)windowSize- the number of most recent values to include- Returns:
- the moving average
- Throws:
NullPointerException- if values is nullIllegalArgumentException- if windowSize is less than 1
-
calculateStandardDeviation
Calculates the standard deviation of a collection of values.- Parameters:
values- collection of numeric values- Returns:
- the standard deviation, or 0.0 if the collection has less than 2 elements
- Throws:
NullPointerException- if values is null
-
calculateEWMA
Calculates an Exponentially Weighted Moving Average (EWMA) baseline from historical values.EWMA gives more weight to recent values while still considering historical context, making it ideal for performance monitoring and trend detection. The decay factor (lambda) determines how quickly older values lose influence.
Formula: EWMA = Σ(value_i × λ^i) / Σ(λ^i) where i=0 is the most recent value, i=1 is second most recent, etc.
- Parameters:
values- list of historical values, ordered from newest to oldestlambda- decay factor (typically 0.2-0.3 for performance monitoring). Smaller values = more weight on recent data.- Returns:
- the weighted baseline value
- Throws:
NullPointerException- if values is nullIllegalArgumentException- if lambda is not in (0, 1] range
-
determineTrendDirection
Determines the trend direction based on percentage change and a stability threshold.- Parameters:
percentageChange- the percentage change valuestabilityThreshold- the threshold (as a percentage) below which the trend is considered stable- Returns:
- "up", "down", or "stable"
-
computeStatistics
Computes comprehensive statistics for a dataset.- Parameters:
values- collection of numeric values- Returns:
- a Statistics object containing min, max, mean, median, standard deviation, and count
- Throws:
NullPointerException- if values is null
-