github.com/influxdata/influxdb/v2@v2.7.6/influxql/query/linear.go (about) 1 package query 2 3 // linearFloat computes the slope of the line between the points (previousTime, previousValue) and (nextTime, nextValue) 4 // and returns the value of the point on the line with time windowTime 5 // y = mx + b 6 func linearFloat(windowTime, previousTime, nextTime int64, previousValue, nextValue float64) float64 { 7 m := (nextValue - previousValue) / float64(nextTime-previousTime) // the slope of the line 8 x := float64(windowTime - previousTime) // how far into the interval we are 9 b := previousValue 10 return m*x + b 11 } 12 13 // linearInteger computes the slope of the line between the points (previousTime, previousValue) and (nextTime, nextValue) 14 // and returns the value of the point on the line with time windowTime 15 // y = mx + b 16 func linearInteger(windowTime, previousTime, nextTime int64, previousValue, nextValue int64) int64 { 17 m := float64(nextValue-previousValue) / float64(nextTime-previousTime) // the slope of the line 18 x := float64(windowTime - previousTime) // how far into the interval we are 19 b := float64(previousValue) 20 return int64(m*x + b) 21 } 22 23 // linearInteger computes the slope of the line between the points (previousTime, previousValue) and (nextTime, nextValue) 24 // and returns the value of the point on the line with time windowTime 25 // y = mx + b 26 func linearUnsigned(windowTime, previousTime, nextTime int64, previousValue, nextValue uint64) uint64 { 27 m := float64(nextValue-previousValue) / float64(nextTime-previousTime) // the slope of the line 28 x := float64(windowTime - previousTime) // how far into the interval we are 29 b := float64(previousValue) 30 return uint64(m*x + b) 31 }