Overall score for Genre for user

Requires styling work (out of my skills 100%)
Basic mechanics added and someone should continue for styles.
This commit is contained in:
Jarmo Riikonen 2018-07-02 20:57:44 +03:00
parent ec2d9d98fd
commit 54e0f4fc09
2 changed files with 25 additions and 2 deletions

View File

@ -1,6 +1,7 @@
package genre package genre
import ( import (
"strconv"
"strings" "strings"
"github.com/aerogo/aero" "github.com/aerogo/aero"
@ -23,13 +24,15 @@ func Get(ctx *aero.Context) string {
} }
} }
userScore := averageGenreScore(user, animes)
arn.SortAnimeByQuality(animes) arn.SortAnimeByQuality(animes)
if len(animes) > animePerPage { if len(animes) > animePerPage {
animes = animes[:animePerPage] animes = animes[:animePerPage]
} }
return ctx.HTML(components.Genre(genreName, animes, user)) return ctx.HTML(components.Genre(genreName, animes, user, userScore))
} }
// containsLowerCase tells you whether the given element exists when all elements are lowercased. // containsLowerCase tells you whether the given element exists when all elements are lowercased.
@ -42,3 +45,22 @@ func containsLowerCase(array []string, search string) bool {
return false return false
} }
func averageGenreScore(user *arn.User, animes []*arn.Anime) string {
if user == nil {
return ""
}
counter := 0.0
scores := 0.0
for _, anime := range animes {
if user.AnimeList().Contains(anime.ID) {
scores = scores + user.AnimeList().Find(anime.ID).Rating.Overall
counter = counter + 1
}
}
return strconv.FormatFloat(scores/counter, 'f', 6, 64)
}

View File

@ -1,5 +1,6 @@
component Genre(genre string, animes []*arn.Anime, user *arn.User) component Genre(genre string, animes []*arn.Anime, user *arn.User, userScore string)
h1(title=fmt.Sprint(len(animes)) + " anime")= strings.Title(genre) h1(title=fmt.Sprint(len(animes)) + " anime")= strings.Title(genre)
h2()= userScore
.corner-buttons-hide-on-mobile .corner-buttons-hide-on-mobile
if user != nil if user != nil