Artiste : heure de passage ; vœux d'artistes pris en compte par le solveur
Artist gagne start_time/end_time (end <= start ⇒ finit le lendemain, même convention que Shift/DayPart/Availability). Migration 0008. Le solveur (app/solver/) résout maintenant les fenêtres de passage des artistes que chaque bénévole veut voir (VolunteerArtist) et pénalise toute suggestion qui chevaucherait un passage souhaité — le bénévole raterait l'artiste. Comme le reste du scoring, c'est un terme de l'objectif, pas un blocage : pour un créneau urgent sans autre candidat, le solveur propose quand même, quitte à ce que ce soit un pis-aller. - SolverVolunteer.wished_artist_windows (fenêtres ShiftInfo précalculées par le loader depuis Artist + VolunteerArtist). - Nouveau malus _ARTIST_CONFLICT_PENALTY dans engine.py. - Tests : moteur (conflit détecté/ignoré hors chevauchement/toujours suggéré en dernier recours) + intégration API bout en bout. 176 tests, ruff et alembic check au vert. CLAUDE.md mis à jour (§2 et §4). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017uUsRg7XzopkCPWimwg9ZM
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
e47c29d35b
commit
fea9d37019
@@ -21,10 +21,20 @@ def make_position(session, edition, *, name="Bar", category=PositionCategory.BAR
|
||||
|
||||
|
||||
def make_artist(
|
||||
session, edition, *, name="Chilla", performance_date=dt.date(2026, 7, 10)
|
||||
session,
|
||||
edition,
|
||||
*,
|
||||
name="Chilla",
|
||||
performance_date=dt.date(2026, 7, 10),
|
||||
start_time=dt.time(20, 0),
|
||||
end_time=dt.time(21, 0),
|
||||
):
|
||||
artist = Artist(
|
||||
edition_id=edition.id, name=name, performance_date=performance_date
|
||||
edition_id=edition.id,
|
||||
name=name,
|
||||
performance_date=performance_date,
|
||||
start_time=start_time,
|
||||
end_time=end_time,
|
||||
)
|
||||
session.add(artist)
|
||||
session.commit()
|
||||
|
||||
@@ -11,17 +11,24 @@ def _url(edition, suffix=""):
|
||||
return f"/editions/{edition.id}/artists{suffix}"
|
||||
|
||||
|
||||
def _payload(name: str, performance_date: str, **overrides) -> dict:
|
||||
body = {
|
||||
"name": name,
|
||||
"performance_date": performance_date,
|
||||
"start_time": "20:00",
|
||||
"end_time": "21:00",
|
||||
}
|
||||
body.update(overrides)
|
||||
return body
|
||||
|
||||
|
||||
def test_create_and_list_ordered_by_date_then_name(client, edition):
|
||||
client.post(
|
||||
_url(edition), json={"name": "Ziak", "performance_date": "2026-07-11"}
|
||||
)
|
||||
client.post(
|
||||
_url(edition), json={"name": "Aloïse Sauvage", "performance_date": "2026-07-11"}
|
||||
)
|
||||
r = client.post(
|
||||
_url(edition), json={"name": "Chilla", "performance_date": "2026-07-10"}
|
||||
)
|
||||
client.post(_url(edition), json=_payload("Ziak", "2026-07-11"))
|
||||
client.post(_url(edition), json=_payload("Aloïse Sauvage", "2026-07-11"))
|
||||
r = client.post(_url(edition), json=_payload("Chilla", "2026-07-10"))
|
||||
assert r.status_code == 201
|
||||
assert r.json()["start_time"] == "20:00:00"
|
||||
assert r.json()["end_time"] == "21:00:00"
|
||||
|
||||
body = client.get(_url(edition)).json()
|
||||
assert [(a["name"], a["performance_date"]) for a in body] == [
|
||||
@@ -32,24 +39,20 @@ def test_create_and_list_ordered_by_date_then_name(client, edition):
|
||||
|
||||
|
||||
def test_blank_name_is_422(client, edition):
|
||||
r = client.post(
|
||||
_url(edition), json={"name": " ", "performance_date": "2026-07-10"}
|
||||
)
|
||||
r = client.post(_url(edition), json=_payload(" ", "2026-07-10"))
|
||||
assert r.status_code == 422
|
||||
assert r.json()["detail"]["code"] == "artist.name_required"
|
||||
|
||||
|
||||
def test_duplicate_name_and_date_conflicts(client, edition):
|
||||
payload = {"name": "Chilla", "performance_date": "2026-07-10"}
|
||||
payload = _payload("Chilla", "2026-07-10")
|
||||
assert client.post(_url(edition), json=payload).status_code == 201
|
||||
r = client.post(_url(edition), json=payload)
|
||||
assert r.status_code == 409
|
||||
assert r.json()["detail"]["code"] == "artist.duplicate"
|
||||
|
||||
# Même nom, autre jour : autorisé.
|
||||
r2 = client.post(
|
||||
_url(edition), json={"name": "Chilla", "performance_date": "2026-07-11"}
|
||||
)
|
||||
r2 = client.post(_url(edition), json=_payload("Chilla", "2026-07-11"))
|
||||
assert r2.status_code == 201
|
||||
|
||||
|
||||
@@ -57,11 +60,14 @@ def test_update_artist(client, edition, session):
|
||||
artist = make_artist(session, edition, name="Chila")
|
||||
r = client.patch(
|
||||
_url(edition, f"/{artist.id}"),
|
||||
json={"name": "Chilla", "performance_date": "2026-07-12"},
|
||||
json={"name": "Chilla", "performance_date": "2026-07-12", "start_time": "22:00"},
|
||||
)
|
||||
assert r.status_code == 200
|
||||
assert r.json()["name"] == "Chilla"
|
||||
assert r.json()["performance_date"] == "2026-07-12"
|
||||
assert r.json()["start_time"] == "22:00:00"
|
||||
# Non transmis : inchangé.
|
||||
assert r.json()["end_time"] == "21:00:00"
|
||||
|
||||
|
||||
def test_delete_artist_removes_volunteer_wishes(client, edition, session):
|
||||
@@ -88,9 +94,7 @@ def test_unknown_edition_is_404(client):
|
||||
def test_write_is_coordinator_only(edition, make_account, as_account):
|
||||
lead = make_account(Role.LEAD, email="lead@e.fr")
|
||||
api = as_account(lead)
|
||||
resp = api.post(
|
||||
_url(edition), json={"name": "X", "performance_date": "2026-07-10"}
|
||||
)
|
||||
resp = api.post(_url(edition), json=_payload("X", "2026-07-10"))
|
||||
assert resp.status_code == 403
|
||||
# La lecture reste ouverte à tout compte de l'édition.
|
||||
assert api.get(_url(edition)).status_code == 200
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import datetime as dt
|
||||
import uuid
|
||||
|
||||
from app.models import Role
|
||||
from tests.factories import dt_at, make_position, make_shift, make_volunteer
|
||||
from tests.factories import dt_at, make_artist, make_position, make_shift, make_volunteer
|
||||
|
||||
|
||||
def _url(edition, suffix=""):
|
||||
@@ -45,6 +46,31 @@ def test_fully_staffed_shift_has_no_suggestion(client, edition, session):
|
||||
assert str(shift.id) not in shift_ids
|
||||
|
||||
|
||||
def test_avoids_volunteer_whose_wished_artist_would_be_missed(client, edition, session):
|
||||
position = make_position(session, edition)
|
||||
shift = make_shift(
|
||||
session, edition, position,
|
||||
start=dt_at(10, 14), end=dt_at(10, 18), min_staff=1, ideal_staff=1,
|
||||
)
|
||||
artist = make_artist(
|
||||
session, edition,
|
||||
performance_date=dt.date(2026, 7, 10),
|
||||
start_time=dt.time(15, 0), end_time=dt.time(16, 0),
|
||||
)
|
||||
fan = make_volunteer(session, edition, email="fan@ex.fr")
|
||||
assert client.patch(
|
||||
f"/editions/{edition.id}/volunteers/{fan.id}",
|
||||
json={"artist_ids": [str(artist.id)]},
|
||||
).status_code == 200
|
||||
indiff = make_volunteer(session, edition, email="indiff@ex.fr")
|
||||
|
||||
resp = client.post(_url(edition, "/suggestions"))
|
||||
suggestion = next(
|
||||
s for s in resp.json()["suggestions"] if s["shift_id"] == str(shift.id)
|
||||
)
|
||||
assert suggestion["volunteer_ids"] == [str(indiff.id)]
|
||||
|
||||
|
||||
def test_unknown_edition_is_404(client):
|
||||
assert client.post(f"/editions/{uuid.uuid4()}/solver/suggestions").status_code == 404
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ def _volunteer(
|
||||
*,
|
||||
availability=(),
|
||||
wished_position_ids=frozenset(),
|
||||
wished_artist_windows=(),
|
||||
existing_shifts=(),
|
||||
existing_minutes=0,
|
||||
) -> SolverVolunteer:
|
||||
@@ -44,6 +45,7 @@ def _volunteer(
|
||||
id=vid,
|
||||
availability=tuple(availability),
|
||||
wished_position_ids=frozenset(wished_position_ids),
|
||||
wished_artist_windows=tuple(wished_artist_windows),
|
||||
existing_shifts=tuple(existing_shifts),
|
||||
existing_minutes=existing_minutes,
|
||||
)
|
||||
@@ -146,3 +148,41 @@ def test_avoids_volunteer_who_would_exceed_eight_hours_that_day():
|
||||
fresh = _volunteer("fresh", availability=[_full_day(10)])
|
||||
solution = solve(SolverInput(shifts=(shift,), volunteers=(tired, fresh)))
|
||||
assert _by_shift(solution, "s1") == ("fresh",)
|
||||
|
||||
|
||||
def test_avoids_volunteer_whose_wished_artist_plays_during_the_shift():
|
||||
# Le créneau (14 h - 18 h) chevauche le passage de l'artiste (16 h - 17 h)
|
||||
# que « fan » veut voir : le solveur préfère « indiff », qui n'a pas ce
|
||||
# conflit.
|
||||
shift = _shift(start=_dt(10, 14), end=_dt(10, 18))
|
||||
passage = ShiftInfo(id="art1", starts_at=_dt(10, 16), ends_at=_dt(10, 17))
|
||||
fan = _volunteer(
|
||||
"fan", availability=[_full_day(10)], wished_artist_windows=[passage]
|
||||
)
|
||||
indiff = _volunteer("indiff", availability=[_full_day(10)])
|
||||
solution = solve(SolverInput(shifts=(shift,), volunteers=(fan, indiff)))
|
||||
assert _by_shift(solution, "s1") == ("indiff",)
|
||||
|
||||
|
||||
def test_still_suggests_the_only_candidate_despite_an_artist_conflict():
|
||||
# Le conflit d'artiste reste un avertissement, pas un blocage : s'il n'y a
|
||||
# personne d'autre pour un créneau urgent, le solveur propose quand même.
|
||||
shift = _shift(start=_dt(10, 14), end=_dt(10, 18))
|
||||
passage = ShiftInfo(id="art1", starts_at=_dt(10, 16), ends_at=_dt(10, 17))
|
||||
fan = _volunteer(
|
||||
"fan", availability=[_full_day(10)], wished_artist_windows=[passage]
|
||||
)
|
||||
solution = solve(SolverInput(shifts=(shift,), volunteers=(fan,)))
|
||||
assert _by_shift(solution, "s1") == ("fan",)
|
||||
|
||||
|
||||
def test_artist_conflict_outside_shift_hours_has_no_effect():
|
||||
# Le passage (20 h - 21 h) ne chevauche pas le créneau (14 h - 18 h) :
|
||||
# aucun malus, « fan » reste un candidat normal.
|
||||
shift = _shift(start=_dt(10, 14), end=_dt(10, 18))
|
||||
passage = ShiftInfo(id="art1", starts_at=_dt(10, 20), ends_at=_dt(10, 21))
|
||||
fan = _volunteer(
|
||||
"fan", availability=[_full_day(10)], wished_artist_windows=[passage]
|
||||
)
|
||||
solution = solve(SolverInput(shifts=(shift,), volunteers=(fan,)))
|
||||
assert _by_shift(solution, "s1") == ("fan",)
|
||||
|
||||
Reference in New Issue
Block a user