2015-09-15 12:48:43 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2017-09-22 15:42:57 +00:00
|
|
|
// "time"
|
2015-09-15 12:48:43 +00:00
|
|
|
"bufio"
|
2017-09-22 15:42:57 +00:00
|
|
|
"gonum.org/v1/plot"
|
|
|
|
"gonum.org/v1/plot/plotter"
|
|
|
|
"gonum.org/v1/plot/plotutil"
|
|
|
|
"gonum.org/v1/plot/vg"
|
|
|
|
"os"
|
|
|
|
"sort"
|
|
|
|
"strconv"
|
2015-09-15 12:48:43 +00:00
|
|
|
"strings"
|
|
|
|
"unicode"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
if len(os.Args) < 2 {
|
|
|
|
fmt.Printf("%s <replay log>\n", os.Args[0])
|
|
|
|
return
|
|
|
|
}
|
|
|
|
f, err := os.Open(os.Args[1])
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("error opening '%s': %s\n", os.Args[1], err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
rdr := bufio.NewReader(f)
|
|
|
|
|
|
|
|
// For now, "windows" are 1 minute intervals.
|
|
|
|
ppm := make(map[int64]int64) // window number -> pkts
|
|
|
|
curWindow := int64(0)
|
|
|
|
windowOffset := int64(0)
|
|
|
|
for {
|
|
|
|
buf, err := rdr.ReadString('\n')
|
|
|
|
if err != nil {
|
|
|
|
break
|
|
|
|
}
|
2017-09-22 15:42:57 +00:00
|
|
|
buf = strings.TrimFunc(buf, func(r rune) bool { return unicode.IsControl(r) })
|
2015-09-15 12:48:43 +00:00
|
|
|
linesplit := strings.Split(buf, ",")
|
|
|
|
if len(linesplit) < 2 { // Blank line or invalid.
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if linesplit[0] == "START" { // Reset ticker, new start.
|
|
|
|
windowOffset = curWindow
|
|
|
|
} else { // If it's not "START", then it's a tick count.
|
|
|
|
i, err := strconv.ParseInt(linesplit[0], 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("invalid tick: '%s'\n\n\n%s\n", linesplit[0], buf)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Window number in current session.
|
|
|
|
wnum := int64(i / (60 * 1000000000))
|
2017-09-22 15:42:57 +00:00
|
|
|
// fmt.Printf("%d\n", curWindow)
|
|
|
|
if wnum+windowOffset != curWindow { // Switched over.
|
2015-09-15 12:48:43 +00:00
|
|
|
curWindow = wnum + windowOffset
|
2017-09-22 15:42:57 +00:00
|
|
|
fmt.Printf("ppm=%d\n", ppm[curWindow-1])
|
2015-09-15 12:48:43 +00:00
|
|
|
}
|
|
|
|
ppm[curWindow]++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make graph.
|
|
|
|
p, err := plot.New()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
p.Title.Text = "Stratux PPM vs. Time"
|
|
|
|
p.X.Label.Text = "1 min intervals"
|
|
|
|
p.Y.Label.Text = "PPM"
|
|
|
|
|
|
|
|
// Loop through an ordered list of the periods, so that the line connects the right dots.
|
|
|
|
var keys []int
|
|
|
|
for k := range ppm {
|
|
|
|
keys = append(keys, int(k))
|
|
|
|
}
|
|
|
|
sort.Ints(keys)
|
|
|
|
|
|
|
|
pts := make(plotter.XYs, len(ppm))
|
|
|
|
i := 0
|
2017-09-22 15:42:57 +00:00
|
|
|
for _, k := range keys {
|
2015-09-15 12:48:43 +00:00
|
|
|
v := ppm[int64(k)]
|
|
|
|
fmt.Printf("%d, %d\n", k, v)
|
|
|
|
pts[i].X = float64(k)
|
|
|
|
pts[i].Y = float64(v)
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
|
|
|
|
err = plotutil.AddLinePoints(p, "UAT", pts)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2017-09-22 15:42:57 +00:00
|
|
|
if err := p.Save(4*vg.Inch, 4*vg.Inch, "ppm.png"); err != nil {
|
2015-09-15 12:48:43 +00:00
|
|
|
panic(err)
|
|
|
|
}
|
2017-09-22 15:42:57 +00:00
|
|
|
}
|