cmd/ursrv: Summarize tiny fraction items into Other

This commit is contained in:
Jakob Borg 2023-07-05 08:22:10 +02:00
parent c5ab71d7a5
commit 25ec2b63ab
2 changed files with 23 additions and 4 deletions

View File

@ -145,7 +145,7 @@ func statsForFloats(data []float64) [4]float64 {
return res return res
} }
func group(by func(string) string, as []analytic, perGroup int) []analytic { func group(by func(string) string, as []analytic, perGroup int, otherPct float64) []analytic {
var res []analytic var res []analytic
next: next:
@ -170,6 +170,25 @@ next:
} }
sort.Sort(analyticList(res)) sort.Sort(analyticList(res))
if otherPct > 0 {
// Groups with less than otherPCt go into "Other"
other := analytic{
Key: "Other",
}
for i := 0; i < len(res); i++ {
if res[i].Percentage < otherPct || res[i].Key == "Other" {
other.Count += res[i].Count
other.Percentage += res[i].Percentage
res = append(res[:i], res[i+1:]...)
i--
}
}
if other.Count > 0 {
res = append(res, other)
}
}
return res return res
} }

View File

@ -892,10 +892,10 @@ func getReport(db *sql.DB) map[string]interface{} {
r["nodes"] = nodes r["nodes"] = nodes
r["versionNodes"] = reports r["versionNodes"] = reports
r["categories"] = categories r["categories"] = categories
r["versions"] = group(byVersion, analyticsFor(versions, 2000), 10) r["versions"] = group(byVersion, analyticsFor(versions, 2000), 5, 1.0)
r["versionPenetrations"] = penetrationLevels(analyticsFor(versions, 2000), []float64{50, 75, 90, 95}) r["versionPenetrations"] = penetrationLevels(analyticsFor(versions, 2000), []float64{50, 75, 90, 95})
r["platforms"] = group(byPlatform, analyticsFor(platforms, 2000), 10) r["platforms"] = group(byPlatform, analyticsFor(platforms, 2000), 10, 0.0)
r["compilers"] = group(byCompiler, analyticsFor(compilers, 2000), 5) r["compilers"] = group(byCompiler, analyticsFor(compilers, 2000), 5, 1.0)
r["builders"] = analyticsFor(builders, 12) r["builders"] = analyticsFor(builders, 12)
r["distributions"] = analyticsFor(distributions, len(knownDistributions)) r["distributions"] = analyticsFor(distributions, len(knownDistributions))
r["featureOrder"] = featureOrder r["featureOrder"] = featureOrder