|
|
@@ -23,6 +23,7 @@ import (
|
|
|
"os"
|
|
|
"regexp"
|
|
|
"sort"
|
|
|
+ "strconv"
|
|
|
"strings"
|
|
|
"sync"
|
|
|
"time"
|
|
|
@@ -900,7 +901,8 @@ func newDataHandler(db *sql.DB, w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
|
|
|
func summaryHandler(db *sql.DB, w http.ResponseWriter, r *http.Request) {
|
|
|
- s, err := getSummary(db)
|
|
|
+ min, _ := strconv.Atoi(r.URL.Query().Get("min"))
|
|
|
+ s, err := getSummary(db, min)
|
|
|
if err != nil {
|
|
|
log.Println("summaryHandler:", err)
|
|
|
http.Error(w, "Database Error", http.StatusInternalServerError)
|
|
|
@@ -1558,7 +1560,21 @@ func (s *summary) MarshalJSON() ([]byte, error) {
|
|
|
return json.Marshal(table)
|
|
|
}
|
|
|
|
|
|
-func getSummary(db *sql.DB) (summary, error) {
|
|
|
+// filter removes versions that never reach the specified min count.
|
|
|
+func (s *summary) filter(min int) {
|
|
|
+ // We cheat and just remove the versions from the "index" and leave the
|
|
|
+ // data points alone. The version index is used to build the table when
|
|
|
+ // we do the serialization, so at that point the data points are
|
|
|
+ // filtered out as well.
|
|
|
+ for ver := range s.versions {
|
|
|
+ if s.max[ver] < min {
|
|
|
+ delete(s.versions, ver)
|
|
|
+ delete(s.max, ver)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func getSummary(db *sql.DB, min int) (summary, error) {
|
|
|
s := newSummary()
|
|
|
|
|
|
rows, err := db.Query(`SELECT Day, Version, Count FROM VersionSummary WHERE Day > now() - '2 year'::INTERVAL;`)
|
|
|
@@ -1589,6 +1605,7 @@ func getSummary(db *sql.DB) (summary, error) {
|
|
|
s.setCount(day.Format("2006-01-02"), ver, num)
|
|
|
}
|
|
|
|
|
|
+ s.filter(min)
|
|
|
return s, nil
|
|
|
}
|
|
|
|