Merge pull request #169 from Amatrelan/go
Basic implementation of Genre scores
This commit is contained in:
commit
1234120628
@ -23,13 +23,15 @@ func Get(ctx *aero.Context) string {
|
||||
}
|
||||
}
|
||||
|
||||
userScore := averageScore(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 +44,30 @@ func containsLowerCase(array []string, search string) bool {
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// Counts users average score for selected animes
|
||||
func averageScore(user *arn.User, animes []*arn.Anime) float64 {
|
||||
if user == nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
count := 0.0
|
||||
scores := 0.0
|
||||
|
||||
animeList := user.AnimeList()
|
||||
|
||||
for _, anime := range animes {
|
||||
userAnime := animeList.Find(anime.ID)
|
||||
|
||||
if userAnime != nil && !userAnime.Rating.IsNotRated() {
|
||||
scores += userAnime.Rating.Overall
|
||||
count++
|
||||
}
|
||||
}
|
||||
|
||||
if count == 0.0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
return scores / count
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
component Genre(genre string, animes []*arn.Anime, user *arn.User)
|
||||
component Genre(genre string, animes []*arn.Anime, user *arn.User, userScore float64)
|
||||
h1(title=fmt.Sprint(len(animes)) + " anime")= strings.Title(genre)
|
||||
|
||||
if user != nil
|
||||
h2= fmt.Sprintf("%.1f", userScore)
|
||||
|
||||
.corner-buttons-hide-on-mobile
|
||||
if user != nil
|
||||
button.action(data-trigger="click", data-action="hideAddedAnime", title="Hide anime in my collection")
|
||||
|
Loading…
Reference in New Issue
Block a user