Truncate list of versions

This commit is contained in:
Jakob Borg 2014-12-09 16:52:02 +01:00
parent 9c51cf50ad
commit 97a9ca24f3
2 changed files with 13 additions and 4 deletions

View File

@ -23,7 +23,7 @@ func (l analyticList) Len() int {
}
// Returns a list of frequency analytics for a given list of strings.
func analyticsFor(ss []string) []analytic {
func analyticsFor(ss []string, cutoff int) []analytic {
m := make(map[string]int)
t := 0
for _, s := range ss {
@ -37,6 +37,15 @@ func analyticsFor(ss []string) []analytic {
}
sort.Sort(analyticList(l))
if cutoff > 0 && len(l) > cutoff {
c := 0
for _, i := range l[cutoff:] {
c += i.Count
}
l = append(l[:cutoff], analytic{"Others", c, 100 * float64(c) / float64(t)})
}
return l
}

View File

@ -363,9 +363,9 @@ func getReport(key string) map[string]interface{} {
r["key"] = key
r["nodes"] = nodes
r["categories"] = categories
r["versions"] = analyticsFor(versions)
r["platforms"] = analyticsFor(platforms)
r["os"] = analyticsFor(oses)
r["versions"] = analyticsFor(versions, 10)
r["platforms"] = analyticsFor(platforms, 0)
r["os"] = analyticsFor(oses, 0)
reportCache = r