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 package genre
import ( import (
"strconv"
"strings" "strings"
"github.com/aerogo/aero" "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) arn.SortAnimeByQuality(animes)
@ -46,21 +45,28 @@ func containsLowerCase(array []string, search string) bool {
return false 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 { if user == nil {
return "" return 0
} }
counter := 0.0 count := 0.0
scores := 0.0 scores := 0.0
animeList := user.AnimeList()
for _, anime := range animes { for _, anime := range animes {
userAnime := animeList.Find(anime.ID)
if user.AnimeList().Contains(anime.ID) { if userAnime != nil && !userAnime.Rating.IsNotRated() {
scores = scores + user.AnimeList().Find(anime.ID).Rating.Overall scores += userAnime.Rating.Overall
counter = counter + 1 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) 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 .corner-buttons-hide-on-mobile
if user != nil if user != nil