Remove statistics and add frequent tags in memory

This commit is contained in:
Las Zenow 2016-09-03 15:08:10 -04:00
parent 284b649b69
commit 18baa2938b
10 changed files with 35 additions and 256 deletions

View file

@ -4,7 +4,6 @@ import (
log "github.com/cihub/seelog"
"net/http"
"strconv"
"strings"
"time"
@ -93,65 +92,6 @@ func (sg StatsGatherer) worker() {
}
}
func statsHandler(h handler) {
data := statsData{
S: GetStatus(h),
HVisits: getVisits(hourlyLabel, h.db, database.Hourly_visits),
DVisits: getVisits(dailyLabel, h.db, database.Daily_visits),
MVisits: getVisits(monthlyLabel, h.db, database.Monthly_visits),
HDownloads: getVisits(hourlyLabel, h.db, database.Hourly_downloads),
DDownloads: getVisits(dailyLabel, h.db, database.Daily_downloads),
MDownloads: getVisits(monthlyLabel, h.db, database.Monthly_downloads),
}
data.S.Title = "Stats -- " + data.S.Title
data.S.Stats = true
h.template.load(h, "stats", data)
}
type statsData struct {
S Status
HVisits []visitData
DVisits []visitData
MVisits []visitData
HDownloads []visitData
DDownloads []visitData
MDownloads []visitData
}
type visitData struct {
Label string
Count int
}
func hourlyLabel(date time.Time) string {
return strconv.Itoa(date.Hour() + 1)
}
func dailyLabel(date time.Time) string {
return strconv.Itoa(date.Day())
}
func monthlyLabel(date time.Time) string {
return date.Month().String()
}
func getVisits(funcLabel func(time.Time) string, db database.DB, visitType database.VisitType) []visitData {
var visits []visitData
visit, err := db.GetVisits(visitType)
if err != nil {
log.Warn("GetVisits error (", visitType, "): ", err)
}
for _, v := range visit {
var elem visitData
elem.Label = funcLabel(v.Date.UTC())
elem.Count = v.Count
visits = append(visits, elem)
}
return visits
}
func appendFiles(r *http.Request, stats map[string]interface{}) {
if r.Method == "POST" && r.MultipartForm != nil {
files := r.MultipartForm.File