func drawDashboardByHour() { lock.Lock() commitByHours := make(map[int]int) for _, evt := range events { if hook, ok := evt.(*Webhook); ok { for _, cmt := range hook.Commits { t, _ := time.Parse(time.RFC3339, cmt.Timestamp) if _, present := commitByHours[t.Hour()]; present { commitByHours[t.Hour()]++ } else { commitByHours[t.Hour()] = 1 } } } } lock.Unlock() sortedHours := make([]int, 0, len(commitByHours)) for hour, _ := range commitByHours { sortedHours = append(sortedHours, hour) } sort.Ints(sortedHours) termbox.Clear(coldef, coldef) termui.UseTheme("helloworld") bc := termui.NewBarChart() data := []int{} bclabels := []string{} for _, hour := range sortedHours { data = append(data, commitByHours[hour]) bclabels = append(bclabels, fmt.Sprintf("%02d", hour)) } bc.Border.Label = "Commit by hour" bc.Data = data bc.Width = w bc.Height = h bc.DataLabels = bclabels bc.TextColor = termui.ColorGreen bc.BarColor = termui.ColorRed bc.NumColor = termui.ColorYellow termui.Render(bc) }
func (this *Histogram) drawAll(offsetTs []time.Time, offsets []int64, netTs []time.Time, rx []int64, tx []int64) { err := termui.Init() swallow(err) defer termui.Close() termui.UseTheme("helloworld") w, h := termbox.Size() bc1 := termui.NewBarChart() bc1.Border.Label = "Messages Produced/in million" data := make([]int, 0) for _, off := range offsets { data = append(data, int(off/1000000)) // in million } bclabels := make([]string, 0) for _, t := range offsetTs { bclabels = append(bclabels, fmt.Sprintf("%02d", t.Hour())) } bc1.Data = data bc1.Width = w bc1.SetY(0) bc1.Height = h / 3 bc1.DataLabels = bclabels bc1.TextColor = termui.ColorWhite bc1.BarColor = termui.ColorRed bc1.NumColor = termui.ColorYellow bclabels = make([]string, 0) // shared between bc2 and bc3 for _, t := range netTs { bclabels = append(bclabels, fmt.Sprintf("%02d", t.Hour())) } bc2 := termui.NewBarChart() bc2.Border.Label = "Network RX/in 10GB" data = make([]int, 0) for _, r := range rx { data = append(data, int(r>>30)/10) } bc2.Data = data bc2.Width = w bc2.SetY(h / 3) bc2.Height = h / 3 bc2.DataLabels = bclabels bc2.TextColor = termui.ColorGreen bc2.BarColor = termui.ColorRed bc2.NumColor = termui.ColorYellow bc3 := termui.NewBarChart() bc3.Border.Label = "Network TX/in 10GB" data = make([]int, 0) for _, t := range tx { data = append(data, int(t>>30)/10) } bc3.Data = data bc3.Width = w bc3.SetY(h * 2 / 3) bc3.Height = h / 3 bc3.DataLabels = bclabels bc3.TextColor = termui.ColorGreen bc3.BarColor = termui.ColorRed bc3.NumColor = termui.ColorYellow termui.Render(bc1, bc2, bc3) termbox.PollEvent() }