diff --git a/server.py b/server.py index cbb9f25..347d9e4 100644 --- a/server.py +++ b/server.py @@ -2153,6 +2153,20 @@ class MetadataDB: # '2005' rather than alphabetic. "year": "(year = '') ASC, CAST(year AS INTEGER) ASC", "year-desc": "(year = '') ASC, CAST(year AS INTEGER) DESC", + # Mastery = best accuracy across a song's arrangements, from the + # separate song_stats table (so via a correlated subquery — this sort + # drops to OFFSET paging, like tuning/year). Unscored ("not started") + # songs push to the BOTTOM in both directions (the IS NULL term); + # ascending is "needs practice first" (weakest measured first), + # descending is "most mastered first". + "mastery": ( + "((SELECT MAX(best_accuracy) FROM song_stats s WHERE s.filename = songs.filename) IS NULL) ASC, " + "(SELECT MAX(best_accuracy) FROM song_stats s WHERE s.filename = songs.filename) ASC" + ), + "mastery-desc": ( + "((SELECT MAX(best_accuracy) FROM song_stats s WHERE s.filename = songs.filename) IS NULL) ASC, " + "(SELECT MAX(best_accuracy) FROM song_stats s WHERE s.filename = songs.filename) DESC" + ), } order = sort_map.get(sort, "artist COLLATE NOCASE") # Legacy `dir=desc` toggle: only safe to append on simple sort diff --git a/static/v3/songs.js b/static/v3/songs.js index 5b64135..8e7b182 100644 --- a/static/v3/songs.js +++ b/static/v3/songs.js @@ -35,6 +35,9 @@ ['title', 'Title A–Z'], ['title-desc', 'Title Z–A'], ['recent', 'Recently Added'], ['year-desc', 'Year (newest)'], ['year', 'Year (oldest)'], ['tuning', 'Tuning'], + // Mastery = best accuracy across arrangements (song_stats); unscored songs + // sort last either way. Ascending surfaces what needs work; never default. + ['mastery', 'Needs practice first'], ['mastery-desc', 'Most mastered first'], ]; const FORMATS = [['', 'All formats'], ['sloppak', 'Feedpak'], ['loose', 'Folder']]; const ARRANGEMENTS = ['Lead', 'Rhythm', 'Bass', 'Combo', 'Vocals'];