Nano integration improvements
This commit is contained in:
@ -2,12 +2,129 @@ package statistics
|
||||
|
||||
import (
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/animenotifier/notify.moe/components"
|
||||
)
|
||||
|
||||
// Anime ...
|
||||
func Anime(ctx *aero.Context) string {
|
||||
// statistics := arn.StatisticsCategory{}
|
||||
// arn.DB.GetObject("Cache", "anime statistics", &statistics)
|
||||
// return ctx.HTML(components.Statistics(statistics.PieCharts...))
|
||||
return ctx.HTML("Not implemented")
|
||||
pieCharts := getAnimeStats()
|
||||
return ctx.HTML(components.Statistics(pieCharts))
|
||||
}
|
||||
|
||||
func getAnimeStats() []*arn.PieChart {
|
||||
shoboi := stats{}
|
||||
anilist := stats{}
|
||||
mal := stats{}
|
||||
anidb := stats{}
|
||||
status := stats{}
|
||||
types := stats{}
|
||||
shoboiEdits := stats{}
|
||||
anilistEdits := stats{}
|
||||
malEdits := stats{}
|
||||
anidbEdits := stats{}
|
||||
rating := stats{}
|
||||
twist := stats{}
|
||||
|
||||
for anime := range arn.StreamAnime() {
|
||||
for _, external := range anime.Mappings {
|
||||
if external.Service == "shoboi/anime" {
|
||||
if external.CreatedBy == "" {
|
||||
shoboiEdits["(auto-generated)"]++
|
||||
} else {
|
||||
user, err := arn.GetUser(external.CreatedBy)
|
||||
arn.PanicOnError(err)
|
||||
shoboiEdits[user.Nick]++
|
||||
}
|
||||
}
|
||||
|
||||
if external.Service == "anilist/anime" {
|
||||
if external.CreatedBy == "" {
|
||||
anilistEdits["(auto-generated)"]++
|
||||
} else {
|
||||
user, err := arn.GetUser(external.CreatedBy)
|
||||
arn.PanicOnError(err)
|
||||
anilistEdits[user.Nick]++
|
||||
}
|
||||
}
|
||||
|
||||
if external.Service == "myanimelist/anime" {
|
||||
if external.CreatedBy == "" {
|
||||
malEdits["(auto-generated)"]++
|
||||
} else {
|
||||
user, err := arn.GetUser(external.CreatedBy)
|
||||
arn.PanicOnError(err)
|
||||
malEdits[user.Nick]++
|
||||
}
|
||||
}
|
||||
|
||||
if external.Service == "anidb/anime" {
|
||||
if external.CreatedBy == "" {
|
||||
anidbEdits["(auto-generated)"]++
|
||||
} else {
|
||||
user, err := arn.GetUser(external.CreatedBy)
|
||||
arn.PanicOnError(err)
|
||||
anidbEdits[user.Nick]++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if anime.GetMapping("shoboi/anime") != "" {
|
||||
shoboi["Connected with Shoboi"]++
|
||||
} else {
|
||||
shoboi["Not connected with Shoboi"]++
|
||||
}
|
||||
|
||||
if anime.GetMapping("anilist/anime") != "" {
|
||||
anilist["Connected with AniList"]++
|
||||
} else {
|
||||
anilist["Not connected with AniList"]++
|
||||
}
|
||||
|
||||
if anime.GetMapping("myanimelist/anime") != "" {
|
||||
mal["Connected with MyAnimeList"]++
|
||||
} else {
|
||||
mal["Not connected with MyAnimeList"]++
|
||||
}
|
||||
|
||||
if anime.GetMapping("anidb/anime") != "" {
|
||||
anidb["Connected with AniDB"]++
|
||||
} else {
|
||||
anidb["Not connected with AniDB"]++
|
||||
}
|
||||
|
||||
rating[arn.ToString(int(anime.Rating.Overall+0.5))]++
|
||||
|
||||
found := false
|
||||
for _, episode := range anime.Episodes().Items {
|
||||
if episode.Links != nil && episode.Links["twist.moe"] != "" {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if found {
|
||||
twist["Connected with AnimeTwist"]++
|
||||
} else {
|
||||
twist["Not connected with AnimeTwist"]++
|
||||
}
|
||||
|
||||
status[anime.Status]++
|
||||
types[anime.Type]++
|
||||
}
|
||||
|
||||
return []*arn.PieChart{
|
||||
arn.NewPieChart("Type", types),
|
||||
arn.NewPieChart("Status", status),
|
||||
arn.NewPieChart("Rating", rating),
|
||||
arn.NewPieChart("MyAnimeList", mal),
|
||||
arn.NewPieChart("AniList", anilist),
|
||||
arn.NewPieChart("AniDB", anidb),
|
||||
arn.NewPieChart("Shoboi", shoboi),
|
||||
arn.NewPieChart("AnimeTwist", twist),
|
||||
// arn.NewPieChart("MyAnimeList Editors", malEdits),
|
||||
arn.NewPieChart("AniList Editors", anilistEdits),
|
||||
// arn.NewPieChart("AniDB Editors", anidbEdits),
|
||||
arn.NewPieChart("Shoboi Editors", shoboiEdits),
|
||||
}
|
||||
}
|
||||
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
component Statistics(pieCharts ...*arn.PieChart)
|
||||
component Statistics(pieCharts []*arn.PieChart)
|
||||
h1.page-title Statistics
|
||||
|
||||
StatisticsHeader
|
||||
|
Reference in New Issue
Block a user