-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmessages_per_day_timeseries.go
50 lines (45 loc) · 1.06 KB
/
messages_per_day_timeseries.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"github.com/evilsocket/islazy/log"
"github.com/evilsocket/joe/models"
"github.com/wcharczuk/go-chart"
"time"
)
func View(res *models.Results) models.Chart {
ts := chart.TimeSeries{
Style: chart.Style{
StrokeColor: chart.GetDefaultColor(0).WithAlpha(64),
FillColor: chart.GetDefaultColor(0).WithAlpha(64),
},
XValues: make([]time.Time, 0),
YValues: make([]float64, 0),
}
layout := "2006-01-02"
for _, row := range res.Rows {
if row["day"] != nil {
day := row["day"].(string)
count := float64(row["sent"].(int64))
if t, err := time.Parse(layout, day); err == nil {
ts.XValues = append(ts.XValues, t)
ts.YValues = append(ts.YValues, count)
} else {
log.Error("can't parse date '%s' as date layout %s", day, layout)
}
}
}
return chart.Chart{
Title: "Messages per Day",
TitleStyle: chart.Style{
Hidden: false,
},
Background: chart.Style{
Padding: chart.Box{
Top: 40,
},
},
XAxis: chart.XAxis{
ValueFormatter: chart.TimeDateValueFormatter,
},
Series: []chart.Series{ts},
}
}