Nano integration improvements
This commit is contained in:
@ -1,13 +1,108 @@
|
||||
package statistics
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/animenotifier/notify.moe/components"
|
||||
)
|
||||
|
||||
type stats map[string]float64
|
||||
|
||||
// Get ...
|
||||
func Get(ctx *aero.Context) string {
|
||||
// statistics := arn.StatisticsCategory{}
|
||||
// arn.DB.GetObject("Cache", "user statistics", &statistics)
|
||||
// return ctx.HTML(components.Statistics(statistics.PieCharts...))
|
||||
return ctx.HTML("Not implemented")
|
||||
pieCharts := getUserStats()
|
||||
return ctx.HTML(components.Statistics(pieCharts))
|
||||
}
|
||||
|
||||
func getUserStats() []*arn.PieChart {
|
||||
screenSize := stats{}
|
||||
pixelRatio := stats{}
|
||||
browser := stats{}
|
||||
country := stats{}
|
||||
gender := stats{}
|
||||
os := stats{}
|
||||
notifications := stats{}
|
||||
avatar := stats{}
|
||||
ip := stats{}
|
||||
pro := stats{}
|
||||
|
||||
for info := range arn.StreamAnalytics() {
|
||||
user, err := arn.GetUser(info.UserID)
|
||||
arn.PanicOnError(err)
|
||||
|
||||
if !user.IsActive() {
|
||||
continue
|
||||
}
|
||||
|
||||
pixelRatio[fmt.Sprintf("%.0f", info.Screen.PixelRatio)]++
|
||||
|
||||
size := arn.ToString(info.Screen.Width) + " x " + arn.ToString(info.Screen.Height)
|
||||
screenSize[size]++
|
||||
}
|
||||
|
||||
for user := range arn.StreamUsers() {
|
||||
if !user.IsActive() {
|
||||
continue
|
||||
}
|
||||
|
||||
if user.Gender != "" && user.Gender != "other" {
|
||||
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]++
|
||||
}
|
||||
|
||||
if len(user.PushSubscriptions().Items) > 0 {
|
||||
notifications["Enabled"]++
|
||||
} else {
|
||||
notifications["Disabled"]++
|
||||
}
|
||||
|
||||
if user.Avatar.Source == "" {
|
||||
avatar["none"]++
|
||||
} else {
|
||||
avatar[user.Avatar.Source]++
|
||||
}
|
||||
|
||||
if arn.IsIPv6(user.IP) {
|
||||
ip["IPv6"]++
|
||||
} else {
|
||||
ip["IPv4"]++
|
||||
}
|
||||
|
||||
if user.IsPro() {
|
||||
pro["PRO accounts"]++
|
||||
} else {
|
||||
pro["Free accounts"]++
|
||||
}
|
||||
}
|
||||
|
||||
return []*arn.PieChart{
|
||||
arn.NewPieChart("OS", os),
|
||||
arn.NewPieChart("Screen size", screenSize),
|
||||
arn.NewPieChart("Browser", browser),
|
||||
arn.NewPieChart("Country", country),
|
||||
arn.NewPieChart("Avatar", avatar),
|
||||
arn.NewPieChart("Notifications", notifications),
|
||||
arn.NewPieChart("Gender", gender),
|
||||
arn.NewPieChart("Pixel ratio", pixelRatio),
|
||||
arn.NewPieChart("IP version", ip),
|
||||
arn.NewPieChart("PRO accounts", pro),
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user