Răsfoiți Sursa

cmd/ursrv: Summarize tiny fraction items into Other

Jakob Borg 2 ani în urmă
părinte
comite
25ec2b63ab
2 a modificat fișierele cu 23 adăugiri și 4 ștergeri
  1. 20 1
      cmd/ursrv/analytics.go
  2. 3 3
      cmd/ursrv/main.go

+ 20 - 1
cmd/ursrv/analytics.go

@@ -145,7 +145,7 @@ func statsForFloats(data []float64) [4]float64 {
 	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
 
 next:
@@ -170,6 +170,25 @@ next:
 	}
 
 	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
 }
 

+ 3 - 3
cmd/ursrv/main.go

@@ -892,10 +892,10 @@ func getReport(db *sql.DB) map[string]interface{} {
 	r["nodes"] = nodes
 	r["versionNodes"] = reports
 	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["platforms"] = group(byPlatform, analyticsFor(platforms, 2000), 10)
-	r["compilers"] = group(byCompiler, analyticsFor(compilers, 2000), 5)
+	r["platforms"] = group(byPlatform, analyticsFor(platforms, 2000), 10, 0.0)
+	r["compilers"] = group(byCompiler, analyticsFor(compilers, 2000), 5, 1.0)
 	r["builders"] = analyticsFor(builders, 12)
 	r["distributions"] = analyticsFor(distributions, len(knownDistributions))
 	r["featureOrder"] = featureOrder