-
Notifications
You must be signed in to change notification settings - Fork 0
/
status.go
61 lines (50 loc) · 954 Bytes
/
status.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
package entry
import "fmt"
type StatusScore struct {
Status int
Score Score
}
type Status struct {
values map[int]Score
total int
}
func NewStatus() *Status {
return &Status{make(map[int]Score, 0), 0}
}
func (m *Status) Add(status int) {
m.values[status]++
m.total++
}
func (m *Status) Len() int {
return m.total
}
func (m *Status) Union() StatusScore {
common := StatusScore{0, 0.0}
for k, v := range m.values {
if v != common.Score {
common.Status = k
common.Score = v
}
}
common.Score = common.Score / Score(float64(m.total))
return common
}
func (m *Status) Difference() []StatusScore {
var (
common = m.Union()
alt = make([]StatusScore, 0)
)
for k, v := range m.values {
if k == common.Status {
continue
}
alt = append(alt, StatusScore{
Status: k,
Score: v / Score(float64(m.total)),
})
}
return alt
}
func (m *Status) String() string {
return fmt.Sprintf("%d", m.Union().Status)
}