Show only float with 1 decimal for consistency.
This commit is contained in:
parent
524c39b283
commit
1e5f654928
@ -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
|
||||||
|
|
||||||
for _, anime := range animes {
|
animeList := user.AnimeList()
|
||||||
|
|
||||||
if user.AnimeList().Contains(anime.ID) {
|
for _, anime := range animes {
|
||||||
scores = scores + user.AnimeList().Find(anime.ID).Rating.Overall
|
userAnime := animeList.Find(anime.ID)
|
||||||
counter = counter + 1
|
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
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user