Nano integration improvements
This commit is contained in:
parent
b07a98ed32
commit
76e5f37eca
@ -1,114 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/fatih/color"
|
||||
)
|
||||
|
||||
func main() {
|
||||
color.Yellow("Caching list of active users")
|
||||
|
||||
// Filter out active users with an avatar
|
||||
users, err := arn.FilterUsers(func(user *arn.User) bool {
|
||||
return user.IsActive() && user.Avatar.Extension != ""
|
||||
})
|
||||
fmt.Println(len(users))
|
||||
|
||||
arn.PanicOnError(err)
|
||||
|
||||
// Sort
|
||||
sort.Slice(users, func(i, j int) bool {
|
||||
if users[i].LastSeen < users[j].LastSeen {
|
||||
return false
|
||||
}
|
||||
|
||||
if users[i].LastSeen > users[j].LastSeen {
|
||||
return true
|
||||
}
|
||||
|
||||
return users[i].Registered > users[j].Registered
|
||||
})
|
||||
|
||||
// Add users to list
|
||||
SaveInCache("active users", users)
|
||||
|
||||
// Sort by osu rank
|
||||
osuUsers := users[:]
|
||||
|
||||
sort.Slice(osuUsers, func(i, j int) bool {
|
||||
return osuUsers[i].Accounts.Osu.PP > osuUsers[j].Accounts.Osu.PP
|
||||
})
|
||||
|
||||
// Cut off users with 0 pp
|
||||
for index, user := range osuUsers {
|
||||
if user.Accounts.Osu.PP == 0 {
|
||||
osuUsers = osuUsers[:index]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Save osu users
|
||||
SaveInCache("active osu users", osuUsers)
|
||||
|
||||
// Sort by role
|
||||
staff := users[:]
|
||||
|
||||
sort.Slice(staff, func(i, j int) bool {
|
||||
if staff[i].Role == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
if staff[j].Role == "" {
|
||||
return true
|
||||
}
|
||||
|
||||
return staff[i].Role == "admin"
|
||||
})
|
||||
|
||||
// Cut off non-staff
|
||||
for index, user := range staff {
|
||||
if user.Role == "" {
|
||||
staff = staff[:index]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Save staff users
|
||||
SaveInCache("active staff users", staff)
|
||||
|
||||
// Sort by anime watching list length
|
||||
watching := users[:]
|
||||
|
||||
sort.Slice(watching, func(i, j int) bool {
|
||||
return len(watching[i].AnimeList().FilterStatus(arn.AnimeListStatusWatching).Items) > len(watching[j].AnimeList().FilterStatus(arn.AnimeListStatusWatching).Items)
|
||||
})
|
||||
|
||||
// Save watching users
|
||||
SaveInCache("active anime watching users", watching)
|
||||
|
||||
color.Green("Finished.")
|
||||
}
|
||||
|
||||
// SaveInCache ...
|
||||
func SaveInCache(key string, users []*arn.User) {
|
||||
cache := arn.ListOfIDs{
|
||||
IDList: GenerateIDList(users),
|
||||
}
|
||||
|
||||
fmt.Println(len(cache.IDList), key)
|
||||
arn.PanicOnError(arn.DB.Set("Cache", key, cache))
|
||||
}
|
||||
|
||||
// GenerateIDList generates an ID list from a slice of users.
|
||||
func GenerateIDList(users []*arn.User) []string {
|
||||
list := []string{}
|
||||
|
||||
for _, user := range users {
|
||||
list = append(list, user.ID)
|
||||
}
|
||||
|
||||
return list
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/fatih/color"
|
||||
)
|
||||
|
||||
const (
|
||||
currentlyAiringBonus = 5.0
|
||||
popularityThreshold = 5
|
||||
popularityPenalty = 8.0
|
||||
watchingPopularityWeight = 0.3
|
||||
plannedPopularityWeight = 0.2
|
||||
)
|
||||
|
||||
func main() {
|
||||
color.Yellow("Caching airing anime")
|
||||
|
||||
animeList, err := arn.GetAiringAnime()
|
||||
|
||||
if err != nil {
|
||||
color.Red("Failed fetching airing anime")
|
||||
color.Red(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
sort.Slice(animeList, func(i, j int) bool {
|
||||
a := animeList[i]
|
||||
b := animeList[j]
|
||||
scoreA := a.Rating.Overall
|
||||
scoreB := b.Rating.Overall
|
||||
|
||||
if a.Status == "current" {
|
||||
scoreA += currentlyAiringBonus
|
||||
}
|
||||
|
||||
if b.Status == "current" {
|
||||
scoreB += currentlyAiringBonus
|
||||
}
|
||||
|
||||
if a.Popularity.Total() < popularityThreshold {
|
||||
scoreA -= popularityPenalty
|
||||
}
|
||||
|
||||
if b.Popularity.Total() < popularityThreshold {
|
||||
scoreB -= popularityPenalty
|
||||
}
|
||||
|
||||
scoreA += float64(a.Popularity.Watching) * watchingPopularityWeight
|
||||
scoreB += float64(b.Popularity.Watching) * watchingPopularityWeight
|
||||
|
||||
scoreA += float64(a.Popularity.Planned) * plannedPopularityWeight
|
||||
scoreB += float64(b.Popularity.Planned) * plannedPopularityWeight
|
||||
|
||||
return scoreA > scoreB
|
||||
})
|
||||
|
||||
// Convert to small anime list
|
||||
cache := &arn.ListOfIDs{}
|
||||
|
||||
for _, anime := range animeList {
|
||||
cache.IDList = append(cache.IDList, anime.ID)
|
||||
}
|
||||
|
||||
println(len(cache.IDList))
|
||||
|
||||
saveErr := arn.DB.Set("Cache", "airing anime", cache)
|
||||
|
||||
if saveErr != nil {
|
||||
color.Red("Error saving airing anime")
|
||||
color.Red(saveErr.Error())
|
||||
return
|
||||
}
|
||||
|
||||
color.Green("Finished.")
|
||||
}
|
@ -24,10 +24,7 @@ var colorPool = []*color.Color{
|
||||
|
||||
var jobs = map[string]time.Duration{
|
||||
"forum-activity": 1 * time.Minute,
|
||||
"active-users": 5 * time.Minute,
|
||||
"anime-ratings": 10 * time.Minute,
|
||||
"airing-anime": 10 * time.Minute,
|
||||
"statistics": 15 * time.Minute,
|
||||
"popular-anime": 20 * time.Minute,
|
||||
"avatars": 1 * time.Hour,
|
||||
"test": 1 * time.Hour,
|
||||
|
@ -1,251 +0,0 @@
|
||||
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,
|
||||
}))
|
||||
|
||||
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{}
|
||||
notifications := stats{}
|
||||
avatar := stats{}
|
||||
ip := stats{}
|
||||
pro := stats{}
|
||||
|
||||
for _, info := range analytics {
|
||||
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.MustStreamUsers() {
|
||||
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"]++
|
||||
}
|
||||
}
|
||||
|
||||
println("Finished user statistics")
|
||||
|
||||
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),
|
||||
}
|
||||
}
|
||||
|
||||
func getAnimeStats() []*arn.PieChart {
|
||||
println("Generating anime statistics")
|
||||
|
||||
allAnime, err := arn.AllAnime()
|
||||
arn.PanicOnError(err)
|
||||
|
||||
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 allAnime {
|
||||
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]++
|
||||
}
|
||||
|
||||
println("Finished anime statistics")
|
||||
|
||||
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),
|
||||
}
|
||||
}
|
3
main.go
3
main.go
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/aerogo/session-store-nano"
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/animenotifier/notify.moe/auth"
|
||||
"github.com/animenotifier/notify.moe/components/css"
|
||||
@ -70,8 +71,8 @@ func configure(app *aero.Application) *aero.Application {
|
||||
app.Sessions.Duration = 3600 * 24 * 30 * 6
|
||||
|
||||
// TODO: ...
|
||||
println("Using memory session store")
|
||||
// app.Sessions.Store = aerospikestore.New(arn.DB, "Session", app.Sessions.Duration)
|
||||
app.Sessions.Store = nanostore.New(arn.DB, "Session")
|
||||
|
||||
// Layout
|
||||
app.Layout = layout.Render
|
||||
|
@ -1,10 +1,7 @@
|
||||
package best
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/animenotifier/notify.moe/components"
|
||||
)
|
||||
|
||||
@ -12,35 +9,5 @@ const maxEntries = 7
|
||||
|
||||
// Get search page.
|
||||
func Get(ctx *aero.Context) string {
|
||||
overall, err := arn.GetListOfAnimeCached("best anime overall")
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusInternalServerError, "Error fetching popular anime", err)
|
||||
}
|
||||
|
||||
story, err := arn.GetListOfAnimeCached("best anime story")
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusInternalServerError, "Error fetching popular anime", err)
|
||||
}
|
||||
|
||||
visuals, err := arn.GetListOfAnimeCached("best anime visuals")
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusInternalServerError, "Error fetching popular anime", err)
|
||||
}
|
||||
|
||||
soundtrack, err := arn.GetListOfAnimeCached("best anime soundtrack")
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusInternalServerError, "Error fetching popular anime", err)
|
||||
}
|
||||
|
||||
airing, err := arn.GetAiringAnimeCached()
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(500, "Couldn't fetch airing anime", err)
|
||||
}
|
||||
|
||||
return ctx.HTML(components.BestAnime(overall[:maxEntries], story[:maxEntries], visuals[:maxEntries], soundtrack[:maxEntries], airing[:maxEntries]))
|
||||
return ctx.HTML(components.BestAnime(nil, nil, nil, nil, nil))
|
||||
}
|
||||
|
@ -1,20 +1,55 @@
|
||||
package explore
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/animenotifier/notify.moe/components"
|
||||
)
|
||||
|
||||
const (
|
||||
currentlyAiringBonus = 5.0
|
||||
popularityThreshold = 5
|
||||
popularityPenalty = 8.0
|
||||
watchingPopularityWeight = 0.3
|
||||
plannedPopularityWeight = 0.2
|
||||
)
|
||||
|
||||
// Get ...
|
||||
func Get(ctx *aero.Context) string {
|
||||
// var cache arn.ListOfIDs
|
||||
// err := arn.DB.GetObject("Cache", "airing anime", &cache)
|
||||
animeList := arn.GetAiringAnime()
|
||||
|
||||
// airing, err := arn.GetAiringAnimeCached()
|
||||
sort.Slice(animeList, func(i, j int) bool {
|
||||
a := animeList[i]
|
||||
b := animeList[j]
|
||||
scoreA := a.Rating.Overall
|
||||
scoreB := b.Rating.Overall
|
||||
|
||||
// if err != nil {
|
||||
// return ctx.Error(500, "Couldn't fetch airing anime", err)
|
||||
// }
|
||||
|
||||
// return ctx.HTML(components.Airing(airing))
|
||||
return ctx.HTML("Not implemented")
|
||||
if a.Status == "current" {
|
||||
scoreA += currentlyAiringBonus
|
||||
}
|
||||
|
||||
if b.Status == "current" {
|
||||
scoreB += currentlyAiringBonus
|
||||
}
|
||||
|
||||
if a.Popularity.Total() < popularityThreshold {
|
||||
scoreA -= popularityPenalty
|
||||
}
|
||||
|
||||
if b.Popularity.Total() < popularityThreshold {
|
||||
scoreB -= popularityPenalty
|
||||
}
|
||||
|
||||
scoreA += float64(a.Popularity.Watching) * watchingPopularityWeight
|
||||
scoreB += float64(b.Popularity.Watching) * watchingPopularityWeight
|
||||
|
||||
scoreA += float64(a.Popularity.Planned) * plannedPopularityWeight
|
||||
scoreB += float64(b.Popularity.Planned) * plannedPopularityWeight
|
||||
|
||||
return scoreA > scoreB
|
||||
})
|
||||
|
||||
return ctx.HTML(components.Explore(animeList))
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
component Airing(animeList []*arn.Anime)
|
||||
component Explore(animeList []*arn.Anime)
|
||||
h1.page-title(title=toString(len(animeList)) + " anime") Explore
|
||||
AnimeGrid(animeList)
|
@ -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
|
||||
|
@ -1,7 +1,7 @@
|
||||
package users
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"sort"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
@ -21,11 +21,14 @@ func Active(ctx *aero.Context) string {
|
||||
|
||||
// Osu ...
|
||||
func Osu(ctx *aero.Context) string {
|
||||
users, err := arn.GetListOfUsersCached("active osu users")
|
||||
users := arn.FilterUsers(func(user *arn.User) bool {
|
||||
return user.IsActive() && user.HasAvatar() && user.Accounts.Osu.PP > 0
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusInternalServerError, "Could not fetch user data", err)
|
||||
}
|
||||
// Sort by pp
|
||||
sort.Slice(users, func(i, j int) bool {
|
||||
return users[i].Accounts.Osu.PP > users[j].Accounts.Osu.PP
|
||||
})
|
||||
|
||||
if len(users) > 50 {
|
||||
users = users[:50]
|
||||
@ -36,22 +39,34 @@ func Osu(ctx *aero.Context) string {
|
||||
|
||||
// Staff ...
|
||||
func Staff(ctx *aero.Context) string {
|
||||
users, err := arn.GetListOfUsersCached("active staff users")
|
||||
users := arn.FilterUsers(func(user *arn.User) bool {
|
||||
return user.IsActive() && user.HasAvatar() && user.Role != ""
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusInternalServerError, "Could not fetch user data", err)
|
||||
sort.Slice(users, func(i, j int) bool {
|
||||
if users[i].Role == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
if users[j].Role == "" {
|
||||
return true
|
||||
}
|
||||
|
||||
return users[i].Role == "admin"
|
||||
})
|
||||
|
||||
return ctx.HTML(components.Users(users))
|
||||
}
|
||||
|
||||
// AnimeWatching ...
|
||||
func AnimeWatching(ctx *aero.Context) string {
|
||||
users, err := arn.GetListOfUsersCached("active anime watching users")
|
||||
users := arn.FilterUsers(func(user *arn.User) bool {
|
||||
return user.IsActive() && user.HasAvatar()
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusInternalServerError, "Could not fetch user data", err)
|
||||
}
|
||||
sort.Slice(users, func(i, j int) bool {
|
||||
return len(users[i].AnimeList().Watching().Items) > len(users[j].AnimeList().Watching().Items)
|
||||
})
|
||||
|
||||
return ctx.HTML(components.Users(users))
|
||||
}
|
||||
|
@ -87,8 +87,6 @@ class MyServiceWorker {
|
||||
onRequest(evt: FetchEvent) {
|
||||
let request = evt.request as Request
|
||||
|
||||
// console.log("fetch:", request.url)
|
||||
|
||||
// If it's not a GET request, fetch it normally
|
||||
if(request.method !== "GET") {
|
||||
return evt.respondWith(fetch(request))
|
||||
@ -96,7 +94,7 @@ class MyServiceWorker {
|
||||
|
||||
// Clear cache on authentication and fetch it normally
|
||||
if(request.url.includes("/auth/") || request.url.includes("/logout")) {
|
||||
return caches.delete(this.cache.version).then(() => evt.respondWith(fetch(request)))
|
||||
return evt.respondWith(caches.delete(this.cache.version).then(() => fetch(request)))
|
||||
}
|
||||
|
||||
// Exclude certain URLs from being cached
|
||||
@ -109,7 +107,7 @@ class MyServiceWorker {
|
||||
// If the request included the header "X-CacheOnly", return a cache-only response.
|
||||
// This is used in reloads to avoid generating a 2nd request after a cache refresh.
|
||||
if(request.headers.get("X-CacheOnly") === "true") {
|
||||
return this.fromCache(request)
|
||||
return evt.respondWith(this.fromCache(request))
|
||||
}
|
||||
|
||||
// Start fetching the request
|
||||
|
Loading…
Reference in New Issue
Block a user