From 4508e87a57c54675ac9d94818ea5e0f4c0f7d4e6 Mon Sep 17 00:00:00 2001 From: Will Hawkins Date: Sat, 5 Nov 2022 20:37:48 -0400 Subject: [Refactor] Rename/update MovingAverage to MathematicalSeries We want the MovingAverage functionality to be more generic and useful than just doing a moving average calculation. The new functionality allows for the calculation of the standard deviation and supports a generic type (so it can be used with integers and floats). --- utilities/utilities.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'utilities/utilities.go') diff --git a/utilities/utilities.go b/utilities/utilities.go index 5143da5..01e2cdd 100644 --- a/utilities/utilities.go +++ b/utilities/utilities.go @@ -24,23 +24,34 @@ import ( "strings" "sync/atomic" "time" + + "golang.org/x/exp/constraints" ) +func Iota(low int, high int) (made []int) { + + made = make([]int, high-low) + for counter := low; counter < high; counter++ { + made[counter-low] = counter + } + return +} + func IsInterfaceNil(ifc interface{}) bool { return ifc == nil || (reflect.ValueOf(ifc).Kind() == reflect.Ptr && reflect.ValueOf(ifc).IsNil()) } -func SignedPercentDifference( - current float64, - previous float64, +func SignedPercentDifference[T constraints.Float | constraints.Integer]( + current T, + previous T, ) (difference float64) { //return ((current - previous) / (float64(current+previous) / 2.0)) * float64( //100, // ) - return ((current - previous) / previous) * float64( - 100, - ) + fCurrent := float64(current) + fPrevious := float64(previous) + return ((fCurrent - fPrevious) / fPrevious) * 100.0 } func AbsPercentDifference( -- cgit v1.2.3