Improved rating system

This commit is contained in:
Eduard Urbach 2018-03-22 03:44:18 +01:00
parent 8fa4d1b941
commit e46c74d7b9
4 changed files with 35 additions and 14 deletions

View File

@ -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

View File

@ -1,3 +0,0 @@
*
!*/
!.gitignore

View File

@ -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)
.anime-rating(title="Rated by " + arn.Plural(userCount, "user"))= fmt.Sprintf("%." + strconv.Itoa(user.Settings().Format.RatingsPrecision) + "f", value)

View File

@ -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