Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Different algo animelist #186

Open
wants to merge 4 commits into
base: go
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pages/animelist/animelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func FilterByStatus(status string) aero.Handle {
func AnimeList(ctx *aero.Context, user *arn.User, status string) string {
nick := ctx.Get("nick")
index, _ := ctx.GetInt("index")
sort := ctx.Query("sort")
viewUser, err := arn.GetUserByNick(nick)

if err != nil {
Expand All @@ -49,7 +50,7 @@ func AnimeList(ctx *aero.Context, user *arn.User, status string) string {
}

// Sort the items
statusList.Sort()
statusList.SortByAlgo(sort, user)

// These are all animer list items for the given status
allItems := statusList.Items
Expand Down
2 changes: 1 addition & 1 deletion pages/editor/editor.pixy
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,5 @@ component EditorTabs(url string, user *arn.User)
if strings.Contains(url, "/editor/anime/") || strings.Contains(url, "/editor/mal/diff/anime")
.editor-filters
#filter-root(data-url=url)
ExploreFilters(user.Settings().Editor.Filter.Year, user.Settings().Editor.Filter.Season, user.Settings().Editor.Filter.Status, user.Settings().Editor.Filter.Type, true)
ExploreFilters(user.Settings().Editor.Filter.Year, user.Settings().Editor.Filter.Season, user.Settings().Editor.Filter.Status, user.Settings().Editor.Filter.Type, user.Settings().Editor.Filter.Sort, true)

10 changes: 8 additions & 2 deletions pages/editor/filteranime/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func editorList(ctx *aero.Context, title string, filter func(*arn.Anime) bool, s
// Determine URL
url := strings.TrimPrefix(ctx.URI(), "/_")
urlParts := strings.Split(url, "/")
urlParts = urlParts[:len(urlParts)-4]
urlParts = urlParts[:len(urlParts)-5]
url = strings.Join(urlParts, "/")

return ctx.HTML(components.AnimeEditorListFull(
Expand All @@ -45,6 +45,7 @@ func filterAnime(ctx *aero.Context, user *arn.User, filter func(*arn.Anime) bool
status := ctx.Get("status")
season := ctx.Get("season")
typ := ctx.Get("type")
sort := ctx.Get("sort")

if year == "any" {
year = ""
Expand All @@ -62,11 +63,16 @@ func filterAnime(ctx *aero.Context, user *arn.User, filter func(*arn.Anime) bool
typ = ""
}

if sort == "Popularity" {
sort = ""
}

settings := user.Settings()
settings.Editor.Filter.Year = year
settings.Editor.Filter.Season = season
settings.Editor.Filter.Status = status
settings.Editor.Filter.Type = typ
settings.Editor.Filter.Sort = sort
settings.Save()

// Filter
Expand All @@ -91,7 +97,7 @@ func filterAnime(ctx *aero.Context, user *arn.User, filter func(*arn.Anime) bool
})

// Sort
arn.SortAnimeByQuality(animes)
arn.SortAnimeWithAlgo(animes, status, sort, user)

// Limit
count := len(animes)
Expand Down
22 changes: 7 additions & 15 deletions pages/editor/mal.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package editor

import (
"sort"

"github.com/animenotifier/notify.moe/utils/animediff"

"github.com/aerogo/aero"
Expand All @@ -24,6 +22,7 @@ func CompareMAL(ctx *aero.Context) string {
status := ctx.Get("status")
season := ctx.Get("season")
typ := ctx.Get("type")
sort := ctx.Get("sort")

if year == "any" {
year = ""
Expand All @@ -41,11 +40,16 @@ func CompareMAL(ctx *aero.Context) string {
typ = ""
}

if sort == "Popularity" {
sort = ""
}

settings := user.Settings()
settings.Editor.Filter.Year = year
settings.Editor.Filter.Season = season
settings.Editor.Filter.Status = status
settings.Editor.Filter.Type = typ
settings.Editor.Filter.Sort = sort
settings.Save()

animes := arn.FilterAnime(func(anime *arn.Anime) bool {
Expand All @@ -68,19 +72,7 @@ func CompareMAL(ctx *aero.Context) string {
return anime.GetMapping("myanimelist/anime") != ""
})

sort.Slice(animes, func(i, j int) bool {
a := animes[i]
b := animes[j]

aPop := a.Popularity.Total()
bPop := b.Popularity.Total()

if aPop == bPop {
return a.Title.Canonical < b.Title.Canonical
}

return aPop > bPop
})
arn.SortAnimeWithAlgo(animes, status, sort, user)

comparisons := compare(animes)

Expand Down
13 changes: 9 additions & 4 deletions pages/explore/explore.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func Filter(ctx *aero.Context) string {
season := ctx.Get("season")
status := ctx.Get("status")
typ := ctx.Get("type")
sort := ctx.Get("sort")
user := utils.GetUser(ctx)
now := time.Now()

Expand All @@ -35,7 +36,7 @@ func Filter(ctx *aero.Context) string {
typ = "tv"
}

results := filterAnime(year, season, status, typ)
results := filterAnime(year, season, status, typ, sort, user)

if year == "any" {
year = ""
Expand All @@ -53,10 +54,14 @@ func Filter(ctx *aero.Context) string {
typ = ""
}

return ctx.HTML(components.ExploreAnime(results, year, season, status, typ, user))
if sort == "Popularity" {
sort = ""
}

return ctx.HTML(components.ExploreAnime(results, year, season, status, typ, sort, user))
}

func filterAnime(year, season, status, typ string) []*arn.Anime {
func filterAnime(year, season, status, typ string, sortAlgo string, user *arn.User) []*arn.Anime {
var results []*arn.Anime

for anime := range arn.StreamAnime() {
Expand Down Expand Up @@ -85,6 +90,6 @@ func filterAnime(year, season, status, typ string) []*arn.Anime {
results = append(results, anime)
}

arn.SortAnimeByQualityDetailed(results, status)
arn.SortAnimeWithAlgo(results, status, sortAlgo, user)
return results
}
18 changes: 14 additions & 4 deletions pages/explore/explore.pixy
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
component ExploreAnime(animes []*arn.Anime, year string, season string, status string, typ string, user *arn.User)
component ExploreAnime(animes []*arn.Anime, year string, season string, status string, typ string, sort string, user *arn.User)
#filter-root(data-url="/explore/anime")
ExploreFilters(year, season, status, typ, false)
ExploreFilters(year, season, status, typ, sort, false)

.corner-buttons-hide-on-mobile
if user != nil
Expand Down Expand Up @@ -30,7 +30,7 @@ component ExploreAnime(animes []*arn.Anime, year string, season string, status s
else
AnimeGrid(animes, user)

component ExploreFilters(year string, season string, status string, typ string, advancedFilters bool)
component ExploreFilters(year string, season string, status string, typ string, sort string, advancedFilters bool)
.explore-filters
.filter-select-container
select#filter-year.filter-select.action(value=year, data-action="filterAnime", data-trigger="change")
Expand Down Expand Up @@ -76,4 +76,14 @@ component ExploreFilters(year string, season string, status string, typ string,
if advancedFilters
option(value="music") Music

.filter-label Type
.filter-label Type

.filter-select-container
select#sort.filter-select.action(value=sort, data-action="filterAnime", data-trigger="change")
option.option-any(value="") Popularity
option(value="Title") Title
option(value="StartDate") Start date
option(value="EpisodeCount") Episode count
option(value="EpisodeLength") Episode length

.filter-label Order By
2 changes: 1 addition & 1 deletion pages/index/exploreroutes/exploreroutes.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func Register(l *layout.Layout) {
// Explore
l.Page("/explore", explore.Filter)
l.Page("/explore/anime/:year/:season/:status/:type", explore.Filter)
l.Page("/explore/anime/:year/:season/:status/:type/:sort", explore.Filter)
l.Page("/explore/color/:color/anime", explorecolor.AnimeByAverageColor)
l.Page("/explore/color/:color/anime/from/:index", explorecolor.AnimeByAverageColor)
l.Page("/halloffame", halloffame.Get)
Expand Down
2 changes: 1 addition & 1 deletion pages/index/staffroutes/staffroutes.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func Register(l *layout.Layout) {

// Editor links can be filtered by year, status and type
editorFilterable := func(route string, handler func(ctx *aero.Context) string) {
l.Page(route+"/:year/:season/:status/:type", handler)
l.Page(route+"/:year/:season/:status/:type/:sort", handler)
}

// Editor - Anime
Expand Down
4 changes: 3 additions & 1 deletion scripts/Actions/Explore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export function filterAnime(arn: AnimeNotifier, input: HTMLInputElement) {
let elementSeason = document.getElementById("filter-season") as HTMLSelectElement
let elementStatus = document.getElementById("filter-status") as HTMLSelectElement
let elementType = document.getElementById("filter-type") as HTMLSelectElement
let elementSort = document.getElementById("sort") as HTMLSelectElement

for(let element of findAll("anime-grid-image")) {
let img = element as HTMLImageElement
Expand All @@ -21,8 +22,9 @@ export function filterAnime(arn: AnimeNotifier, input: HTMLInputElement) {
let season = elementSeason.value || "any"
let status = elementStatus.value || "any"
let type = elementType.value || "any"
let sort = elementSort.value || "Popularity"

arn.diff(`${root.dataset.url}/${year}/${season}/${status}/${type}`)
arn.diff(`${root.dataset.url}/${year}/${season}/${status}/${type}/${sort}`)
}

// Toggle hiding added anime.
Expand Down
4 changes: 2 additions & 2 deletions utils/routetests/All.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ var routeTests = map[string][]string{
"/compare/animelist/Akyoto/Scott",
},

"/explore/anime/:year/:season/:status/:type": []string{
"/explore/anime/2011/any/finished/tv",
"/explore/anime/:year/:season/:status/:type/:sort": []string{
"/explore/anime/2011/any/finished/tv/Popularity",
},

// AMV
Expand Down