From e46c74d7b92bec41108db620db8a0516a61c4d63 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Thu, 22 Mar 2018 03:44:18 +0100 Subject: [PATCH] Improved rating system --- jobs/anime-ratings/anime-ratings.go | 26 +++++++++++++++++++++++++- jobs/mal-download/files/.gitignore | 3 --- mixins/Rating.pixy | 6 +++--- pages/anime/anime.pixy | 14 +++++++------- 4 files changed, 35 insertions(+), 14 deletions(-) delete mode 100644 jobs/mal-download/files/.gitignore diff --git a/jobs/anime-ratings/anime-ratings.go b/jobs/anime-ratings/anime-ratings.go index 875ed50a..ac4eee5b 100644 --- a/jobs/anime-ratings/anime-ratings.go +++ b/jobs/anime-ratings/anime-ratings.go @@ -48,6 +48,30 @@ func main() { } } + // Save number of people who rated on this + finalRating[animeID].Count.Overall = len(overall) + finalRating[animeID].Count.Story = len(story) + finalRating[animeID].Count.Visuals = len(visuals) + finalRating[animeID].Count.Soundtrack = len(soundtrack) + + // Dampen the rating if number of users is too low + if len(overall) < arn.RatingCountThreshold { + overall = append(overall, arn.AverageRating) + } + + if len(story) < arn.RatingCountThreshold { + story = append(story, arn.AverageRating) + } + + if len(visuals) < arn.RatingCountThreshold { + visuals = append(visuals, arn.AverageRating) + } + + if len(soundtrack) < arn.RatingCountThreshold { + soundtrack = append(soundtrack, arn.AverageRating) + } + + // Average rating finalRating[animeID].Overall = average(overall) finalRating[animeID].Story = average(story) finalRating[animeID].Visuals = average(visuals) @@ -75,7 +99,7 @@ func main() { func average(floatSlice []float64) float64 { if len(floatSlice) == 0 { - return arn.DefaultAverageRating + return 0 } var sum float64 diff --git a/jobs/mal-download/files/.gitignore b/jobs/mal-download/files/.gitignore deleted file mode 100644 index 34211e27..00000000 --- a/jobs/mal-download/files/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -* -!*/ -!.gitignore diff --git a/mixins/Rating.pixy b/mixins/Rating.pixy index 775f6a82..4607f535 100644 --- a/mixins/Rating.pixy +++ b/mixins/Rating.pixy @@ -1,5 +1,5 @@ -component Rating(value float64, user *arn.User) +component Rating(value float64, userCount int, user *arn.User) if user == nil - .anime-rating= fmt.Sprintf("%.1f", value) + .anime-rating(title="Rated by " + arn.Plural(userCount, "user"))= fmt.Sprintf("%.1f", value) else - .anime-rating= fmt.Sprintf("%." + strconv.Itoa(user.Settings().Format.RatingsPrecision) + "f", value) \ No newline at end of file + .anime-rating(title="Rated by " + arn.Plural(userCount, "user"))= fmt.Sprintf("%." + strconv.Itoa(user.Settings().Format.RatingsPrecision) + "f", value) \ No newline at end of file diff --git a/pages/anime/anime.pixy b/pages/anime/anime.pixy index 822935ce..50597592 100644 --- a/pages/anime/anime.pixy +++ b/pages/anime/anime.pixy @@ -67,25 +67,25 @@ component AnimeRatings(anime *arn.Anime, user *arn.User) else span Overall: td.anime-info-value - Rating(anime.Rating.Overall, user) + Rating(anime.Rating.Overall, anime.Rating.Count.Overall, user) - if anime.Rating.Story > 0 + if anime.Rating.Count.Story > 0 tr.mountable(data-mountable-type="info") td.anime-info-key Story: td.anime-info-value - Rating(anime.Rating.Story, user) + Rating(anime.Rating.Story, anime.Rating.Count.Story, user) - if anime.Rating.Visuals > 0 + if anime.Rating.Count.Visuals > 0 tr.mountable(data-mountable-type="info") td.anime-info-key Visuals: td.anime-info-value - Rating(anime.Rating.Visuals, user) + Rating(anime.Rating.Visuals, anime.Rating.Count.Visuals, user) - if anime.Rating.Soundtrack > 0 + if anime.Rating.Count.Soundtrack > 0 tr.mountable(data-mountable-type="info") td.anime-info-key Soundtrack: td.anime-info-value - Rating(anime.Rating.Soundtrack, user) + Rating(anime.Rating.Soundtrack, anime.Rating.Count.Soundtrack, user) component AnimePopularity(anime *arn.Anime) if anime.Popularity.Total() > 0