add puzzle training sessions with difficulty and ratings

- /train starts an ephemeral session by choosing easy/medium/hard, banded
  relative to the user's current rating (band width configurable)
- session timer, average per-puzzle time, net rating gain and per-puzzle delta
- next puzzle, plus review and retry reused from the play surface
- explicit stop/start: stopping returns to the difficulty picker
- puzzle rating shown once a puzzle completes, and a side-to-move indicator
- extract the play logic/markup into shared PlayCore and PlayComponents so the
  standalone play view and sessions share one implementation
- sticky footer; glossary entries for Difficulty and Session; ADR 0009
This commit is contained in:
2026-11-05 15:44:11 +01:00
parent c95173cda8
commit 55d2e2a913
19 changed files with 1705 additions and 766 deletions
+13 -2
View File
@@ -27,8 +27,10 @@ defmodule Chesstrainer.Ratings do
Rates both sides of a finished attempt and stamps it as rated.
A solve scores 1 for the user and 0 for the endgame; a failure scores 0 for
the user and 1 for the endgame. Returns `{:ok, %{user, endgame, attempt}}`, or
the user and 1 for the endgame. Returns
`{:ok, %{user, endgame, attempt, user_delta, endgame_delta}}`, or
`{:skipped, attempt}` when the pair was already rated inside the window.
The deltas are the signed change applied to each side's rating.
"""
def rate_attempt(%Attempt{outcome: outcome} = attempt) do
now = DateTime.utc_now(:second)
@@ -74,6 +76,9 @@ defmodule Chesstrainer.Ratings do
end
defp persist(user, endgame, attempt, new_user, new_endgame, now) do
user_delta = new_user.rating - user.rating
endgame_delta = new_endgame.rating - endgame.rating
Repo.transaction(fn ->
user =
user
@@ -96,7 +101,13 @@ defmodule Chesstrainer.Ratings do
|> Ecto.Changeset.change(rated_at: now)
|> Repo.update!()
%{user: user, endgame: endgame, attempt: attempt}
%{
user: user,
endgame: endgame,
attempt: attempt,
user_delta: user_delta,
endgame_delta: endgame_delta
}
end)
end