Fix invalid element order for historical stats -- in API declaration values are from oldest to newest, not other way around.
This commit is contained in:
parent
04562dece3
commit
1f0fdef8d6
18
helpers.go
18
helpers.go
|
@ -51,10 +51,10 @@ func ensureDELETE(handler func(http.ResponseWriter, *http.Request)) func(http.Re
|
||||||
// --------------------------
|
// --------------------------
|
||||||
// helper functions for stats
|
// helper functions for stats
|
||||||
// --------------------------
|
// --------------------------
|
||||||
func getSlice(input [statsHistoryElements]float64, start int, end int) []float64 {
|
func getReversedSlice(input [statsHistoryElements]float64, start int, end int) []float64 {
|
||||||
output := make([]float64, 0)
|
output := make([]float64, 0)
|
||||||
for i := start; i <= end; i++ {
|
for i := start; i <= end; i++ {
|
||||||
output = append(output, input[i])
|
output = append([]float64{input[i]}, output...)
|
||||||
}
|
}
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
@ -66,8 +66,8 @@ func generateMapFromStats(stats *periodicStats, start int, end int) map[string]i
|
||||||
|
|
||||||
avgProcessingTime := make([]float64, 0)
|
avgProcessingTime := make([]float64, 0)
|
||||||
|
|
||||||
count := getSlice(stats.entries[processingTimeCount], start, end)
|
count := getReversedSlice(stats.entries[processingTimeCount], start, end)
|
||||||
sum := getSlice(stats.entries[processingTimeSum], start, end)
|
sum := getReversedSlice(stats.entries[processingTimeSum], start, end)
|
||||||
for i := 0; i < len(count); i++ {
|
for i := 0; i < len(count); i++ {
|
||||||
var avg float64
|
var avg float64
|
||||||
if count[i] != 0 {
|
if count[i] != 0 {
|
||||||
|
@ -78,11 +78,11 @@ func generateMapFromStats(stats *periodicStats, start int, end int) map[string]i
|
||||||
}
|
}
|
||||||
|
|
||||||
result := map[string]interface{}{
|
result := map[string]interface{}{
|
||||||
"dns_queries": getSlice(stats.entries[totalRequests], start, end),
|
"dns_queries": getReversedSlice(stats.entries[totalRequests], start, end),
|
||||||
"blocked_filtering": getSlice(stats.entries[filteredLists], start, end),
|
"blocked_filtering": getReversedSlice(stats.entries[filteredLists], start, end),
|
||||||
"replaced_safebrowsing": getSlice(stats.entries[filteredSafebrowsing], start, end),
|
"replaced_safebrowsing": getReversedSlice(stats.entries[filteredSafebrowsing], start, end),
|
||||||
"replaced_safesearch": getSlice(stats.entries[filteredSafesearch], start, end),
|
"replaced_safesearch": getReversedSlice(stats.entries[filteredSafesearch], start, end),
|
||||||
"replaced_parental": getSlice(stats.entries[filteredParental], start, end),
|
"replaced_parental": getReversedSlice(stats.entries[filteredParental], start, end),
|
||||||
"avg_processing_time": avgProcessingTime,
|
"avg_processing_time": avgProcessingTime,
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
|
Loading…
Reference in New Issue