浏览代码

More details version/platform stats

Jakob Borg 9 年之前
父节点
当前提交
82621f250c
共有 3 个文件被更改,包括 107 次插入54 次删除
  1. 65 3
      cmd/ursrv/analytics.go
  2. 8 20
      cmd/ursrv/main.go
  3. 34 31
      static/index.html

+ 65 - 3
cmd/ursrv/analytics.go

@@ -1,16 +1,26 @@
 package main
 
-import "sort"
+import (
+	"sort"
+	"strings"
+)
 
 type analytic struct {
 	Key        string
 	Count      int
 	Percentage float64
+	Items      []analytic `json:",omitempty"`
 }
 
 type analyticList []analytic
 
 func (l analyticList) Less(a, b int) bool {
+	if l[a].Key == "Others" {
+		return true
+	}
+	if l[b].Key == "Others" {
+		return false
+	}
 	return l[b].Count < l[a].Count // inverse
 }
 
@@ -33,7 +43,11 @@ func analyticsFor(ss []string, cutoff int) []analytic {
 
 	l := make([]analytic, 0, len(m))
 	for k, c := range m {
-		l = append(l, analytic{k, c, 100 * float64(c) / float64(t)})
+		l = append(l, analytic{
+			Key:        k,
+			Count:      c,
+			Percentage: 100 * float64(c) / float64(t),
+		})
 	}
 
 	sort.Sort(analyticList(l))
@@ -43,7 +57,11 @@ func analyticsFor(ss []string, cutoff int) []analytic {
 		for _, i := range l[cutoff:] {
 			c += i.Count
 		}
-		l = append(l[:cutoff], analytic{"Others", c, 100 * float64(c) / float64(t)})
+		l = append(l[:cutoff], analytic{
+			Key:        "Others",
+			Count:      c,
+			Percentage: 100 * float64(c) / float64(t),
+		})
 	}
 
 	return l
@@ -76,3 +94,47 @@ func statsForFloats(data []float64) [4]float64 {
 	res[3] = data[len(data)-1]
 	return res
 }
+
+func group(by func(string) string, as []analytic, perGroup int) []analytic {
+	var res []analytic
+
+next:
+	for _, a := range as {
+		group := by(a.Key)
+		for i := range res {
+			if res[i].Key == group {
+				res[i].Count += a.Count
+				res[i].Percentage += a.Percentage
+				if len(res[i].Items) < perGroup {
+					res[i].Items = append(res[i].Items, a)
+				}
+				continue next
+			}
+		}
+		res = append(res, analytic{
+			Key:        group,
+			Count:      a.Count,
+			Percentage: a.Percentage,
+			Items:      []analytic{a},
+		})
+	}
+
+	sort.Sort(analyticList(res))
+	return res
+}
+
+func byVersion(s string) string {
+	parts := strings.Split(s, ".")
+	if len(parts) >= 2 {
+		return strings.Join(parts[:2], ".")
+	}
+	return s
+}
+
+func byPlatform(s string) string {
+	parts := strings.Split(s, "-")
+	if len(parts) >= 2 {
+		return parts[0]
+	}
+	return s
+}

+ 8 - 20
cmd/ursrv/main.go

@@ -22,13 +22,12 @@ import (
 )
 
 var (
-	keyFile           = getEnvDefault("UR_KEY_FILE", "key.pem")
-	certFile          = getEnvDefault("UR_CRT_FILE", "crt.pem")
-	dbConn            = getEnvDefault("UR_DB_URL", "postgres://user:password@localhost/ur?sslmode=disable")
-	listenAddr        = getEnvDefault("UR_LISTEN", "0.0.0.0:8443")
-	tpl               *template.Template
-	compilerRe        = regexp.MustCompile(`\(([A-Za-z0-9()., -]+) \w+-\w+(?:| android| default)\) ([\[email protected]]+)`)
-	aggregateVersions = []string{"v0.7", "v0.8", "v0.9", "v0.10", "v0.11"}
+	keyFile    = getEnvDefault("UR_KEY_FILE", "key.pem")
+	certFile   = getEnvDefault("UR_CRT_FILE", "crt.pem")
+	dbConn     = getEnvDefault("UR_DB_URL", "postgres://user:password@localhost/ur?sslmode=disable")
+	listenAddr = getEnvDefault("UR_LISTEN", "0.0.0.0:8443")
+	tpl        *template.Template
+	compilerRe = regexp.MustCompile(`\(([A-Za-z0-9()., -]+) \w+-\w+(?:| android| default)\) ([\[email protected]]+)`)
 )
 
 var funcs = map[string]interface{}{
@@ -476,7 +475,6 @@ func getReport(db *sql.DB) map[string]interface{} {
 	nodes := 0
 	var versions []string
 	var platforms []string
-	var oses []string
 	var numFolders []int
 	var numDevices []int
 	var totFiles []int
@@ -540,8 +538,6 @@ func getReport(db *sql.DB) map[string]interface{} {
 		nodes++
 		versions = append(versions, transformVersion(rep.Version))
 		platforms = append(platforms, rep.Platform)
-		ps := strings.Split(rep.Platform, "-")
-		oses = append(oses, ps[0])
 		if m := compilerRe.FindStringSubmatch(rep.LongVersion); len(m) == 3 {
 			compilers = append(compilers, m[1])
 			builders = append(builders, m[2])
@@ -739,9 +735,8 @@ func getReport(db *sql.DB) map[string]interface{} {
 	r["nodes"] = nodes
 	r["v2nodes"] = v2Reports
 	r["categories"] = categories
-	r["versions"] = analyticsFor(versions, 10)
-	r["platforms"] = analyticsFor(platforms, 0)
-	r["os"] = analyticsFor(oses, 0)
+	r["versions"] = group(byVersion, analyticsFor(versions, 2000), 5)
+	r["platforms"] = group(byPlatform, analyticsFor(platforms, 2000), 5)
 	r["compilers"] = analyticsFor(compilers, 12)
 	r["builders"] = analyticsFor(builders, 12)
 	r["features"] = featureList
@@ -773,13 +768,6 @@ func transformVersion(v string) string {
 		return m[1] + " (+dev)"
 	}
 
-	// Truncate old versions to just the generation part
-	for _, agg := range aggregateVersions {
-		if strings.HasPrefix(v, agg) {
-			return agg + ".x"
-		}
-	}
-
 	return v
 }
 

+ 34 - 31
static/index.html

@@ -22,6 +22,12 @@ found in the LICENSE file.
       margin: 40px;
       font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
     }
+    tr.main td {
+      font-weight: bold;
+    }
+    tr.child td.first {
+      padding-left: 2em;
+    }
   </style>
   <script type="text/javascript"
           src="https://www.google.com/jsapi?autoload={
@@ -144,7 +150,7 @@ found in the LICENSE file.
 
     <div class="row">
 
-      <div class="col-md-4">
+      <div class="col-md-6">
         <table class="table table-striped">
           <thead>
             <tr>
@@ -153,17 +159,26 @@ found in the LICENSE file.
           </thead>
           <tbody>
             {{range .versions}}
-            <tr>
-              <td>{{.Key}}</td>
-              <td class="text-right">{{.Count}}</td>
-              <td class="text-right">{{.Percentage | printf "%.01f"}}%</td>
-            </tr>
+              {{if gt .Percentage 0.5}}
+                <tr class="main">
+                  <td>{{.Key}}</td>
+                  <td class="text-right">{{.Count}}</td>
+                  <td class="text-right">{{.Percentage | printf "%.01f"}}%</td>
+                </tr>
+                {{range .Items}}
+                  <tr class="child">
+                    <td class="first">{{.Key}}</td>
+                    <td class="text-right">{{.Count}}</td>
+                    <td class="text-right">{{.Percentage | printf "%.01f"}}%</td>
+                  </tr>
+                {{end}}
+              {{end}}
             {{end}}
           </tbody>
         </table>
       </div>
 
-      <div class="col-md-4">
+      <div class="col-md-6">
         <table class="table table-striped">
           <thead>
             <tr>
@@ -172,30 +187,18 @@ found in the LICENSE file.
           </thead>
           <tbody>
             {{range .platforms}}
-            <tr>
-              <td>{{.Key}}</td>
-              <td class="text-right">{{.Count}}</td>
-              <td class="text-right">{{.Percentage | printf "%.01f"}}%</td>
-            </tr>
-            {{end}}
-          </tbody>
-        </table>
-      </div>
-
-      <div class="col-md-4">
-        <table class="table table-striped">
-          <thead>
-            <tr>
-              <th>OS</th><th class="text-right">Devices</th><th class="text-right">Share</th>
-            </tr>
-          </thead>
-          <tbody>
-            {{range .os}}
-            <tr>
-              <td>{{.Key}}</td>
-              <td class="text-right">{{.Count}}</td>
-              <td class="text-right">{{.Percentage | printf "%.01f"}}%</td>
-            </tr>
+              <tr class="main">
+                <td>{{.Key}}</td>
+                <td class="text-right">{{.Count}}</td>
+                <td class="text-right">{{.Percentage | printf "%.01f"}}%</td>
+              </tr>
+              {{range .Items}}
+                <tr class="child">
+                  <td class="first">{{.Key}}</td>
+                  <td class="text-right">{{.Count}}</td>
+                  <td class="text-right">{{.Percentage | printf "%.01f"}}%</td>
+                </tr>
+              {{end}}
             {{end}}
           </tbody>
         </table>