stats: Some attempt at a filter to make the dictionary lighter
This commit is contained in:
parent
bf7f2b6b55
commit
600f8f6ef7
1 changed files with 20 additions and 1 deletions
21
stats/web.go
21
stats/web.go
|
@ -7,6 +7,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func webStats(rw http.ResponseWriter, req *http.Request) {
|
func webStats(rw http.ResponseWriter, req *http.Request) {
|
||||||
|
rw.Header().Set("Content-Type", "application/json")
|
||||||
err := json.NewEncoder(rw).Encode(stats)
|
err := json.NewEncoder(rw).Encode(stats)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("[webStats] JSON Encoding error: " + err.Error())
|
log.Println("[webStats] JSON Encoding error: " + err.Error())
|
||||||
|
@ -14,14 +15,32 @@ func webStats(rw http.ResponseWriter, req *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func webUsers(rw http.ResponseWriter, req *http.Request) {
|
func webUsers(rw http.ResponseWriter, req *http.Request) {
|
||||||
|
rw.Header().Set("Content-Type", "application/json")
|
||||||
err := json.NewEncoder(rw).Encode(users)
|
err := json.NewEncoder(rw).Encode(users)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("[webUsers] JSON Encoding error: " + err.Error())
|
log.Println("[webUsers] JSON Encoding error: " + err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const USAGE_THRESHOLD = 3
|
||||||
|
|
||||||
func webWords(rw http.ResponseWriter, req *http.Request) {
|
func webWords(rw http.ResponseWriter, req *http.Request) {
|
||||||
err := json.NewEncoder(rw).Encode(words)
|
// Filter words under a certain usage
|
||||||
|
filtered := make(map[string]UserCount)
|
||||||
|
for word, usage := range words {
|
||||||
|
total := 0
|
||||||
|
for _, count := range usage {
|
||||||
|
total += count
|
||||||
|
}
|
||||||
|
|
||||||
|
if total < USAGE_THRESHOLD {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
filtered[word] = usage
|
||||||
|
}
|
||||||
|
|
||||||
|
rw.Header().Set("Content-Type", "application/json")
|
||||||
|
err := json.NewEncoder(rw).Encode(filtered)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("[webWords] JSON Encoding error: " + err.Error())
|
log.Println("[webWords] JSON Encoding error: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue