-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
chart-counters.go
84 lines (65 loc) · 1.71 KB
/
chart-counters.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
package web
import (
"github.com/aceberg/rediary/internal/models"
)
func countTotal(records []models.Record) models.Record {
var total models.Record
for _, rec := range records {
total.Minus = total.Minus + rec.Minus
total.Plus = total.Plus + rec.Plus
total.Total = total.Total + rec.Total
}
return total
}
func countTags(records []models.Record) models.ChartJS {
var chart models.ChartJS
countTagMap := make(map[string]int)
for _, rec := range records {
_, exists := countTagMap[rec.Tag]
if exists {
countTagMap[rec.Tag] = countTagMap[rec.Tag] + rec.Total
} else {
countTagMap[rec.Tag] = rec.Total
}
}
for tag, count := range countTagMap {
chart.Tag = append(chart.Tag, tag)
chart.Color = append(chart.Color, AppConfig.TagMap[tag])
chart.Count = append(chart.Count, count)
}
return chart
}
func countNames(records []models.Record) models.ChartJS {
var chart models.ChartJS
countTagMap := make(map[string]int)
for _, rec := range records {
_, exists := countTagMap[rec.Name]
if exists {
countTagMap[rec.Name] = countTagMap[rec.Name] + rec.Total
} else {
countTagMap[rec.Name] = rec.Total
}
}
for tag, count := range countTagMap {
chart.Tag = append(chart.Tag, tag)
chart.Count = append(chart.Count, count)
}
return chart
}
func countCloud(records []models.Record) models.ChartJS {
var chart models.ChartJS
countTagMap := make(map[string]int)
for _, rec := range records {
_, exists := countTagMap[rec.Name]
if exists {
countTagMap[rec.Name] = countTagMap[rec.Name] + 1
} else {
countTagMap[rec.Name] = 1
}
}
for tag, count := range countTagMap {
chart.Tag = append(chart.Tag, tag)
chart.Count = append(chart.Count, count*10)
}
return chart
}