Improved explore page

This commit is contained in:
2017-11-07 17:46:39 +01:00
parent f5935ab12b
commit 3fb236de25
6 changed files with 108 additions and 37 deletions

View File

@ -9,20 +9,67 @@ import (
)
const (
currentlyAiringBonus = 5.0
popularityThreshold = 5
popularityPenalty = 8.0
watchingPopularityWeight = 0.3
plannedPopularityWeight = 0.2
currentlyAiringBonus = 5.0
popularityThreshold = 5
popularityPenalty = 8.0
watchingPopularityWeight = 0.3
completedPopularityWeight = 0.3
plannedPopularityWeight = 0.2
)
// Get ...
func Get(ctx *aero.Context) string {
animeList := arn.GetAiringAnime()
year := "2017"
status := "current"
typ := "tv"
results := filterAnime(year, status, typ)
return ctx.HTML(components.ExploreAnime(results, year, status, typ))
}
// Filter ...
func Filter(ctx *aero.Context) string {
year := ctx.Get("year")
status := ctx.Get("status")
typ := ctx.Get("type")
results := filterAnime(year, status, typ)
return ctx.HTML(components.ExploreAnime(results, year, status, typ))
}
func filterAnime(year, status, typ string) []*arn.Anime {
var results []*arn.Anime
for anime := range arn.StreamAnime() {
if len(anime.StartDate) < 4 {
continue
}
if anime.StartDate[:4] != year {
continue
}
if anime.Status != status {
continue
}
if anime.Type != typ {
continue
}
results = append(results, anime)
}
sortAnime(results)
return results
}
func sortAnime(animeList []*arn.Anime) {
sort.Slice(animeList, func(i, j int) bool {
a := animeList[i]
b := animeList[j]
scoreA := a.Rating.Overall
scoreB := b.Rating.Overall
@ -48,33 +95,9 @@ func Get(ctx *aero.Context) string {
scoreA += float64(a.Popularity.Planned) * plannedPopularityWeight
scoreB += float64(b.Popularity.Planned) * plannedPopularityWeight
scoreA += float64(a.Popularity.Completed) * completedPopularityWeight
scoreB += float64(b.Popularity.Completed) * completedPopularityWeight
return scoreA > scoreB
})
return ctx.HTML(components.Explore(animeList))
}
// Filter ...
func Filter(ctx *aero.Context) string {
year := ctx.Get("year")
status := ctx.Get("status")
var results []*arn.Anime
for anime := range arn.StreamAnime() {
if len(anime.StartDate) < 4 {
continue
}
if anime.StartDate[:4] != year {
continue
}
if anime.Status != status {
continue
}
}
return ctx.HTML(components.Explore(results))
}