prep / average Goto Github PK
View Code? Open in Web Editor NEWA sliding time window for Go
License: BSD 3-Clause "New" or "Revised" License
A sliding time window for Go
License: BSD 3-Clause "New" or "Revised" License
I copied the example code into a file, build with Go 1.1.0.3 and execute. The results are that it returns all zeros. (after I fixed some missing closing brackets in the example code)
$ go build average-example.go
$ go version
go version go1.10.3 windows/amd64
$ ./average-example.exe
Average of last 1m: 0.000000
Average of last 5m: 0.000000
Average of last 15m: 0.000000
Counter has a total of 0 over 0 samples
$
average_example.go:
package main
import (
"fmt"
"time"
"github.com/prep/average"
)
func main() {
// Create a SlidingWindow that has a window of 15 minutes, with a
// granulity of 1 minute.
sw := average.MustNew(15*time.Minute, time.Minute)
defer sw.Stop()
// Do some work.
sw.Add(15)
// Do some more work.
sw.Add(22)
// Do even more work.
sw.Add(22)
fmt.Printf("Average of last 1m: %f\n", sw.Average(time.Minute))
fmt.Printf("Average of last 5m: %f\n", sw.Average(5*time.Minute))
fmt.Printf("Average of last 15m: %f\n\n", sw.Average(15*time.Minute))
total, numSamples := sw.Total(15 * time.Minute)
fmt.Printf("Counter has a total of %d over %d samples", total, numSamples)
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.