Skip to content

raspi/timeaverage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

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 directory for more examples.

Releases

No releases published

Packages

No packages published

Languages