diff --git a/pages/compare/animelist.go b/pages/compare/animelist.go index 784c661d..a0b2a4a7 100644 --- a/pages/compare/animelist.go +++ b/pages/compare/animelist.go @@ -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)) diff --git a/pages/explore/explore.go b/pages/explore/explore.go index c9b4710b..73277098 100644 --- a/pages/explore/explore.go +++ b/pages/explore/explore.go @@ -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 - }) -} diff --git a/pages/genre/genre.go b/pages/genre/genre.go index 5824f62d..f5350c75 100644 --- a/pages/genre/genre.go +++ b/pages/genre/genre.go @@ -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 } diff --git a/pages/genre/genre.pixy b/pages/genre/genre.pixy index 52647340..038a1eee 100644 --- a/pages/genre/genre.pixy +++ b/pages/genre/genre.pixy @@ -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) \ No newline at end of file +component Genre(genre string, animes []*arn.Anime, user *arn.User) + h1(title=toString(len(animes)) + " anime")= strings.Title(genre) + AnimeGrid(animes, user) \ No newline at end of file diff --git a/pages/genres/genres.go b/pages/genres/genres.go index c4077dc4..09890229 100644 --- a/pages/genres/genres.go +++ b/pages/genres/genres.go @@ -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)) diff --git a/pages/genres/genres.pixy b/pages/genres/genres.pixy index 06218201..0c789b42 100644 --- a/pages/genres/genres.pixy +++ b/pages/genres/genres.pixy @@ -1,4 +1,4 @@ -component Genres(genres []*arn.Genre) +component Genres(genres []string) //- h1.page-title Genres //- .genres diff --git a/pages/index.go b/pages/index.go index f61ec5b4..b5eef65b 100644 --- a/pages/index.go +++ b/pages/index.go @@ -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) }