Anime ratings
This commit is contained in:
parent
7215dffb3b
commit
db347c7470
94
jobs/anime-ratings/main.go
Normal file
94
jobs/anime-ratings/main.go
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/animenotifier/arn"
|
||||||
|
"github.com/fatih/color"
|
||||||
|
)
|
||||||
|
|
||||||
|
var ratings = map[string][]*arn.AnimeRating{}
|
||||||
|
var finalRating = map[string]*arn.AnimeRating{}
|
||||||
|
|
||||||
|
// Note this is using the airing-anime as a template with modfications
|
||||||
|
// made to it.
|
||||||
|
func main() {
|
||||||
|
color.Yellow("Updating anime ratings")
|
||||||
|
|
||||||
|
allAnimeLists, err := arn.AllAnimeLists()
|
||||||
|
arn.PanicOnError(err)
|
||||||
|
|
||||||
|
for _, animeList := range allAnimeLists {
|
||||||
|
extractRatings(animeList)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate
|
||||||
|
for animeID := range finalRating {
|
||||||
|
overall := []float64{}
|
||||||
|
story := []float64{}
|
||||||
|
visuals := []float64{}
|
||||||
|
soundtrack := []float64{}
|
||||||
|
|
||||||
|
for _, rating := range ratings[animeID] {
|
||||||
|
if rating.Overall != 0 {
|
||||||
|
overall = append(overall, rating.Overall)
|
||||||
|
}
|
||||||
|
|
||||||
|
if rating.Story != 0 {
|
||||||
|
story = append(story, rating.Story)
|
||||||
|
}
|
||||||
|
|
||||||
|
if rating.Visuals != 0 {
|
||||||
|
visuals = append(visuals, rating.Visuals)
|
||||||
|
}
|
||||||
|
|
||||||
|
if rating.Soundtrack != 0 {
|
||||||
|
soundtrack = append(soundtrack, rating.Soundtrack)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
finalRating[animeID].Overall = average(overall)
|
||||||
|
finalRating[animeID].Story = average(story)
|
||||||
|
finalRating[animeID].Visuals = average(visuals)
|
||||||
|
finalRating[animeID].Soundtrack = average(soundtrack)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save
|
||||||
|
for animeID := range finalRating {
|
||||||
|
anime, err := arn.GetAnime(animeID)
|
||||||
|
arn.PanicOnError(err)
|
||||||
|
anime.Rating = finalRating[animeID]
|
||||||
|
arn.PanicOnError(anime.Save())
|
||||||
|
}
|
||||||
|
|
||||||
|
color.Green("Finished.")
|
||||||
|
}
|
||||||
|
|
||||||
|
func average(floatSlice []float64) float64 {
|
||||||
|
if len(floatSlice) == 0 {
|
||||||
|
return arn.DefaultAverageRating
|
||||||
|
}
|
||||||
|
|
||||||
|
var sum float64
|
||||||
|
|
||||||
|
for _, value := range floatSlice {
|
||||||
|
sum += value
|
||||||
|
}
|
||||||
|
|
||||||
|
return sum / float64(len(floatSlice))
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractRatings(animeList *arn.AnimeList) {
|
||||||
|
for _, item := range animeList.Items {
|
||||||
|
if item.Rating.IsNotRated() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
_, found := ratings[item.AnimeID]
|
||||||
|
|
||||||
|
if !found {
|
||||||
|
ratings[item.AnimeID] = []*arn.AnimeRating{}
|
||||||
|
finalRating[item.AnimeID] = &arn.AnimeRating{}
|
||||||
|
}
|
||||||
|
|
||||||
|
ratings[item.AnimeID] = append(ratings[item.AnimeID], item.Rating)
|
||||||
|
}
|
||||||
|
}
|
@ -25,7 +25,8 @@ var colorPool = []*color.Color{
|
|||||||
var jobs = map[string]time.Duration{
|
var jobs = map[string]time.Duration{
|
||||||
"active-users": 1 * time.Minute,
|
"active-users": 1 * time.Minute,
|
||||||
"forum-activity": 1 * time.Minute,
|
"forum-activity": 1 * time.Minute,
|
||||||
"avatars": 1 * time.Hour,
|
"anime-ratings": 15 * time.Minute,
|
||||||
|
"avatars": 30 * time.Minute,
|
||||||
"refresh-track-titles": 10 * time.Hour,
|
"refresh-track-titles": 10 * time.Hour,
|
||||||
"sync-anime": 12 * time.Hour,
|
"sync-anime": 12 * time.Hour,
|
||||||
"popular-anime": 12 * time.Hour,
|
"popular-anime": 12 * time.Hour,
|
||||||
|
@ -3,7 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/animenotifier/arn"
|
"github.com/animenotifier/arn"
|
||||||
@ -83,13 +82,13 @@ func sync(data *kitsu.Anime) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Rating
|
// Rating
|
||||||
overall, convertError := strconv.ParseFloat(attr.AverageRating, 64)
|
if anime.Rating == nil {
|
||||||
|
anime.Rating = &arn.AnimeRating{}
|
||||||
if convertError != nil {
|
|
||||||
overall = 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
anime.Rating.Overall = overall
|
if anime.Rating.IsNotRated() {
|
||||||
|
anime.Rating.Reset()
|
||||||
|
}
|
||||||
|
|
||||||
// Trailers
|
// Trailers
|
||||||
anime.Trailers = []*arn.ExternalMedia{}
|
anime.Trailers = []*arn.ExternalMedia{}
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
component Rating(value float64)
|
component Rating(value float64)
|
||||||
.anime-rating= int(value / 10 + 0.5)
|
.anime-rating= int(value + 0.5)
|
@ -37,16 +37,16 @@ component Anime(anime *arn.Anime, tracks []*arn.SoundTrack, user *arn.User, epis
|
|||||||
|
|
||||||
h3.anime-section-name Ratings
|
h3.anime-section-name Ratings
|
||||||
.anime-rating-categories
|
.anime-rating-categories
|
||||||
.anime-rating-category(title=toString(anime.Rating.Overall / 10))
|
.anime-rating-category(title=toString(anime.Rating.Overall))
|
||||||
.anime-rating-category-name Overall
|
.anime-rating-category-name Overall
|
||||||
Rating(anime.Rating.Overall)
|
Rating(anime.Rating.Overall)
|
||||||
.anime-rating-category(title=toString(anime.Rating.Story / 10))
|
.anime-rating-category(title=toString(anime.Rating.Story))
|
||||||
.anime-rating-category-name Story
|
.anime-rating-category-name Story
|
||||||
Rating(anime.Rating.Story)
|
Rating(anime.Rating.Story)
|
||||||
.anime-rating-category(title=toString(anime.Rating.Visuals / 10))
|
.anime-rating-category(title=toString(anime.Rating.Visuals))
|
||||||
.anime-rating-category-name Visuals
|
.anime-rating-category-name Visuals
|
||||||
Rating(anime.Rating.Visuals)
|
Rating(anime.Rating.Visuals)
|
||||||
.anime-rating-category(title=toString(anime.Rating.Soundtrack / 10))
|
.anime-rating-category(title=toString(anime.Rating.Soundtrack))
|
||||||
.anime-rating-category-name Soundtrack
|
.anime-rating-category-name Soundtrack
|
||||||
Rating(anime.Rating.Soundtrack)
|
Rating(anime.Rating.Soundtrack)
|
||||||
|
|
||||||
|
10
patches/clear-anime-ratings/main.go
Normal file
10
patches/clear-anime-ratings/main.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "github.com/animenotifier/arn"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
for anime := range arn.MustStreamAnime() {
|
||||||
|
anime.Rating.Reset()
|
||||||
|
anime.MustSave()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user