From 750302b60eab6d1fced1820b6dc637a91a12a3d5 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sat, 1 Jul 2017 02:14:14 +0200 Subject: [PATCH] Improved exploration --- jobs/popular-anime/popular-anime.go | 54 ++++++++++++++++---------- main.go | 6 +-- mixins/Navigation.pixy | 4 +- pages/airing/airing.go | 21 ---------- pages/airing/airing.pixy | 3 -- pages/anime/anime.pixy | 5 ++- pages/animelistitem/animelistitem.pixy | 2 +- pages/best/best.go | 46 ++++++++++++++++++++++ pages/best/best.pixy | 15 +++++++ pages/explore/explore.go | 13 ++++--- pages/explore/explore.pixy | 12 ++---- 11 files changed, 114 insertions(+), 67 deletions(-) delete mode 100644 pages/airing/airing.go delete mode 100644 pages/airing/airing.pixy create mode 100644 pages/best/best.go create mode 100644 pages/best/best.pixy diff --git a/jobs/popular-anime/popular-anime.go b/jobs/popular-anime/popular-anime.go index 9a1a0143..10a5483a 100644 --- a/jobs/popular-anime/popular-anime.go +++ b/jobs/popular-anime/popular-anime.go @@ -14,37 +14,49 @@ const maxPopularAnime = 10 func main() { color.Yellow("Caching popular anime") + // Fetch all anime animeList, err := arn.AllAnime() + arn.PanicOnError(err) - if err != nil { - color.Red("Failed fetching anime channel") - color.Red(err.Error()) - return - } - + // Overall sort.Slice(animeList, func(i, j int) bool { return animeList[i].Rating.Overall > animeList[j].Rating.Overall }) - // Change size of anime list to 10 - animeList = animeList[:maxPopularAnime] + saveAs(animeList[:maxPopularAnime], "best anime overall") - // Convert to small anime list + // Story + sort.Slice(animeList, func(i, j int) bool { + return animeList[i].Rating.Story > animeList[j].Rating.Story + }) + + saveAs(animeList[:maxPopularAnime], "best anime story") + + // Visuals + sort.Slice(animeList, func(i, j int) bool { + return animeList[i].Rating.Visuals > animeList[j].Rating.Visuals + }) + + saveAs(animeList[:maxPopularAnime], "best anime visuals") + + // Soundtrack + sort.Slice(animeList, func(i, j int) bool { + return animeList[i].Rating.Soundtrack > animeList[j].Rating.Soundtrack + }) + + saveAs(animeList[:maxPopularAnime], "best anime soundtrack") + + // Done. + color.Green("Finished.") +} + +// Convert to ListOfIDs and save in cache. +func saveAs(list []*arn.Anime, cacheKey string) { cache := &arn.ListOfIDs{} - for _, anime := range animeList { + for _, anime := range list { cache.IDList = append(cache.IDList, anime.ID) } - println(len(cache.IDList)) - - saveErr := arn.DB.Set("Cache", "popular anime", cache) - - if saveErr != nil { - color.Red("Error saving popular anime") - color.Red(saveErr.Error()) - return - } - - color.Green("Finished.") + arn.PanicOnError(arn.DB.Set("Cache", cacheKey, cache)) } diff --git a/main.go b/main.go index 21e4e7d6..36de93c6 100644 --- a/main.go +++ b/main.go @@ -9,10 +9,10 @@ import ( "github.com/animenotifier/notify.moe/layout" "github.com/animenotifier/notify.moe/middleware" "github.com/animenotifier/notify.moe/pages/admin" - "github.com/animenotifier/notify.moe/pages/airing" "github.com/animenotifier/notify.moe/pages/anime" "github.com/animenotifier/notify.moe/pages/animelist" "github.com/animenotifier/notify.moe/pages/animelistitem" + "github.com/animenotifier/notify.moe/pages/best" "github.com/animenotifier/notify.moe/pages/dashboard" "github.com/animenotifier/notify.moe/pages/editanime" "github.com/animenotifier/notify.moe/pages/embed" @@ -57,9 +57,10 @@ func configure(app *aero.Application) *aero.Application { // Ajax routes app.Ajax("/", dashboard.Get) - app.Ajax("/anime", explore.Get) app.Ajax("/anime/:id", anime.Get) app.Ajax("/anime/:id/edit", editanime.Get) + app.Ajax("/best/anime", best.Get) + app.Ajax("/explore", explore.Get) app.Ajax("/forum", forums.Get) app.Ajax("/forum/:tag", forum.Get) app.Ajax("/threads/:id", threads.Get) @@ -81,7 +82,6 @@ func configure(app *aero.Application) *aero.Application { app.Ajax("/search/:term", search.Get) app.Ajax("/users", users.Get) app.Ajax("/login", login.Get) - app.Ajax("/airing", airing.Get) app.Ajax("/webdev", webdev.Get) app.Ajax("/extension/embed", embed.Get) // app.Ajax("/genres", genres.Get) diff --git a/mixins/Navigation.pixy b/mixins/Navigation.pixy index d57e9aa8..c70c4178 100644 --- a/mixins/Navigation.pixy +++ b/mixins/Navigation.pixy @@ -15,7 +15,7 @@ component LoggedOutMenu .extra-navigation NavigationButton("Users", "/users", "globe") - NavigationButton("Anime", "/anime", "th") + NavigationButton("Explore", "/explore", "th") NavigationButton("Login", "/login", "sign-in") component LoggedInMenu(user *arn.User) @@ -34,7 +34,7 @@ component LoggedInMenu(user *arn.User) NavigationButton("Users", "/users", "globe") .extra-navigation - NavigationButton("Anime", "/anime", "th") + NavigationButton("Explore", "/explore", "th") NavigationButton("Settings", "/settings", "cog") diff --git a/pages/airing/airing.go b/pages/airing/airing.go deleted file mode 100644 index 05f68638..00000000 --- a/pages/airing/airing.go +++ /dev/null @@ -1,21 +0,0 @@ -package airing - -import ( - "github.com/aerogo/aero" - "github.com/animenotifier/arn" - "github.com/animenotifier/notify.moe/components" -) - -// Get ... -func Get(ctx *aero.Context) string { - var cache arn.ListOfIDs - err := arn.DB.GetObject("Cache", "airing anime", &cache) - - airing, err := arn.GetAiringAnimeCached() - - if err != nil { - return ctx.Error(500, "Couldn't fetch airing anime", err) - } - - return ctx.HTML(components.Airing(airing)) -} diff --git a/pages/airing/airing.pixy b/pages/airing/airing.pixy deleted file mode 100644 index 81f5d4c6..00000000 --- a/pages/airing/airing.pixy +++ /dev/null @@ -1,3 +0,0 @@ -component Airing(animeList []*arn.Anime) - h2.page-title(title=toString(len(animeList)) + " anime") Airing - AnimeGrid(animeList) \ No newline at end of file diff --git a/pages/anime/anime.pixy b/pages/anime/anime.pixy index ee57a586..854807bd 100644 --- a/pages/anime/anime.pixy +++ b/pages/anime/anime.pixy @@ -38,7 +38,10 @@ component Anime(anime *arn.Anime, tracks []*arn.SoundTrack, user *arn.User, epis h3.anime-section-name Ratings .anime-rating-categories .anime-rating-category(title=toString(anime.Rating.Overall)) - .anime-rating-category-name Overall + if anime.Status == "upcoming" + .anime-rating-category-name Hype + else + .anime-rating-category-name Overall Rating(anime.Rating.Overall) .anime-rating-category(title=toString(anime.Rating.Story)) .anime-rating-category-name Story diff --git a/pages/animelistitem/animelistitem.pixy b/pages/animelistitem/animelistitem.pixy index b2739f27..d4b95315 100644 --- a/pages/animelistitem/animelistitem.pixy +++ b/pages/animelistitem/animelistitem.pixy @@ -14,7 +14,7 @@ component AnimeListItem(viewUser *arn.User, item *arn.AnimeListItem, anime *arn. option(value=arn.AnimeListStatusDropped) Dropped .anime-list-item-rating-edit - InputNumber("Rating.Overall", item.Rating.Overall, item.OverallRatingName(), "Overall rating on a scale of 0 to 10", "0", "10", "0.1") + InputNumber("Rating.Overall", item.Rating.Overall, arn.OverallRatingName(item.Episodes), "Overall rating on a scale of 0 to 10", "0", "10", "0.1") InputNumber("Rating.Story", item.Rating.Story, "Story", "Story rating on a scale of 0 to 10", "0", "10", "0.1") InputNumber("Rating.Visuals", item.Rating.Visuals, "Visuals", "Visuals rating on a scale of 0 to 10", "0", "10", "0.1") InputNumber("Rating.Soundtrack", item.Rating.Soundtrack, "Soundtrack", "Soundtrack rating on a scale of 0 to 10", "0", "10", "0.1") diff --git a/pages/best/best.go b/pages/best/best.go new file mode 100644 index 00000000..e5ce245d --- /dev/null +++ b/pages/best/best.go @@ -0,0 +1,46 @@ +package best + +import ( + "net/http" + + "github.com/aerogo/aero" + "github.com/animenotifier/arn" + "github.com/animenotifier/notify.moe/components" +) + +const maxEntries = 7 + +// Get search page. +func Get(ctx *aero.Context) string { + overall, err := arn.GetListOfAnimeCached("best anime overall") + + if err != nil { + return ctx.Error(http.StatusInternalServerError, "Error fetching popular anime", err) + } + + story, err := arn.GetListOfAnimeCached("best anime story") + + if err != nil { + return ctx.Error(http.StatusInternalServerError, "Error fetching popular anime", err) + } + + visuals, err := arn.GetListOfAnimeCached("best anime visuals") + + if err != nil { + return ctx.Error(http.StatusInternalServerError, "Error fetching popular anime", err) + } + + soundtrack, err := arn.GetListOfAnimeCached("best anime soundtrack") + + if err != nil { + return ctx.Error(http.StatusInternalServerError, "Error fetching popular anime", err) + } + + airing, err := arn.GetAiringAnimeCached() + + if err != nil { + return ctx.Error(500, "Couldn't fetch airing anime", err) + } + + return ctx.HTML(components.BestAnime(overall[:maxEntries], story[:maxEntries], visuals[:maxEntries], soundtrack[:maxEntries], airing[:maxEntries])) +} diff --git a/pages/best/best.pixy b/pages/best/best.pixy new file mode 100644 index 00000000..3455ed32 --- /dev/null +++ b/pages/best/best.pixy @@ -0,0 +1,15 @@ +component BestAnime(overall []*arn.Anime, story []*arn.Anime, visuals []*arn.Anime, soundtrack []*arn.Anime, airing []*arn.Anime) + h2 Currently Airing + AnimeGrid(airing) + + h2 Best Overall + AnimeGrid(overall) + + h2 Best Story + AnimeGrid(story) + + h2 Best Visuals + AnimeGrid(visuals) + + h2 Best Soundtrack + AnimeGrid(soundtrack) \ No newline at end of file diff --git a/pages/explore/explore.go b/pages/explore/explore.go index 18896117..529bbb15 100644 --- a/pages/explore/explore.go +++ b/pages/explore/explore.go @@ -1,20 +1,21 @@ package explore import ( - "net/http" - "github.com/aerogo/aero" "github.com/animenotifier/arn" "github.com/animenotifier/notify.moe/components" ) -// Get search page. +// Get ... func Get(ctx *aero.Context) string { - animeList, err := arn.GetPopularAnimeCached() + var cache arn.ListOfIDs + err := arn.DB.GetObject("Cache", "airing anime", &cache) + + airing, err := arn.GetAiringAnimeCached() if err != nil { - return ctx.Error(http.StatusInternalServerError, "Error fetching popular anime", err) + return ctx.Error(500, "Couldn't fetch airing anime", err) } - return ctx.HTML(components.ExploreAnime(nil, nil, animeList)) + return ctx.HTML(components.Airing(airing)) } diff --git a/pages/explore/explore.pixy b/pages/explore/explore.pixy index 744423f0..202a7817 100644 --- a/pages/explore/explore.pixy +++ b/pages/explore/explore.pixy @@ -1,9 +1,3 @@ -component ExploreAnime(overall []*arn.Anime, story []*arn.Anime, airing []*arn.Anime) - h2 Highest Rating - AnimeGrid(overall) - - h2 Best Story - AnimeGrid(story) - - h2 Currently Airing - AnimeGrid(airing) \ No newline at end of file +component Airing(animeList []*arn.Anime) + h2.page-title(title=toString(len(animeList)) + " anime") Explore + AnimeGrid(animeList) \ No newline at end of file