From 5e0e8ba0be2c98b5f54e55fdbc1b928a4717e047 Mon Sep 17 00:00:00 2001 From: Will Hawkins Date: Sun, 20 Nov 2022 00:10:15 -0500 Subject: [Feature] Make MathematicalSeries an interface 1. Make MathematicalSeries an interface so that there can be different ways for implementing it. 2. Introduce a CappedMathematicalSeries that stores a maximum of N recent (by time of insertion) values. 3. Add a method to the MathematicalSeries interface for calculating the Nth percentile of the values it contains. --- stabilizer/rev3.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'stabilizer/rev3.go') diff --git a/stabilizer/rev3.go b/stabilizer/rev3.go index 2e29626..79f5f27 100644 --- a/stabilizer/rev3.go +++ b/stabilizer/rev3.go @@ -11,8 +11,8 @@ import ( ) type DataPointStabilizer struct { - instantaneousMeasurements *ms.MathematicalSeries[float64] - movingAverages *ms.MathematicalSeries[float64] + instantaneousMeasurements ms.MathematicalSeries[float64] + movingAverages ms.MathematicalSeries[float64] stabilityStandardDeviation float64 m sync.Mutex dbgLevel debug.DebugLevel @@ -30,8 +30,8 @@ type ThroughputStabilizer DataPointStabilizer // moving averages of a measurement. func NewProbeStabilizer(i int, k int, s float64, debugLevel debug.DebugLevel, debug *debug.DebugWithPrefix) ProbeStabilizer { - return ProbeStabilizer{instantaneousMeasurements: ms.NewMathematicalSeries[float64](i), - movingAverages: ms.NewMathematicalSeries[float64](k), + return ProbeStabilizer{instantaneousMeasurements: ms.NewCappedMathematicalSeries[float64](i), + movingAverages: ms.NewCappedMathematicalSeries[float64](k), stabilityStandardDeviation: s, dbgConfig: debug, dbgLevel: debugLevel} @@ -97,8 +97,8 @@ func (r3 *ProbeStabilizer) IsStable() bool { } func NewThroughputStabilizer(i int, k int, s float64, debugLevel debug.DebugLevel, debug *debug.DebugWithPrefix) ThroughputStabilizer { - return ThroughputStabilizer{instantaneousMeasurements: ms.NewMathematicalSeries[float64](i), - movingAverages: ms.NewMathematicalSeries[float64](k), + return ThroughputStabilizer{instantaneousMeasurements: ms.NewCappedMathematicalSeries[float64](i), + movingAverages: ms.NewCappedMathematicalSeries[float64](k), stabilityStandardDeviation: s, dbgConfig: debug, dbgLevel: debugLevel} -- cgit v1.2.3