Nano integration improvements
This commit is contained in:
@ -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),
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user