-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge_overall.go
56 lines (50 loc) · 1.29 KB
/
merge_overall.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
package usage
import "fmt"
func MergeOverall(q []Quantity) []Quantity {
merged := make(map[string]Quantity)
for i := range q {
hash := fmt.Sprintf(
"%s%s%s%s%s",
q[i].UsageType,
q[i].Platform,
q[i].CacheEngine,
q[i].DatabaseEngine,
q[i].Date,
)
v, ok := merged[hash]
if !ok {
merged[hash] = Quantity{
Region: q[i].Region,
UsageType: q[i].UsageType,
Platform: q[i].Platform,
CacheEngine: q[i].CacheEngine,
DatabaseEngine: q[i].DatabaseEngine,
Date: q[i].Date,
InstanceHour: q[i].InstanceHour,
InstanceNum: q[i].InstanceNum,
GByte: q[i].GByte,
Requests: q[i].Requests,
Unit: q[i].Unit,
}
continue
}
merged[hash] = Quantity{
Region: q[i].Region,
UsageType: q[i].UsageType,
Platform: q[i].Platform,
CacheEngine: q[i].CacheEngine,
DatabaseEngine: q[i].DatabaseEngine,
Date: q[i].Date,
InstanceHour: q[i].InstanceHour + v.InstanceHour,
InstanceNum: q[i].InstanceNum + v.InstanceNum,
GByte: q[i].GByte + v.GByte,
Requests: q[i].Requests + v.Requests,
Unit: q[i].Unit,
}
}
out := make([]Quantity, 0)
for k := range merged {
out = append(out, merged[k])
}
return out
}