summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Hawkins <[email protected]>2021-12-16 00:38:05 -0500
committerWill Hawkins <[email protected]>2021-12-16 00:38:05 -0500
commitbb48aa9f23d3b74aa3e31f395deaf6fdd1618391 (patch)
treeddaf9901e191e42011fd80ad76a5c5035bb41280
parentc24e70fd98bb61ddf735a7f54e278258f2dfc990 (diff)
Bugfix: Incorrect AllSequentialIncreasesLessThan (nee IncreasesLessThan) Calculation
In AllSequentialIncreasesLessThan (nee IncreasesLessThan), an earlier version of this function did not properly take into account the order in which values were added to the moving average when calculating the percent change. This patch fixes that error and adds an additional criteria for the function to return `true`: there must be *at least* `intervals` collected samples.
-rw-r--r--ma/ma.go14
-rw-r--r--networkQuality.go2
2 files changed, 12 insertions, 4 deletions
diff --git a/ma/ma.go b/ma/ma.go
index b591d19..8d06a67 100644
--- a/ma/ma.go
+++ b/ma/ma.go
@@ -32,10 +32,18 @@ func (ma *MovingAverage) CalculateAverage() float64 {
return float64(total) / float64(ma.divisor.Value())
}
-func (ma *MovingAverage) IncreasesLessThan(limit float64) bool {
- previous := ma.instants[0]
+func (ma *MovingAverage) AllSequentialIncreasesLessThan(limit float64) bool {
+
+ // If we have not yet accumulated a complete set of intervals,
+ // this is false.
+ if ma.divisor.Value() != ma.intervals {
+ return false
+ }
+
+ previous := ma.instants[ma.index]
for i := 1; i < ma.intervals; i++ {
- current := ma.instants[i]
+ currentIndex := (ma.index + i) % ma.intervals
+ current := ma.instants[currentIndex]
percentChange := utilities.SignedPercentDifference(current, previous)
previous = current
if percentChange > limit {
diff --git a/networkQuality.go b/networkQuality.go
index 54c4260..e052e1f 100644
--- a/networkQuality.go
+++ b/networkQuality.go
@@ -242,7 +242,7 @@ func saturate(saturationCtx context.Context, operatingCtx context.Context, lbcGe
fmt.Printf("%v: Network reached saturation with current flow count.\n", debug)
}
// If new flows added and for 4 seconds the moving average throughput did not change: network reached stable saturation
- if (currentIteration-previousFlowIncreaseIteration) < 4 && movingAverageAverage.IncreasesLessThan(float64(5)) {
+ if (currentIteration-previousFlowIncreaseIteration) < 4 && movingAverageAverage.AllSequentialIncreasesLessThan(float64(5)) {
if debug != nil {
fmt.Printf("%v: New flows added within the last four seconds and the moving-average average is consistent!\n", debug)
}