Merge pull request #187 from atjallen/iss94
UI for Genre: Average Rating and Total Completed Anime
This commit is contained in:
commit
732e9c6970
@ -10,6 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const animePerPage = 100
|
const animePerPage = 100
|
||||||
|
const animeRatingThreshold = 5
|
||||||
|
|
||||||
// Get ...
|
// Get ...
|
||||||
func Get(ctx *aero.Context) string {
|
func Get(ctx *aero.Context) string {
|
||||||
@ -23,7 +24,9 @@ func Get(ctx *aero.Context) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
userScore := averageScore(user, animes)
|
userScore := averageUserScore(user, animes)
|
||||||
|
userCompleted := totalCompleted(user, animes)
|
||||||
|
globalScore := averageGlobalScore(animes)
|
||||||
|
|
||||||
arn.SortAnimeByQuality(animes)
|
arn.SortAnimeByQuality(animes)
|
||||||
|
|
||||||
@ -31,7 +34,7 @@ func Get(ctx *aero.Context) string {
|
|||||||
animes = animes[:animePerPage]
|
animes = animes[:animePerPage]
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx.HTML(components.Genre(genreName, animes, user, userScore))
|
return ctx.HTML(components.Genre(genreName, animes, user, userScore, userCompleted, globalScore))
|
||||||
}
|
}
|
||||||
|
|
||||||
// containsLowerCase tells you whether the given element exists when all elements are lowercased.
|
// containsLowerCase tells you whether the given element exists when all elements are lowercased.
|
||||||
@ -45,8 +48,8 @@ func containsLowerCase(array []string, search string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// averageScore counts the user's average score for the given animes.
|
// averageUserScore counts the user's average score for the given animes.
|
||||||
func averageScore(user *arn.User, animes []*arn.Anime) float64 {
|
func averageUserScore(user *arn.User, animes []*arn.Anime) float64 {
|
||||||
if user == nil {
|
if user == nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@ -71,3 +74,37 @@ func averageScore(user *arn.User, animes []*arn.Anime) float64 {
|
|||||||
|
|
||||||
return scores / count
|
return scores / count
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// averageGlobalScore returns the average overall score for the given anime
|
||||||
|
func averageGlobalScore(animes []*arn.Anime) float64 {
|
||||||
|
sum := 0.0
|
||||||
|
count := 0
|
||||||
|
|
||||||
|
for _, anime := range animes {
|
||||||
|
if anime.Rating.Count.Overall >= animeRatingThreshold {
|
||||||
|
sum += anime.Rating.Overall
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sum / float64(count)
|
||||||
|
}
|
||||||
|
|
||||||
|
// totalCompleted counts the number of animes the user has completed from a given list of anime
|
||||||
|
func totalCompleted(user *arn.User, animes []*arn.Anime) int {
|
||||||
|
if user == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
count := 0
|
||||||
|
|
||||||
|
completedList := user.AnimeList().FilterStatus(arn.AnimeListStatusCompleted)
|
||||||
|
|
||||||
|
for _, anime := range animes {
|
||||||
|
if completedList.Contains(anime.ID) {
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
component Genre(genre string, animes []*arn.Anime, user *arn.User, userScore float64)
|
component Genre(genre string, animes []*arn.Anime, user *arn.User, userScore float64, userCompleted int, globalScore float64)
|
||||||
h1(title=fmt.Sprint(len(animes)) + " anime")= strings.Title(genre)
|
h1(title=fmt.Sprint(len(animes)) + " anime")= strings.Title(genre)
|
||||||
|
|
||||||
//- if user != nil
|
GenreStatistics(user, userScore, userCompleted, globalScore)
|
||||||
//- h2= fmt.Sprintf("%.1f", userScore)
|
|
||||||
|
|
||||||
.corner-buttons-hide-on-mobile
|
.corner-buttons-hide-on-mobile
|
||||||
if user != nil
|
if user != nil
|
||||||
@ -12,4 +11,9 @@ component Genre(genre string, animes []*arn.Anime, user *arn.User, userScore flo
|
|||||||
a.button(href="/genres", title="View genres")
|
a.button(href="/genres", title="View genres")
|
||||||
RawIcon("clone")
|
RawIcon("clone")
|
||||||
|
|
||||||
AnimeGrid(animes, user)
|
AnimeGrid(animes, user)
|
||||||
|
|
||||||
|
component GenreStatistics(user *arn.User, userScore float64, userCompleted int, globalScore float64)
|
||||||
|
if user != nil
|
||||||
|
.average-score-total-completed
|
||||||
|
p= fmt.Sprintf("Average rating: %." + strconv.Itoa(user.Settings().Format.RatingsPrecision) + "f | Total completed: %d", userScore, userCompleted)
|
3
pages/genre/genre.scarlet
Normal file
3
pages/genre/genre.scarlet
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
.average-score-total-completed
|
||||||
|
text-align center
|
||||||
|
font-size 1.25em
|
Loading…
Reference in New Issue
Block a user