-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.go
133 lines (121 loc) · 2.2 KB
/
data.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package main
import (
"github.com/gizak/termui"
"strconv"
"time"
)
var weekDays = map[string]time.Weekday{
"Mon": time.Monday,
"Tue": time.Tuesday,
"Wed": time.Wednesday,
"Thu": time.Thursday,
"Fri": time.Friday,
"Sat": time.Saturday,
"Sun": time.Sunday,
}
// months represent all the month choices available in a year
var months = map[string]time.Month{
"Jan": time.January,
"Feb": time.February,
"Mar": time.March,
"Apr": time.April,
"May": time.May,
"Jun": time.June,
"Jul": time.July,
"Aug": time.August,
"Sep": time.September,
"Oct": time.October,
"Nov": time.November,
"Dec": time.December,
}
var defaultHourlyProfile = map[string]float64{
"0": 1,
"1": 1,
"2": 1,
"3": 1,
"4": 1,
"5": 1,
"6": 1,
"7": 1,
"8": 1,
"9": 1,
"10": 1,
"11": 1,
"12": 1,
"13": 1,
"14": 1,
"15": 1,
"16": 1,
"17": 1,
"18": 1,
"19": 1,
"20": 1,
"21": 1,
"22": 1,
"23": 1,
}
var defaultWeeklyProfile = map[string]float64{
"Sun": 1,
"Mon": 1,
"Tue": 1,
"Wed": 1,
"Thu": 1,
"Fri": 1,
"Sat": 1,
}
var defaultMonthlyProfile = map[string]float64{
"Jan": 1,
"Feb": 1,
"Mar": 1,
"Apr": 1,
"May": 1,
"Jun": 1,
"Jul": 1,
"Aug": 1,
"Sep": 1,
"Oct": 1,
"Nov": 1,
"Dec": 1,
}
func PlotBarChart(keys []int, labels []string, header string) {
if err := termui.Init(); err != nil {
panic(err)
}
defer termui.Close()
bc := termui.NewBarChart()
bc.BorderLabel = header
bc.Data = keys
bc.Width = 170
bc.Height = 15
bc.DataLabels = labels
bc.BarGap = 1
bc.BarWidth = 4
bc.TextColor = termui.ColorGreen
bc.BarColor = termui.ColorRed
bc.NumColor = termui.ColorYellow
termui.Render(bc)
termui.Handle("/sys/kbd/q", func(termui.Event) {
termui.StopLoop()
})
termui.Loop()
}
func FloatToString(input_num float64) string {
// to convert a float number to a string
return strconv.FormatFloat(input_num, 'f', 6, 64)
}
func GetStringSliceFromInt(intKeys []int) []string {
var stringKeys = []string{}
for _, i := range intKeys {
j := strconv.Itoa(i)
stringKeys = append(stringKeys, j)
}
return stringKeys
}
func GetIntSliceFromFloat(floatKeys []float64) []int {
var intKeys = []int{}
for _, i := range floatKeys {
j := int(i)
intKeys = append(intKeys, j)
}
return intKeys
}