Improved statistics
This commit is contained in:
@ -1,76 +1,14 @@
|
||||
package statistics
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/animenotifier/notify.moe/components"
|
||||
"github.com/animenotifier/notify.moe/utils"
|
||||
)
|
||||
|
||||
// Anime ...
|
||||
func Anime(ctx *aero.Context) string {
|
||||
allAnime, err := arn.AllAnime()
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusInternalServerError, "Couldn't fetch anime", err)
|
||||
}
|
||||
|
||||
shoboi := stats{}
|
||||
anilist := stats{}
|
||||
status := stats{}
|
||||
types := stats{}
|
||||
shoboiEdits := stats{}
|
||||
anilistEdits := stats{}
|
||||
rating := stats{}
|
||||
|
||||
for _, anime := range allAnime {
|
||||
for _, external := range anime.Mappings {
|
||||
if external.Service == "shoboi/anime" {
|
||||
if external.CreatedBy == "" {
|
||||
shoboiEdits["Bot"]++
|
||||
} else {
|
||||
user, _ := arn.GetUser(external.CreatedBy)
|
||||
shoboiEdits[user.Nick]++
|
||||
}
|
||||
}
|
||||
|
||||
if external.Service == "anilist/anime" {
|
||||
if external.CreatedBy == "" {
|
||||
anilistEdits["Bot"]++
|
||||
} else {
|
||||
user, _ := arn.GetUser(external.CreatedBy)
|
||||
anilistEdits[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"]++
|
||||
}
|
||||
|
||||
rating[arn.ToString(int(anime.Rating.Overall+0.5))]++
|
||||
|
||||
status[anime.Status]++
|
||||
types[anime.Type]++
|
||||
}
|
||||
|
||||
return ctx.HTML(components.Statistics(
|
||||
utils.NewPieChart("Type", types),
|
||||
utils.NewPieChart("Status", status),
|
||||
utils.NewPieChart("Rating", rating),
|
||||
utils.NewPieChart("Anilist", anilist),
|
||||
utils.NewPieChart("Shoboi", shoboi),
|
||||
utils.NewPieChart("Anilist Editors", anilistEdits),
|
||||
utils.NewPieChart("Shoboi Editors", shoboiEdits),
|
||||
))
|
||||
statistics := arn.StatisticsCategory{}
|
||||
arn.DB.GetObject("Cache", "anime statistics", &statistics)
|
||||
return ctx.HTML(components.Statistics(statistics.PieCharts...))
|
||||
}
|
||||
|
@ -1,71 +1,14 @@
|
||||
package statistics
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/animenotifier/notify.moe/components"
|
||||
"github.com/animenotifier/notify.moe/utils"
|
||||
)
|
||||
|
||||
type stats = map[string]float64
|
||||
|
||||
// Get ...
|
||||
func Get(ctx *aero.Context) string {
|
||||
analytics, err := arn.AllAnalytics()
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusInternalServerError, "Couldn't fetch analytics", err)
|
||||
}
|
||||
|
||||
screenSize := stats{}
|
||||
// platform := stats{}
|
||||
pixelRatio := stats{}
|
||||
browser := stats{}
|
||||
country := stats{}
|
||||
gender := stats{}
|
||||
os := stats{}
|
||||
|
||||
for _, info := range analytics {
|
||||
// platform[info.System.Platform]++
|
||||
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() {
|
||||
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(
|
||||
utils.NewPieChart("OS", os),
|
||||
// utils.NewPieChart("Platform", platform),
|
||||
utils.NewPieChart("Screen size", screenSize),
|
||||
utils.NewPieChart("Browser", browser),
|
||||
utils.NewPieChart("Country", country),
|
||||
utils.NewPieChart("Gender", gender),
|
||||
utils.NewPieChart("Pixel ratio", pixelRatio),
|
||||
))
|
||||
statistics := arn.StatisticsCategory{}
|
||||
arn.DB.GetObject("Cache", "user statistics", &statistics)
|
||||
return ctx.HTML(components.Statistics(statistics.PieCharts...))
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
component Statistics(pieCharts ...*utils.PieChart)
|
||||
component Statistics(pieCharts ...*arn.PieChart)
|
||||
h1 Statistics
|
||||
|
||||
StatisticsHeader
|
||||
@ -19,7 +19,7 @@ component StatisticsHeader
|
||||
Icon("tv")
|
||||
span Anime
|
||||
|
||||
component PieChart(slices []*utils.PieChartSlice)
|
||||
component PieChart(slices []*arn.PieChartSlice)
|
||||
svg.pie-chart(viewBox="-1.1 -1.1 2.2 2.2")
|
||||
each slice in slices
|
||||
g
|
||||
|
Reference in New Issue
Block a user