summaryrefslogtreecommitdiff
path: root/score.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-07-17 14:18:34 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-07-17 14:18:34 +0200
commit9478c76ea54a69f09676df6d3c86479723f363d9 (patch)
tree7cf7aa7ffc164fb53777a68768f05d043fe7acfb /score.go
parentd76a78f72877154aa37d5a1f0e8846d3918cd92e (diff)
Add cmd timeout and score percent
Diffstat (limited to 'score.go')
-rw-r--r--score.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/score.go b/score.go
index c449c9a..f38cccb 100644
--- a/score.go
+++ b/score.go
@@ -14,8 +14,9 @@ const gobfile = `score.gob`
var score map[string]int
type Score struct {
- Nick string
- Count int
+ Nick string
+ Count int
+ Percent float64
}
type Scores []Score
@@ -25,16 +26,21 @@ func (s Scores) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s Scores) Less(i, j int) bool { return s[i].Count < s[j].Count }
func NewScores() (s Scores) {
+ var total int
for k, v := range score {
s = append(s, Score{
Nick: k,
Count: v,
})
+ total += v
}
sort.Sort(sort.Reverse(s))
if len(s) > 10 {
s = s[:10]
}
+ for i := range s {
+ s[i].Percent = 100.0 * float64(s[i].Count) / float64(total)
+ }
return
}
@@ -65,7 +71,7 @@ func saveScore(m map[string]int) {
}
func (s Score) String() string {
- return fmt.Sprintf("%v (%v)", s.Nick, s.Count)
+ return fmt.Sprintf("%v (%v/%.1f%%)", s.Nick, s.Count, s.Percent)
}
func (s Scores) String() (ret string) {