2017-07-07 10:10:27 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/animenotifier/arn"
|
|
|
|
"github.com/fatih/color"
|
|
|
|
)
|
|
|
|
|
|
|
|
type stats map[string]float64
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
color.Yellow("Generating statistics")
|
|
|
|
|
|
|
|
userStats := getUserStats()
|
|
|
|
animeStats := getAnimeStats()
|
|
|
|
|
|
|
|
arn.PanicOnError(arn.DB.Set("Cache", "user statistics", &arn.StatisticsCategory{
|
|
|
|
Name: "Users",
|
|
|
|
PieCharts: userStats,
|
|
|
|
}))
|
2017-07-15 17:31:34 +00:00
|
|
|
|
2017-07-07 10:10:27 +00:00
|
|
|
arn.PanicOnError(arn.DB.Set("Cache", "anime statistics", &arn.StatisticsCategory{
|
|
|
|
Name: "Anime",
|
|
|
|
PieCharts: animeStats,
|
|
|
|
}))
|
|
|
|
|
|
|
|
color.Green("Finished.")
|
|
|
|
}
|
|
|
|
|
|
|
|
func getUserStats() []*arn.PieChart {
|
|
|
|
println("Generating user statistics")
|
|
|
|
|
|
|
|
analytics, err := arn.AllAnalytics()
|
|
|
|
arn.PanicOnError(err)
|
|
|
|
|
|
|
|
screenSize := stats{}
|
|
|
|
pixelRatio := stats{}
|
|
|
|
browser := stats{}
|
|
|
|
country := stats{}
|
|
|
|
gender := stats{}
|
|
|
|
os := stats{}
|
2017-07-15 17:31:34 +00:00
|
|
|
notifications := stats{}
|
2017-07-17 21:56:05 +00:00
|
|
|
avatar := stats{}
|
2017-07-07 10:10:27 +00:00
|
|
|
|
|
|
|
for _, info := range analytics {
|
|
|
|
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() {
|
2017-07-19 00:36:52 +00:00
|
|
|
if !user.IsActive() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2017-07-17 21:56:05 +00:00
|
|
|
if user.Gender != "" && user.Gender != "other" {
|
2017-07-07 10:10:27 +00:00
|
|
|
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]++
|
|
|
|
}
|
2017-07-15 17:31:34 +00:00
|
|
|
|
|
|
|
if len(user.PushSubscriptions().Items) > 0 {
|
|
|
|
notifications["Enabled"]++
|
|
|
|
} else {
|
|
|
|
notifications["Disabled"]++
|
|
|
|
}
|
|
|
|
|
2017-07-17 21:56:05 +00:00
|
|
|
if user.Avatar.Source == "" {
|
|
|
|
avatar["none"]++
|
|
|
|
} else {
|
|
|
|
avatar[user.Avatar.Source]++
|
|
|
|
}
|
2017-07-07 10:10:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
println("Finished user statistics")
|
|
|
|
|
|
|
|
return []*arn.PieChart{
|
|
|
|
arn.NewPieChart("OS", os),
|
|
|
|
arn.NewPieChart("Screen size", screenSize),
|
|
|
|
arn.NewPieChart("Browser", browser),
|
|
|
|
arn.NewPieChart("Country", country),
|
2017-07-17 21:56:05 +00:00
|
|
|
arn.NewPieChart("Avatar", avatar),
|
2017-07-15 17:31:34 +00:00
|
|
|
arn.NewPieChart("Notifications", notifications),
|
2017-07-07 10:10:27 +00:00
|
|
|
arn.NewPieChart("Gender", gender),
|
|
|
|
arn.NewPieChart("Pixel ratio", pixelRatio),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func getAnimeStats() []*arn.PieChart {
|
|
|
|
println("Generating anime statistics")
|
|
|
|
|
|
|
|
allAnime, err := arn.AllAnime()
|
|
|
|
arn.PanicOnError(err)
|
|
|
|
|
|
|
|
shoboi := stats{}
|
|
|
|
anilist := stats{}
|
2017-07-07 14:06:46 +00:00
|
|
|
mal := stats{}
|
|
|
|
anidb := stats{}
|
2017-07-07 10:10:27 +00:00
|
|
|
status := stats{}
|
|
|
|
types := stats{}
|
|
|
|
shoboiEdits := stats{}
|
|
|
|
anilistEdits := stats{}
|
2017-07-07 14:06:46 +00:00
|
|
|
malEdits := stats{}
|
|
|
|
anidbEdits := stats{}
|
2017-07-07 10:10:27 +00:00
|
|
|
rating := stats{}
|
2017-07-10 20:35:48 +00:00
|
|
|
twist := stats{}
|
2017-07-07 10:10:27 +00:00
|
|
|
|
|
|
|
for _, anime := range allAnime {
|
|
|
|
for _, external := range anime.Mappings {
|
|
|
|
if external.Service == "shoboi/anime" {
|
|
|
|
if external.CreatedBy == "" {
|
2017-07-07 14:06:46 +00:00
|
|
|
shoboiEdits["(auto-generated)"]++
|
2017-07-07 10:10:27 +00:00
|
|
|
} else {
|
|
|
|
user, err := arn.GetUser(external.CreatedBy)
|
|
|
|
arn.PanicOnError(err)
|
|
|
|
shoboiEdits[user.Nick]++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if external.Service == "anilist/anime" {
|
|
|
|
if external.CreatedBy == "" {
|
2017-07-07 14:06:46 +00:00
|
|
|
anilistEdits["(auto-generated)"]++
|
2017-07-07 10:10:27 +00:00
|
|
|
} else {
|
|
|
|
user, err := arn.GetUser(external.CreatedBy)
|
|
|
|
arn.PanicOnError(err)
|
|
|
|
anilistEdits[user.Nick]++
|
|
|
|
}
|
|
|
|
}
|
2017-07-07 14:06:46 +00:00
|
|
|
|
|
|
|
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]++
|
|
|
|
}
|
|
|
|
}
|
2017-07-07 10:10:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if anime.GetMapping("shoboi/anime") != "" {
|
|
|
|
shoboi["Connected with Shoboi"]++
|
|
|
|
} else {
|
|
|
|
shoboi["Not connected with Shoboi"]++
|
|
|
|
}
|
|
|
|
|
|
|
|
if anime.GetMapping("anilist/anime") != "" {
|
2017-07-07 14:06:46 +00:00
|
|
|
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"]++
|
2017-07-07 10:10:27 +00:00
|
|
|
} else {
|
2017-07-07 14:06:46 +00:00
|
|
|
anidb["Not connected with AniDB"]++
|
2017-07-07 10:10:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rating[arn.ToString(int(anime.Rating.Overall+0.5))]++
|
|
|
|
|
2017-07-10 20:35:48 +00:00
|
|
|
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"]++
|
|
|
|
}
|
|
|
|
|
2017-07-07 10:10:27 +00:00
|
|
|
status[anime.Status]++
|
|
|
|
types[anime.Type]++
|
|
|
|
}
|
|
|
|
|
|
|
|
println("Finished anime statistics")
|
|
|
|
|
|
|
|
return []*arn.PieChart{
|
|
|
|
arn.NewPieChart("Type", types),
|
|
|
|
arn.NewPieChart("Status", status),
|
|
|
|
arn.NewPieChart("Rating", rating),
|
2017-07-07 14:06:46 +00:00
|
|
|
arn.NewPieChart("MyAnimeList", mal),
|
|
|
|
arn.NewPieChart("AniList", anilist),
|
|
|
|
arn.NewPieChart("AniDB", anidb),
|
2017-07-07 10:10:27 +00:00
|
|
|
arn.NewPieChart("Shoboi", shoboi),
|
2017-07-10 20:35:48 +00:00
|
|
|
arn.NewPieChart("AnimeTwist", twist),
|
2017-07-07 14:06:46 +00:00
|
|
|
// arn.NewPieChart("MyAnimeList Editors", malEdits),
|
|
|
|
arn.NewPieChart("AniList Editors", anilistEdits),
|
|
|
|
// arn.NewPieChart("AniDB Editors", anidbEdits),
|
2017-07-07 10:10:27 +00:00
|
|
|
arn.NewPieChart("Shoboi Editors", shoboiEdits),
|
|
|
|
}
|
|
|
|
}
|