https://github.com/raspi/timeaverage
Moving average window
https://github.com/raspi/timeaverage
average go golang time
Last synced: 12 months ago
JSON representation
Moving average window
- Host: GitHub
- URL: https://github.com/raspi/timeaverage
- Owner: raspi
- License: apache-2.0
- Created: 2019-12-20T16:44:33.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-20T17:25:26.000Z (about 6 years ago)
- Last Synced: 2023-03-11T06:32:54.755Z (almost 3 years ago)
- Topics: average, go, golang, time
- Language: Go
- Homepage:
- Size: 10.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# timeaverage
Call a function which returns a float every X duration and keep history of N values and return average value of that window.
## Install
go get -u github.com/raspi/timeaverage
## Example
Take measurement every 500 ms and keep history of 10 seconds.
```go
package main
import (
"github.com/raspi/timeaverage"
"log"
"time"
)
func exampleSampler() (float64, error) {
return 1, nil
}
func main() {
avg := timeaverage.New(time.Second*10, time.Millisecond*500, 0.0, exampleSampler)
avg.Start()
for {
v := avg.Average()
log.Printf(`%f`, v)
time.Sleep(time.Second * 1)
}
}
```
See [_examples](_examples/) directory for more examples.