39 lines
935 B
Go
Raw Normal View History

2017-07-07 00:07:34 +00:00
package statistics
import (
2017-07-07 00:37:43 +00:00
"fmt"
2017-07-07 00:07:34 +00:00
"net/http"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
)
// Get ...
func Get(ctx *aero.Context) string {
analytics, err := arn.AllAnalytics()
if err != nil {
return ctx.Error(http.StatusInternalServerError, "Couldn't retrieve analytics", err)
}
2017-07-07 01:22:29 +00:00
screenSize := map[string]float64{}
platform := map[string]float64{}
pixelRatio := map[string]float64{}
2017-07-07 00:07:34 +00:00
for _, info := range analytics {
2017-07-07 01:22:29 +00:00
platform[info.System.Platform]++
pixelRatio[fmt.Sprintf("%.1f", info.Screen.PixelRatio)]++
2017-07-07 00:07:34 +00:00
2017-07-07 01:22:29 +00:00
size := arn.ToString(info.Screen.Width) + " x " + arn.ToString(info.Screen.Height)
screenSize[size]++
2017-07-07 00:07:34 +00:00
}
2017-07-07 01:22:29 +00:00
return ctx.HTML(components.Statistics(
utils.NewPieChart("Screen sizes", screenSize),
utils.NewPieChart("Platforms", platform),
utils.NewPieChart("Pixel ratios", pixelRatio),
))
2017-07-07 00:07:34 +00:00
}