mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-22 19:08:58 +00:00
cmd/ursrv: Filter out ancient versions from chart
This commit is contained in:
parent
41ef945b2b
commit
5373e38ac8
@ -23,6 +23,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"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) {
|
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 {
|
if err != nil {
|
||||||
log.Println("summaryHandler:", err)
|
log.Println("summaryHandler:", err)
|
||||||
http.Error(w, "Database Error", http.StatusInternalServerError)
|
http.Error(w, "Database Error", http.StatusInternalServerError)
|
||||||
@ -1558,7 +1560,21 @@ func (s *summary) MarshalJSON() ([]byte, error) {
|
|||||||
return json.Marshal(table)
|
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()
|
s := newSummary()
|
||||||
|
|
||||||
rows, err := db.Query(`SELECT Day, Version, Count FROM VersionSummary WHERE Day > now() - '2 year'::INTERVAL;`)
|
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.setCount(day.Format("2006-01-02"), ver, num)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.filter(min)
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ found in the LICENSE file.
|
|||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/leaflet.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/leaflet.js"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/heatmapjs@2.0.2/heatmap.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/heatmapjs@2.0.2/heatmap.min.js"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/leaflet-heatmap@1.0.0/leaflet-heatmap.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/leaflet-heatmap@1.0.0/leaflet-heatmap.js"></script>
|
||||||
|
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
body {
|
body {
|
||||||
margin: 40px;
|
margin: 40px;
|
||||||
@ -55,7 +55,10 @@ found in the LICENSE file.
|
|||||||
google.setOnLoadCallback(drawPerformanceCharts);
|
google.setOnLoadCallback(drawPerformanceCharts);
|
||||||
|
|
||||||
function drawVersionChart() {
|
function drawVersionChart() {
|
||||||
var jsonData = $.ajax({url: "summary.json", dataType:"json", async: false}).responseText;
|
// Summary version chart for versions that at some point in the chart
|
||||||
|
// reaches 250 devices. This filters out versions that are old and
|
||||||
|
// uninteresting yet linger forever with like four users.
|
||||||
|
var jsonData = $.ajax({url: "summary.json?min=250", dataType:"json", async: false}).responseText;
|
||||||
var rows = JSON.parse(jsonData);
|
var rows = JSON.parse(jsonData);
|
||||||
|
|
||||||
var data = new google.visualization.DataTable();
|
var data = new google.visualization.DataTable();
|
||||||
@ -224,7 +227,7 @@ found in the LICENSE file.
|
|||||||
var testData = {
|
var testData = {
|
||||||
data: locations
|
data: locations
|
||||||
};
|
};
|
||||||
|
|
||||||
var baseLayer = L.tileLayer(
|
var baseLayer = L.tileLayer(
|
||||||
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',{
|
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',{
|
||||||
attribution: '...',
|
attribution: '...',
|
||||||
|
Loading…
Reference in New Issue
Block a user