More stats
This commit is contained in:
parent
bff0f62629
commit
1fb5b4210e
@ -3,6 +3,7 @@ package statistics
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/aerogo/aero"
|
"github.com/aerogo/aero"
|
||||||
"github.com/animenotifier/arn"
|
"github.com/animenotifier/arn"
|
||||||
@ -10,6 +11,8 @@ import (
|
|||||||
"github.com/animenotifier/notify.moe/utils"
|
"github.com/animenotifier/notify.moe/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type stats = map[string]float64
|
||||||
|
|
||||||
// Get ...
|
// Get ...
|
||||||
func Get(ctx *aero.Context) string {
|
func Get(ctx *aero.Context) string {
|
||||||
analytics, err := arn.AllAnalytics()
|
analytics, err := arn.AllAnalytics()
|
||||||
@ -18,21 +21,51 @@ func Get(ctx *aero.Context) string {
|
|||||||
return ctx.Error(http.StatusInternalServerError, "Couldn't retrieve analytics", err)
|
return ctx.Error(http.StatusInternalServerError, "Couldn't retrieve analytics", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
screenSize := map[string]float64{}
|
screenSize := stats{}
|
||||||
platform := map[string]float64{}
|
// platform := stats{}
|
||||||
pixelRatio := map[string]float64{}
|
pixelRatio := stats{}
|
||||||
|
browser := stats{}
|
||||||
|
country := stats{}
|
||||||
|
gender := stats{}
|
||||||
|
os := stats{}
|
||||||
|
|
||||||
for _, info := range analytics {
|
for _, info := range analytics {
|
||||||
platform[info.System.Platform]++
|
// platform[info.System.Platform]++
|
||||||
pixelRatio[fmt.Sprintf("%.1f", info.Screen.PixelRatio)]++
|
pixelRatio[fmt.Sprintf("%.1f", info.Screen.PixelRatio)]++
|
||||||
|
|
||||||
size := arn.ToString(info.Screen.Width) + " x " + arn.ToString(info.Screen.Height)
|
size := arn.ToString(info.Screen.Width) + " x " + arn.ToString(info.Screen.Height)
|
||||||
screenSize[size]++
|
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(
|
return ctx.HTML(components.Statistics(
|
||||||
utils.NewPieChart("Screen sizes", screenSize),
|
utils.NewPieChart("OS", os),
|
||||||
utils.NewPieChart("Platforms", platform),
|
// utils.NewPieChart("Platform", platform),
|
||||||
utils.NewPieChart("Pixel ratios", pixelRatio),
|
utils.NewPieChart("Screen size", screenSize),
|
||||||
|
utils.NewPieChart("Pixel ratio", pixelRatio),
|
||||||
|
utils.NewPieChart("Browser", browser),
|
||||||
|
utils.NewPieChart("Country", country),
|
||||||
|
utils.NewPieChart("Gender", gender),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -98,17 +98,17 @@ func ToPieChartSlices(data map[string]float64) []*PieChartSlice {
|
|||||||
|
|
||||||
slices := []*PieChartSlice{}
|
slices := []*PieChartSlice{}
|
||||||
current := 0.0
|
current := 0.0
|
||||||
hueOffset := 0.0
|
hueOffset := 230.0
|
||||||
hueScaling := 60.0
|
hueScaling := -30.0
|
||||||
|
|
||||||
for _, item := range dataSorted {
|
for i, item := range dataSorted {
|
||||||
percentage := float64(item.Value) / sum
|
percentage := float64(item.Value) / sum
|
||||||
|
|
||||||
slices = append(slices, &PieChartSlice{
|
slices = append(slices, &PieChartSlice{
|
||||||
From: current,
|
From: current,
|
||||||
To: current + percentage,
|
To: current + percentage,
|
||||||
Title: fmt.Sprintf("%s (%d%%)", item.Key, int(percentage*100+0.5)),
|
Title: fmt.Sprintf("%s (%d%%)", item.Key, int(percentage*100+0.5)),
|
||||||
Color: fmt.Sprintf("hsl(%.2f, 75%%, 50%%)", current*hueScaling+hueOffset),
|
Color: fmt.Sprintf("hsl(%.2f, 75%%, 50%%)", float64(i)*hueScaling+hueOffset),
|
||||||
})
|
})
|
||||||
|
|
||||||
current += percentage
|
current += percentage
|
||||||
|
Loading…
Reference in New Issue
Block a user