Improved statistics on genre pages

This commit is contained in:
Eduard Urbach 2018-10-10 18:37:31 +09:00
parent 732e9c6970
commit 1524d9f504
3 changed files with 18 additions and 13 deletions

View File

@ -10,9 +10,9 @@ import (
) )
const animePerPage = 100 const animePerPage = 100
const animeRatingThreshold = 5 const animeRatingCountThreshold = 5
// Get ... // Get renders the genre page.
func Get(ctx *aero.Context) string { func Get(ctx *aero.Context) string {
user := utils.GetUser(ctx) user := utils.GetUser(ctx)
genreName := ctx.Get("name") genreName := ctx.Get("name")
@ -48,7 +48,7 @@ func containsLowerCase(array []string, search string) bool {
return false return false
} }
// averageUserScore counts the user's average score for the given animes. // averageUserScore counts the user's average score for a list of anime.
func averageUserScore(user *arn.User, animes []*arn.Anime) float64 { func averageUserScore(user *arn.User, animes []*arn.Anime) float64 {
if user == nil { if user == nil {
return 0 return 0
@ -75,13 +75,13 @@ func averageUserScore(user *arn.User, animes []*arn.Anime) float64 {
return scores / count return scores / count
} }
// averageGlobalScore returns the average overall score for the given anime // averageGlobalScore returns the average overall score for the given anime.
func averageGlobalScore(animes []*arn.Anime) float64 { func averageGlobalScore(animes []*arn.Anime) float64 {
sum := 0.0 sum := 0.0
count := 0 count := 0
for _, anime := range animes { for _, anime := range animes {
if anime.Rating.Count.Overall >= animeRatingThreshold { if anime.Rating.Count.Overall >= animeRatingCountThreshold {
sum += anime.Rating.Overall sum += anime.Rating.Overall
count++ count++
} }
@ -90,7 +90,7 @@ func averageGlobalScore(animes []*arn.Anime) float64 {
return sum / float64(count) return sum / float64(count)
} }
// totalCompleted counts the number of animes the user has completed from a given list of anime // totalCompleted counts the number of anime the user has completed from a given list of anime.
func totalCompleted(user *arn.User, animes []*arn.Anime) int { func totalCompleted(user *arn.User, animes []*arn.Anime) int {
if user == nil { if user == nil {
return 0 return 0

View File

@ -1,7 +1,8 @@
component Genre(genre string, animes []*arn.Anime, user *arn.User, userScore float64, userCompleted int, globalScore float64) component Genre(genre string, animes []*arn.Anime, user *arn.User, userScore float64, userCompleted int, globalScore float64)
h1(title=fmt.Sprint(len(animes)) + " anime")= strings.Title(genre) h1.genre-title(title=fmt.Sprint(len(animes)) + " anime")= strings.Title(genre)
GenreStatistics(user, userScore, userCompleted, globalScore) if user != nil
GenreStatistics(user, userScore, userCompleted, globalScore)
.corner-buttons-hide-on-mobile .corner-buttons-hide-on-mobile
if user != nil if user != nil
@ -14,6 +15,5 @@ component Genre(genre string, animes []*arn.Anime, user *arn.User, userScore flo
AnimeGrid(animes, user) AnimeGrid(animes, user)
component GenreStatistics(user *arn.User, userScore float64, userCompleted int, globalScore float64) component GenreStatistics(user *arn.User, userScore float64, userCompleted int, globalScore float64)
if user != nil .genre-statistics
.average-score-total-completed p= fmt.Sprintf("Your average rating: %." + strconv.Itoa(user.Settings().Format.RatingsPrecision) + "f | Total completed: %d", userScore, userCompleted)
p= fmt.Sprintf("Average rating: %." + strconv.Itoa(user.Settings().Format.RatingsPrecision) + "f | Total completed: %d", userScore, userCompleted)

View File

@ -1,3 +1,8 @@
.average-score-total-completed .genre-title
margin-bottom 0.5rem
.genre-statistics
text-align center text-align center
font-size 1.25em opacity 0.5
font-size 0.9rem
margin-bottom content-padding