summaryrefslogtreecommitdiff
path: root/stabilizer/rev3.go
diff options
context:
space:
mode:
Diffstat (limited to 'stabilizer/rev3.go')
-rw-r--r--stabilizer/rev3.go50
1 files changed, 41 insertions, 9 deletions
diff --git a/stabilizer/rev3.go b/stabilizer/rev3.go
index e81fc76..2e29626 100644
--- a/stabilizer/rev3.go
+++ b/stabilizer/rev3.go
@@ -40,8 +40,14 @@ func NewProbeStabilizer(i int, k int, s float64, debugLevel debug.DebugLevel, de
func (r3 *ProbeStabilizer) AddMeasurement(measurement rpm.ProbeDataPoint) {
r3.m.Lock()
defer r3.m.Unlock()
- // Add this instantaneous measurement to the mix of the I previous instantaneous measurements.
- r3.instantaneousMeasurements.AddElement(measurement.Duration.Seconds())
+
+ // There may be more than one round trip accumulated together. If that is the case,
+ // we will blow them apart in to three separate measurements and each one will just
+ // be 1 / measurement.RoundTripCount of the total length.
+ for range utilities.Iota(0, int(measurement.RoundTripCount)) {
+ // Add this instantaneous measurement to the mix of the I previous instantaneous measurements.
+ r3.instantaneousMeasurements.AddElement(measurement.Duration.Seconds() / float64(measurement.RoundTripCount))
+ }
// Calculate the moving average of the I previous instantaneous measurements and add it to
// the mix of K previous moving averages.
r3.movingAverages.AddElement(r3.instantaneousMeasurements.CalculateAverage())
@@ -58,14 +64,27 @@ func (r3 *ProbeStabilizer) AddMeasurement(measurement rpm.ProbeDataPoint) {
func (r3 *ProbeStabilizer) IsStable() bool {
// calculate whether the standard deviation of the K previous moving averages falls below S.
- islt, stddev := r3.movingAverages.StandardDeviationLessThan(r3.stabilityStandardDeviation)
+ isvalid, stddev := r3.movingAverages.StandardDeviation()
+
+ if !isvalid {
+ // If there are not enough values in the series to be able to calculate a
+ // standard deviation, then we know that we are not yet stable. Vamoose.
+ return false
+ }
+
+ // Stability is determined by whether or not the standard deviation of the values
+ // is within 5% of the average.
+ stabilityCutoff := r3.movingAverages.CalculateAverage() * (r3.stabilityStandardDeviation / 100.0)
+ isStable := stddev <= stabilityCutoff
if debug.IsDebug(r3.dbgLevel) {
fmt.Printf(
- "%s: Standard Deviation: %f s; Is Normally Distributed? %v).\n",
+ "%s: Is Stable? %v; Standard Deviation: %f s; Is Normally Distributed? %v; Standard Deviation Cutoff: %v s).\n",
r3.dbgConfig.String(),
+ isStable,
stddev,
r3.movingAverages.IsNormallyDistributed(),
+ stabilityCutoff,
)
fmt.Printf("%s: Values: ", r3.dbgConfig.String())
for _, v := range r3.movingAverages.Values() {
@@ -73,7 +92,8 @@ func (r3 *ProbeStabilizer) IsStable() bool {
}
fmt.Printf("\n")
}
- return islt
+
+ return isStable
}
func NewThroughputStabilizer(i int, k int, s float64, debugLevel debug.DebugLevel, debug *debug.DebugWithPrefix) ThroughputStabilizer {
@@ -104,15 +124,27 @@ func (r3 *ThroughputStabilizer) AddMeasurement(measurement rpm.ThroughputDataPoi
}
func (r3 *ThroughputStabilizer) IsStable() bool {
- // calculate whether the standard deviation of the K previous moving averages falls below S.
- islt, stddev := r3.movingAverages.StandardDeviationLessThan(r3.stabilityStandardDeviation)
+ isvalid, stddev := r3.movingAverages.StandardDeviation()
+
+ if !isvalid {
+ // If there are not enough values in the series to be able to calculate a
+ // standard deviation, then we know that we are not yet stable. Vamoose.
+ return false
+ }
+
+ // Stability is determined by whether or not the standard deviation of the values
+ // is within 5% of the average.
+ stabilityCutoff := r3.movingAverages.CalculateAverage() * (r3.stabilityStandardDeviation / 100.0)
+ isStable := stddev <= stabilityCutoff
if debug.IsDebug(r3.dbgLevel) {
fmt.Printf(
- "%s: Standard Deviation: %f Mbps; Is Normally Distributed? %v).\n",
+ "%s: Is Stable? %v; Standard Deviation: %f Mbps; Is Normally Distributed? %v; Standard Deviation Cutoff: %v Mbps).\n",
r3.dbgConfig.String(),
+ isStable,
stddev,
r3.movingAverages.IsNormallyDistributed(),
+ stabilityCutoff,
)
fmt.Printf("%s: Values: ", r3.dbgConfig.String())
for _, v := range r3.movingAverages.Values() {
@@ -120,5 +152,5 @@ func (r3 *ThroughputStabilizer) IsStable() bool {
}
fmt.Printf("\n")
}
- return islt
+ return isStable
}