From 1524d9f504635acb6199464542de80d6f0730d36 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Wed, 10 Oct 2018 18:37:31 +0900 Subject: [PATCH] Improved statistics on genre pages --- pages/genre/genre.go | 12 ++++++------ pages/genre/genre.pixy | 10 +++++----- pages/genre/genre.scarlet | 9 +++++++-- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/pages/genre/genre.go b/pages/genre/genre.go index 6682f179..01283d46 100644 --- a/pages/genre/genre.go +++ b/pages/genre/genre.go @@ -10,9 +10,9 @@ import ( ) const animePerPage = 100 -const animeRatingThreshold = 5 +const animeRatingCountThreshold = 5 -// Get ... +// Get renders the genre page. func Get(ctx *aero.Context) string { user := utils.GetUser(ctx) genreName := ctx.Get("name") @@ -48,7 +48,7 @@ func containsLowerCase(array []string, search string) bool { 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 { if user == nil { return 0 @@ -75,13 +75,13 @@ func averageUserScore(user *arn.User, animes []*arn.Anime) float64 { 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 { sum := 0.0 count := 0 for _, anime := range animes { - if anime.Rating.Count.Overall >= animeRatingThreshold { + if anime.Rating.Count.Overall >= animeRatingCountThreshold { sum += anime.Rating.Overall count++ } @@ -90,7 +90,7 @@ func averageGlobalScore(animes []*arn.Anime) float64 { 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 { if user == nil { return 0 diff --git a/pages/genre/genre.pixy b/pages/genre/genre.pixy index de4079e8..b608716e 100644 --- a/pages/genre/genre.pixy +++ b/pages/genre/genre.pixy @@ -1,7 +1,8 @@ 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 if user != nil @@ -14,6 +15,5 @@ component Genre(genre string, animes []*arn.Anime, user *arn.User, userScore flo AnimeGrid(animes, user) component GenreStatistics(user *arn.User, userScore float64, userCompleted int, globalScore float64) - if user != nil - .average-score-total-completed - p= fmt.Sprintf("Average rating: %." + strconv.Itoa(user.Settings().Format.RatingsPrecision) + "f | Total completed: %d", userScore, userCompleted) \ No newline at end of file + .genre-statistics + p= fmt.Sprintf("Your average rating: %." + strconv.Itoa(user.Settings().Format.RatingsPrecision) + "f | Total completed: %d", userScore, userCompleted) \ No newline at end of file diff --git a/pages/genre/genre.scarlet b/pages/genre/genre.scarlet index 254172df..f5870e96 100644 --- a/pages/genre/genre.scarlet +++ b/pages/genre/genre.scarlet @@ -1,3 +1,8 @@ -.average-score-total-completed +.genre-title + margin-bottom 0.5rem + +.genre-statistics text-align center - font-size 1.25em \ No newline at end of file + opacity 0.5 + font-size 0.9rem + margin-bottom content-padding \ No newline at end of file