Show only float with 1 decimal for consistency.

This commit is contained in:
Jarmo Riikonen 2018-07-03 13:13:38 +03:00
parent 524c39b283
commit 1e5f654928
2 changed files with 20 additions and 13 deletions

View File

@ -1,7 +1,6 @@
package genre
import (
"strconv"
"strings"
"github.com/aerogo/aero"
@ -24,7 +23,7 @@ func Get(ctx *aero.Context) string {
}
}
userScore := averageGenreScore(user, animes)
userScore := averageScore(user, animes)
arn.SortAnimeByQuality(animes)
@ -46,21 +45,28 @@ func containsLowerCase(array []string, search string) bool {
return false
}
func averageGenreScore(user *arn.User, animes []*arn.Anime) string {
// Counts users average score in genre
func averageScore(user *arn.User, animes []*arn.Anime) float64 {
if user == nil {
return ""
return 0
}
counter := 0.0
count := 0.0
scores := 0.0
animeList := user.AnimeList()
for _, anime := range animes {
if user.AnimeList().Contains(anime.ID) {
scores = scores + user.AnimeList().Find(anime.ID).Rating.Overall
counter = counter + 1
userAnime := animeList.Find(anime.ID)
if userAnime != nil && !userAnime.Rating.IsNotRated() {
scores += userAnime.Rating.Overall
count += 1
}
}
return strconv.FormatFloat(scores/counter, 'f', 6, 64)
if count == 0.0 || scores == 0.0 {
return 0
}
return scores / count
}

View File

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