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:
parent
ec2d9d98fd
commit
54e0f4fc09
@ -1,6 +1,7 @@
|
||||
package genre
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
@ -23,13 +24,15 @@ func Get(ctx *aero.Context) string {
|
||||
}
|
||||
}
|
||||
|
||||
userScore := averageGenreScore(user, animes)
|
||||
|
||||
arn.SortAnimeByQuality(animes)
|
||||
|
||||
if len(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.
|
||||
@ -42,3 +45,22 @@ func containsLowerCase(array []string, search string) bool {
|
||||
|
||||
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)
|
||||
}
|
||||
|
@ -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)
|
||||
h2()= userScore
|
||||
|
||||
.corner-buttons-hide-on-mobile
|
||||
if user != nil
|
||||
|
Loading…
Reference in New Issue
Block a user