Bonus za sérii a hájení plných bodů 3,5 s (#26)
CI / test (push) Successful in 19s
CI / docker (push) Successful in 5s

Série nově ovlivňuje body, aby běžná hra a připravovaný živý režim pro třídu (`zivy-rezim-trida`) bodovaly srovnatelně. OpenSpec změna `bonus-za-serii`.

## Změny
- Za každou odpověď `spravne` se k bodům z časové křivky přičte bonus `min(série − 1, 5) × 10 %` základního maxima režimu (*Psaní* +100 až +500 b., *A–D* +50 až +250 b.). Bonus nezávisí na čase.
- `max_body` počítá s nepřerušenou sérií (4 otázky *Psaní* = 4600, 8 otázek *A–D* = 5250). `odpovedi.body` obsahují bonus, součet dál sedí s `kola.body`.
- API po odpovědi vrací `streak_bonus`. Zpětná vazba ukazuje body za odpověď a štítek „+200 za sérii ×3“ zvlášť, pod prstencem je štítek s bonusem za příští správnou odpověď.
- **BREAKING:** výchozí `POZNAVACKY_SCORE_GRACE_SECONDS` je `3.5` (dosud `2.0`). Starší kola se nepřepočítávají.
- `docs/navrh.md` a hlavní specifikace `answer-scoring` a `quiz-gameplay` aktualizovány, změna archivována.

## Ověření
- `pytest` 357 passed, `ruff check` bez chyb.
- Ručně v Chrome nad syntetickou sadou o 8 položkách: *Psaní* bonus 0 / +100 / … / +500 / +500, *A–D* 0 / +50 / … / +250, po chybě bez bonusu, shrnutí „z 5 250 možných“.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_013nPfHU2PPEvpqm9w9WixvF
Reviewed-on: #26
Co-authored-by: David Spáčil <spacildavi@gmail.com>
This commit was merged in pull request #26.
This commit is contained in:
david-spacil authored and David Spáčil committed 2026-11-29 18:00:45 +01:00
1 parent 745fb341c0
commit 4e52d46e7f
18 files changed
+617 -63

No files matched your search

+40 -11
View File
@@ -9,6 +9,7 @@ from poznavacky.scoring import (
AnswerItemSpec,
ScoringConfig,
calculate_question_points,
calculate_question_score,
calculate_round_max_points,
calculate_weighted_accuracy,
damerau_levenshtein,
@@ -34,7 +35,7 @@ def _item(
def test_scoring_config_defaults_and_custom_env() -> None:
cfg = load_config(environ={}, overrides={"TESTING": True})
assert cfg.score_grace_seconds == 2.0
assert cfg.score_grace_seconds == 3.5
assert cfg.score_max_seconds == 15.0
assert cfg.score_floor_ratio == 0.30
assert cfg.quick_round_size == 10
@@ -82,19 +83,19 @@ def test_scoring_config_rejects_invalid_values(
def test_time_scoring_curve_default_boundaries() -> None:
cfg = ScoringConfig()
# Grace period 0-2 s -> 100 % maxima.
# Grace period 0-3.5 s -> 100 % maxima.
assert calculate_question_points("psani", "spravne", 0, cfg) == 1000
assert calculate_question_points("psani", "spravne", 1800, cfg) == 1000
assert calculate_question_points("psani", "spravne", 2000, cfg) == 1000
assert calculate_question_points("psani", "spravne", 3400, cfg) == 1000
assert calculate_question_points("psani", "spravne", 3500, cfg) == 1000
assert calculate_question_points("psani", "castecne", 1500, cfg) == 500
assert calculate_question_points("abcd", "spravne", 2000, cfg) == 500
assert calculate_question_points("abcd", "spravne", 3500, cfg) == 500
assert calculate_question_points("psani", "spatne", 500, cfg) == 0
assert calculate_question_points("abcd", "spatne", 500, cfg) == 0
# Střed intervalu (8.5 s mezi 2.0 a 15.0 s -> koeficient 0.65).
assert calculate_question_points("psani", "spravne", 8500, cfg) == 650
assert calculate_question_points("psani", "castecne", 8500, cfg) == 325
assert calculate_question_points("abcd", "spravne", 8500, cfg) == 325
# Střed intervalu (9.25 s mezi 3.5 a 15.0 s -> koeficient 0.65).
assert calculate_question_points("psani", "spravne", 9250, cfg) == 650
assert calculate_question_points("psani", "castecne", 9250, cfg) == 325
assert calculate_question_points("abcd", "spravne", 9250, cfg) == 325
# Strop a nad stropem -> podlaha 30 %.
assert calculate_question_points("psani", "spravne", 15000, cfg) == 300
@@ -104,6 +105,33 @@ def test_time_scoring_curve_default_boundaries() -> None:
assert calculate_question_points("psani", "spatne", 20000, cfg) == 0
def test_streak_bonus_grows_and_caps() -> None:
totals = [
calculate_question_score("psani", "spravne", 1000, streak).total
for streak in range(1, 8)
]
assert totals == [1000, 1100, 1200, 1300, 1400, 1500, 1500]
def test_streak_bonus_is_time_independent_and_halved_in_abcd() -> None:
score = calculate_question_score("abcd", "spravne", 20000, 3)
assert score.time_points == 150
assert score.streak_bonus == 100
assert score.total == 250
def test_partial_answer_gets_no_bonus_and_breaks_streak() -> None:
# Po dvou `spravne` přijde `castecne` (série -> 0) a pak `spravne`
# (série 1).
partial = calculate_question_score("psani", "castecne", 1000, 0)
assert (partial.time_points, partial.streak_bonus) == (500, 0)
# Ani případná nenulová série bonus k `castecne` nepřidá.
assert calculate_question_score("psani", "castecne", 1000, 3).total == 500
after = calculate_question_score("psani", "spravne", 1000, 1)
assert (after.time_points, after.streak_bonus) == (1000, 0)
assert calculate_question_score("psani", "spatne", 1000, 0).total == 0
def test_time_scoring_curve_custom_parameters() -> None:
cfg = ScoringConfig(grace_seconds=3.0, max_seconds=13.0, floor_ratio=0.5)
assert calculate_question_points("psani", "spravne", 3000, cfg) == 1000
@@ -116,8 +144,9 @@ def test_weighted_accuracy_and_round_max_points() -> None:
assert calculate_weighted_accuracy(2, 1, 4) == pytest.approx(0.625)
assert calculate_weighted_accuracy(0, 0, 0) == 0.0
assert calculate_weighted_accuracy(3, 0, 3) == 1.0
assert calculate_round_max_points("psani", 4) == 4000
assert calculate_round_max_points("abcd", 4) == 2000
assert calculate_round_max_points("psani", 4) == 4600
assert calculate_round_max_points("abcd", 8) == 5250
assert calculate_round_max_points("abcd", 0) == 0
def test_normalize_and_damerau_levenshtein() -> None: