mirror of
https://github.com/got-feedBack/feedBack.git
synced 2026-09-11 02:44:30 +00:00
fix(career): a gig's song pool is the whole genre, and re-roll varies it
Two tester reports, one root: the gig song pool was built from only two sets — songs played ON THIS PASSPORT'S INSTRUMENT, and songs never played AT ALL (`filename NOT IN song_stats`). A song played on a DIFFERENT instrument's arrangement is in neither: it has a stats row (so the "unplayed" filler skipped it), and its played bucket is that other instrument's, not this passport's. It could never be gigged. - "Metalcore says 137 songs only shows 1 in the gig list" — a library of metalcore all played on another instrument. Reproduced: a guitar passport with 137 bass-played metalcore songs got a 404, zero songs. The "1" the tester saw was whatever handful happened to be on-instrument or truly unplayed. - "Passport re-roll does not change songs" — a set drawn from that filler was the library's first N in table ORDER, every call. Re-roll re-proposes, so it returned the identical set. Reproduced: 3 proposals, byte-identical. _unplayed_genre_songs -> _fill_genre_songs: the pool is now every library song of the genre the set hasn't already picked (a stats row on some other instrument has no bearing on whether a song can be in THIS gig), and it is shuffled so re-roll actually re-rolls. Both reproduced against the real propose logic before the fix and pinned as regression tests (both fail on the pre-fix routes.py). Full career suite green.
This commit is contained in:
+29
-17
@@ -522,27 +522,39 @@ def _current_venue():
|
|||||||
return best
|
return best
|
||||||
|
|
||||||
|
|
||||||
def _unplayed_genre_songs(gkey, exclude, limit):
|
def _fill_genre_songs(gkey, exclude, limit):
|
||||||
"""Library songs of a genre with no stats yet — a young passport's gig
|
"""Library songs of a genre to round out a gig — ANY song of the genre the
|
||||||
still gets a full set (playing them is how stubs start).
|
set hasn't already picked.
|
||||||
ponytail: full stat-less scan + python-side genre match (a few ms at 7k
|
|
||||||
songs, single-user); push the match into SQL if propose ever feels slow."""
|
Was `_unplayed_genre_songs`, restricted to `filename NOT IN song_stats`.
|
||||||
|
That restriction created a hole: a song you'd played on a DIFFERENT
|
||||||
|
instrument's arrangement has a stats row, so it was excluded here — and it
|
||||||
|
lives in the played bucket for THAT instrument, not this passport's, so it
|
||||||
|
was excluded there too. It could never be gigged. A player with 137 metalcore
|
||||||
|
songs, all played on another instrument, got a 404 (reproduced). The player's
|
||||||
|
library is the pool; whether a song has stats on some other instrument has no
|
||||||
|
bearing on whether it can be in THIS gig.
|
||||||
|
|
||||||
|
Shuffled, so re-roll actually changes the set. The old version returned the
|
||||||
|
library's first N in table order every time, so re-roll was a no-op for any
|
||||||
|
set drawn from the filler (reproduced).
|
||||||
|
|
||||||
|
ponytail: full genre scan + python-side match + shuffle (a few ms at 7k
|
||||||
|
songs, single-user); push into SQL if propose ever feels slow.
|
||||||
|
"""
|
||||||
db = _state["meta_db"]
|
db = _state["meta_db"]
|
||||||
if db is None:
|
if db is None:
|
||||||
return []
|
return []
|
||||||
rows = db.conn.execute(
|
rows = db.conn.execute(
|
||||||
f"SELECT filename, title, artist, {_genre_expr(db)} AS g FROM songs "
|
f"SELECT filename, title, artist, {_genre_expr(db)} AS g FROM songs"
|
||||||
"WHERE filename NOT IN (SELECT filename FROM song_stats)"
|
|
||||||
).fetchall()
|
).fetchall()
|
||||||
out = []
|
pool = [
|
||||||
for filename, title, artist, genre in rows:
|
{"filename": filename, "title": title or filename, "artist": artist or ""}
|
||||||
if _genre_key(genre) != gkey or filename in exclude:
|
for filename, title, artist, genre in rows
|
||||||
continue
|
if _genre_key(genre) == gkey and filename not in exclude
|
||||||
out.append({"filename": filename, "title": title or filename,
|
]
|
||||||
"artist": artist or ""})
|
random.shuffle(pool) # re-roll must vary; free per call
|
||||||
if len(out) >= limit:
|
return pool[:limit]
|
||||||
break
|
|
||||||
return out
|
|
||||||
|
|
||||||
|
|
||||||
def _validate_pack_dir(pack_dir: Path):
|
def _validate_pack_dir(pack_dir: Path):
|
||||||
@@ -836,7 +848,7 @@ def setup(app, context):
|
|||||||
picks.append(s)
|
picks.append(s)
|
||||||
if len(picks) < size:
|
if len(picks) < size:
|
||||||
exclude = {s["filename"] for s in picks}
|
exclude = {s["filename"] for s in picks}
|
||||||
picks.extend(_unplayed_genre_songs(gkey, exclude, size - len(picks)))
|
picks.extend(_fill_genre_songs(gkey, exclude, size - len(picks)))
|
||||||
if not picks:
|
if not picks:
|
||||||
raise HTTPException(404, "No songs of this genre in the library.")
|
raise HTTPException(404, "No songs of this genre in the library.")
|
||||||
venue = _current_venue()
|
venue = _current_venue()
|
||||||
|
|||||||
@@ -445,3 +445,30 @@ def test_gold_intake_rejects_junk(client, meta_db):
|
|||||||
res = client.post("/api/plugins/career/drill-state",
|
res = client.post("/api/plugins/career/drill-state",
|
||||||
json={"byNode": {}, "goldImprov": blob})
|
json={"byNode": {}, "goldImprov": blob})
|
||||||
assert res.status_code == 413
|
assert res.status_code == 413
|
||||||
|
|
||||||
|
|
||||||
|
def test_gig_includes_songs_played_on_another_instrument(client, meta_db):
|
||||||
|
# feedBack#… (tester): "Metalcore says 137 songs, only shows 1 in the gig list".
|
||||||
|
# A song played on a DIFFERENT instrument's arrangement has a stats row, so it
|
||||||
|
# was excluded from the unplayed filler — and its played bucket is that other
|
||||||
|
# instrument's, not this passport's — so it fell into a gap and could never be
|
||||||
|
# gigged. A guitar passport with a library of bass-played metalcore got a 404.
|
||||||
|
for i in range(137):
|
||||||
|
meta_db.add(f"mc{i}.feedpak", 0, 0.80, genre="Metalcore", arrangements=BASS)
|
||||||
|
res = client.post("/api/plugins/career/gigs/propose",
|
||||||
|
json={"instrument": "guitar", "genre": "Metalcore", "size": 4})
|
||||||
|
assert res.status_code == 200, "a full library of the genre must never 404"
|
||||||
|
assert len(res.json()["songs"]) == 4, "the gig must fill from the library, not the gap"
|
||||||
|
|
||||||
|
|
||||||
|
def test_gig_reroll_changes_the_set(client, meta_db):
|
||||||
|
# feedBack#… (tester): "Passport re-roll does not change songs". A set drawn
|
||||||
|
# from the filler used to be the library's first N in table order, every time.
|
||||||
|
for i in range(40):
|
||||||
|
meta_db.add_song_only(f"un{i}.feedpak", genre="Metalcore")
|
||||||
|
sets = set()
|
||||||
|
for _ in range(5):
|
||||||
|
r = client.post("/api/plugins/career/gigs/propose",
|
||||||
|
json={"instrument": "guitar", "genre": "Metalcore", "size": 4})
|
||||||
|
sets.add(tuple(sorted(s["filename"] for s in r.json()["songs"])))
|
||||||
|
assert len(sets) > 1, "re-roll must be able to produce a different set"
|
||||||
|
|||||||
Reference in New Issue
Block a user