Improved statistics
This commit is contained in:
@ -1,71 +1,14 @@
|
||||
package statistics
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/animenotifier/notify.moe/components"
|
||||
"github.com/animenotifier/notify.moe/utils"
|
||||
)
|
||||
|
||||
type stats = map[string]float64
|
||||
|
||||
// Get ...
|
||||
func Get(ctx *aero.Context) string {
|
||||
analytics, err := arn.AllAnalytics()
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusInternalServerError, "Couldn't fetch analytics", err)
|
||||
}
|
||||
|
||||
screenSize := stats{}
|
||||
// platform := stats{}
|
||||
pixelRatio := stats{}
|
||||
browser := stats{}
|
||||
country := stats{}
|
||||
gender := stats{}
|
||||
os := stats{}
|
||||
|
||||
for _, info := range analytics {
|
||||
// platform[info.System.Platform]++
|
||||
pixelRatio[fmt.Sprintf("%.1f", info.Screen.PixelRatio)]++
|
||||
|
||||
size := arn.ToString(info.Screen.Width) + " x " + arn.ToString(info.Screen.Height)
|
||||
screenSize[size]++
|
||||
}
|
||||
|
||||
for user := range arn.MustStreamUsers() {
|
||||
if user.Gender != "" {
|
||||
gender[user.Gender]++
|
||||
}
|
||||
|
||||
if user.Browser.Name != "" {
|
||||
browser[user.Browser.Name]++
|
||||
}
|
||||
|
||||
if user.Location.CountryName != "" {
|
||||
country[user.Location.CountryName]++
|
||||
}
|
||||
|
||||
if user.OS.Name != "" {
|
||||
if strings.HasPrefix(user.OS.Name, "CrOS") {
|
||||
user.OS.Name = "Chrome OS"
|
||||
}
|
||||
|
||||
os[user.OS.Name]++
|
||||
}
|
||||
}
|
||||
|
||||
return ctx.HTML(components.Statistics(
|
||||
utils.NewPieChart("OS", os),
|
||||
// utils.NewPieChart("Platform", platform),
|
||||
utils.NewPieChart("Screen size", screenSize),
|
||||
utils.NewPieChart("Browser", browser),
|
||||
utils.NewPieChart("Country", country),
|
||||
utils.NewPieChart("Gender", gender),
|
||||
utils.NewPieChart("Pixel ratio", pixelRatio),
|
||||
))
|
||||
statistics := arn.StatisticsCategory{}
|
||||
arn.DB.GetObject("Cache", "user statistics", &statistics)
|
||||
return ctx.HTML(components.Statistics(statistics.PieCharts...))
|
||||
}
|
||||
|
Reference in New Issue
Block a user