Added anime grid for genres (up to 100 for now)
This commit is contained in:
parent
1c2cd2cee7
commit
91b6ae7efd
@ -66,7 +66,14 @@ func AnimeList(ctx *aero.Context) string {
|
||||
}
|
||||
|
||||
sort.Slice(comparisons, func(i, j int) bool {
|
||||
return comparisons[i].Anime.Popularity.Total() > comparisons[j].Anime.Popularity.Total()
|
||||
aPopularity := comparisons[i].Anime.Popularity.Total()
|
||||
bPopularity := comparisons[j].Anime.Popularity.Total()
|
||||
|
||||
if aPopularity == bPopularity {
|
||||
return comparisons[i].Anime.Title.Canonical < comparisons[j].Anime.Title.Canonical
|
||||
}
|
||||
|
||||
return aPopularity > bPopularity
|
||||
})
|
||||
|
||||
return ctx.HTML(components.CompareAnimeList(a, b, countA, countB, comparisons, user))
|
||||
|
@ -1,26 +1,12 @@
|
||||
package explore
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/animenotifier/notify.moe/components"
|
||||
"github.com/animenotifier/notify.moe/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
currentlyAiringBonus = 5.0
|
||||
popularityThreshold = 5
|
||||
popularityPenalty = 8.0
|
||||
watchingPopularityWeight = 0.3
|
||||
completedPopularityWeight = 0.3
|
||||
plannedPopularityWeight = 0.2
|
||||
agePenalty = 11.0
|
||||
ageThreshold = 6 * 30 * 24 * time.Hour
|
||||
)
|
||||
|
||||
// Get ...
|
||||
func Get(ctx *aero.Context) string {
|
||||
year := "2017"
|
||||
@ -67,54 +53,6 @@ func filterAnime(year, status, typ string) []*arn.Anime {
|
||||
results = append(results, anime)
|
||||
}
|
||||
|
||||
sortAnime(results, status)
|
||||
arn.SortAnimeByQuality(results, status)
|
||||
return results
|
||||
}
|
||||
|
||||
func sortAnime(animeList []*arn.Anime, filterStatus string) {
|
||||
sort.Slice(animeList, func(i, j int) bool {
|
||||
a := animeList[i]
|
||||
b := animeList[j]
|
||||
|
||||
scoreA := a.Rating.Overall
|
||||
scoreB := b.Rating.Overall
|
||||
|
||||
if a.Status == "current" {
|
||||
scoreA += currentlyAiringBonus
|
||||
}
|
||||
|
||||
if b.Status == "current" {
|
||||
scoreB += currentlyAiringBonus
|
||||
}
|
||||
|
||||
if a.Popularity.Total() < popularityThreshold {
|
||||
scoreA -= popularityPenalty
|
||||
}
|
||||
|
||||
if b.Popularity.Total() < popularityThreshold {
|
||||
scoreB -= popularityPenalty
|
||||
}
|
||||
|
||||
// If we show current shows, rank old shows a bit lower
|
||||
if filterStatus == "current" {
|
||||
if a.StartDate != "" && time.Since(a.StartDateTime()) > ageThreshold {
|
||||
scoreA -= agePenalty
|
||||
}
|
||||
|
||||
if b.StartDate != "" && time.Since(b.StartDateTime()) > ageThreshold {
|
||||
scoreB -= agePenalty
|
||||
}
|
||||
}
|
||||
|
||||
scoreA += float64(a.Popularity.Watching) * watchingPopularityWeight
|
||||
scoreB += float64(b.Popularity.Watching) * watchingPopularityWeight
|
||||
|
||||
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
|
||||
})
|
||||
}
|
||||
|
@ -1,21 +1,44 @@
|
||||
package genre
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/animenotifier/notify.moe/components"
|
||||
"github.com/animenotifier/notify.moe/utils"
|
||||
)
|
||||
|
||||
const animePerPage = 100
|
||||
|
||||
// Get ...
|
||||
func Get(ctx *aero.Context) string {
|
||||
user := utils.GetUser(ctx)
|
||||
genreName := ctx.Get("name")
|
||||
genre, err := arn.GetGenre(genreName)
|
||||
animes := []*arn.Anime{}
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(404, "Genre not found", err)
|
||||
for anime := range arn.StreamAnime() {
|
||||
if containsLowerCase(anime.Genres, genreName) {
|
||||
animes = append(animes, anime)
|
||||
}
|
||||
}
|
||||
|
||||
return ctx.HTML(components.Genre(genre, user))
|
||||
arn.SortAnimeByQuality(animes, "")
|
||||
|
||||
if len(animes) > animePerPage {
|
||||
animes = animes[:animePerPage]
|
||||
}
|
||||
|
||||
return ctx.HTML(components.Genre(genreName, animes, user))
|
||||
}
|
||||
|
||||
// containsLowerCase tells you whether the given element exists when all elements are lowercased.
|
||||
func containsLowerCase(array []string, search string) bool {
|
||||
for _, item := range array {
|
||||
if strings.ToLower(item) == search {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
component Genre(genre *arn.Genre, user *arn.User)
|
||||
h2(title=toString(len(genre.AnimeList)) + " anime")= arn.Capitalize(genre.ID)
|
||||
AnimeGrid(genre.AnimeList, user)
|
||||
component Genre(genre string, animes []*arn.Anime, user *arn.User)
|
||||
h1(title=toString(len(animes)) + " anime")= strings.Title(genre)
|
||||
AnimeGrid(animes, user)
|
@ -1,8 +1,6 @@
|
||||
package genres
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/animenotifier/notify.moe/components"
|
||||
@ -10,22 +8,15 @@ import (
|
||||
|
||||
// Get ...
|
||||
func Get(ctx *aero.Context) string {
|
||||
var genres []*arn.Genre
|
||||
var genres []string
|
||||
|
||||
for _, genreName := range arn.Genres {
|
||||
for _, genre := range arn.Genres {
|
||||
// Skip this genre because it doesn't get processed in the background jobs
|
||||
if genreName == "Hentai" {
|
||||
continue
|
||||
}
|
||||
|
||||
genre, err := arn.GetGenre(arn.GetGenreIDByName(genreName))
|
||||
|
||||
if err == nil {
|
||||
genre.Name = genreName
|
||||
genres = append(genres, genre)
|
||||
} else {
|
||||
fmt.Println(err)
|
||||
}
|
||||
genres = append(genres, genre)
|
||||
}
|
||||
|
||||
return ctx.HTML(components.Genres(genres))
|
||||
|
@ -1,4 +1,4 @@
|
||||
component Genres(genres []*arn.Genre)
|
||||
component Genres(genres []string)
|
||||
//- h1.page-title Genres
|
||||
|
||||
//- .genres
|
||||
|
@ -23,6 +23,7 @@ import (
|
||||
"github.com/animenotifier/notify.moe/pages/embed"
|
||||
"github.com/animenotifier/notify.moe/pages/explore"
|
||||
"github.com/animenotifier/notify.moe/pages/forum"
|
||||
"github.com/animenotifier/notify.moe/pages/genre"
|
||||
"github.com/animenotifier/notify.moe/pages/group"
|
||||
"github.com/animenotifier/notify.moe/pages/groups"
|
||||
"github.com/animenotifier/notify.moe/pages/home"
|
||||
@ -201,6 +202,6 @@ func Configure(app *aero.Application) {
|
||||
app.Post("/api/paypal/payment/create", paypal.CreatePayment)
|
||||
|
||||
// Genres
|
||||
// l.Ajax("/genres", genres.Get)
|
||||
// l.Ajax("/genres/:name", genre.Get)
|
||||
// l.Page("/genres", genres.Get)
|
||||
l.Page("/genre/:name", genre.Get)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user