Enhance Slot Difference Annotation and Rematch Suggestion Logic
Deploy Development / deploy (push) Successful in 43s
Test Suite / pytest-backend (push) Successful in 44s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 14s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Successful in 1m13s
Deploy Development / deploy (push) Successful in 43s
Test Suite / pytest-backend (push) Successful in 44s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 14s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Successful in 1m13s
- Introduced `_annotate_slot_diffs` to mark trivial ID swaps in slot differences, improving clarity in comparison results. - Added `_actionable_slot_diffs` to filter out non-actionable differences, streamlining the evaluation process. - Implemented `_build_rematch_suggestion_diffs` to generate suggestions based on rematch logs, enhancing the path optimization workflow. - Updated `_build_progression_compare_response` to incorporate actionable slot differences and rematch suggestions, improving the response structure. - Enhanced frontend components to display rematch suggestions and handle trivial differences more effectively. - Bumped version to reflect the new features and improvements.
This commit is contained in:
1 parent
e828a5da32
commit
dccb065181
11 files changed
+552
-84
No files matched your search
@@ -2208,20 +2208,120 @@ def _normalize_slot_title(title: Optional[str]) -> str:
|
||||
return (title or "").strip().casefold()
|
||||
|
||||
|
||||
def _filter_trivial_slot_diffs(diffs: Sequence[Mapping[str, Any]]) -> List[Dict[str, Any]]:
|
||||
"""Gleicher sichtbarer Titel = kein inhaltlicher Wechsel (nur ID-Doppel in der Bibliothek)."""
|
||||
def _annotate_slot_diffs(
|
||||
diffs: Sequence[Mapping[str, Any]],
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""Kennzeichnet reine ID-Tausche (gleicher Titel) — bleiben sichtbar, zählen aber nicht als inhaltlich."""
|
||||
out: List[Dict[str, Any]] = []
|
||||
for raw in diffs or []:
|
||||
if not isinstance(raw, dict):
|
||||
continue
|
||||
bt = _normalize_slot_title(raw.get("baseline_title"))
|
||||
pt = _normalize_slot_title(raw.get("proposed_title"))
|
||||
if bt and pt and bt == pt:
|
||||
continue
|
||||
out.append(dict(raw))
|
||||
entry = dict(raw)
|
||||
bt = _normalize_slot_title(entry.get("baseline_title"))
|
||||
pt = _normalize_slot_title(entry.get("proposed_title"))
|
||||
entry["trivial_id_swap"] = bool(bt and pt and bt == pt)
|
||||
out.append(entry)
|
||||
return out
|
||||
|
||||
|
||||
def _actionable_slot_diffs(diffs: Sequence[Mapping[str, Any]]) -> List[Dict[str, Any]]:
|
||||
return [d for d in diffs if not d.get("trivial_id_swap")]
|
||||
|
||||
|
||||
def _last_rematch_replacements_by_slot(
|
||||
rematch_log: Sequence[Mapping[str, Any]],
|
||||
) -> Dict[int, Mapping[str, Any]]:
|
||||
"""Letzter erfolgreicher Replace je Slot (Multi-Runden-Rematch)."""
|
||||
out: Dict[int, Mapping[str, Any]] = {}
|
||||
for entry in rematch_log or []:
|
||||
if not isinstance(entry, dict):
|
||||
continue
|
||||
if str(entry.get("action") or "") != "replaced":
|
||||
continue
|
||||
if entry.get("new_exercise_id") is None:
|
||||
continue
|
||||
midx = entry.get("roadmap_major_step_index")
|
||||
if midx is None:
|
||||
continue
|
||||
out[int(midx)] = entry
|
||||
return out
|
||||
|
||||
|
||||
def _build_rematch_suggestion_diffs(
|
||||
baseline_steps: Sequence[Mapping[str, Any]],
|
||||
rematch_log: Sequence[Mapping[str, Any]],
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""Vorschläge aus Rematch-Protokoll, wenn End-Pfad vs. Baseline identisch wirkt."""
|
||||
base_by = _steps_by_major_index(baseline_steps)
|
||||
replacements = _last_rematch_replacements_by_slot(rematch_log)
|
||||
diffs: List[Dict[str, Any]] = []
|
||||
for midx, entry in sorted(replacements.items()):
|
||||
base = base_by.get(midx, {})
|
||||
base_id = base.get("exercise_id")
|
||||
new_id = entry.get("new_exercise_id")
|
||||
base_title = (base.get("title") or "").strip() or None
|
||||
new_title = (entry.get("new_title") or "").strip() or None
|
||||
same_id = False
|
||||
if base_id is not None and new_id is not None:
|
||||
try:
|
||||
same_id = int(base_id) == int(new_id)
|
||||
except (TypeError, ValueError):
|
||||
same_id = False
|
||||
if same_id:
|
||||
bt = _normalize_slot_title(base_title)
|
||||
pt = _normalize_slot_title(new_title)
|
||||
if bt and pt and bt == pt:
|
||||
continue
|
||||
diffs.append(
|
||||
{
|
||||
"roadmap_major_step_index": midx,
|
||||
"baseline_exercise_id": int(base_id) if base_id is not None else None,
|
||||
"baseline_title": base_title,
|
||||
"proposed_exercise_id": int(new_id) if new_id is not None else None,
|
||||
"proposed_title": new_title,
|
||||
"baseline_slot_status": base.get("slot_status"),
|
||||
"proposed_slot_status": "matched",
|
||||
"changed": True,
|
||||
"from_rematch_log": True,
|
||||
}
|
||||
)
|
||||
return diffs
|
||||
|
||||
|
||||
def _overlay_rematch_suggestions_on_steps(
|
||||
proposed_steps: Sequence[Mapping[str, Any]],
|
||||
suggestion_diffs: Sequence[Mapping[str, Any]],
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""Ergänzt proposed_steps um Rematch-Kandidaten (für selektive Übernahme)."""
|
||||
if not suggestion_diffs:
|
||||
return list(proposed_steps or [])
|
||||
prop_by = _steps_by_major_index(proposed_steps)
|
||||
for diff in suggestion_diffs:
|
||||
if not isinstance(diff, dict) or not diff.get("from_rematch_log"):
|
||||
continue
|
||||
midx = diff.get("roadmap_major_step_index")
|
||||
new_id = diff.get("proposed_exercise_id")
|
||||
if midx is None or new_id is None:
|
||||
continue
|
||||
existing = dict(prop_by.get(int(midx), {}))
|
||||
existing.update(
|
||||
{
|
||||
"exercise_id": int(new_id),
|
||||
"title": diff.get("proposed_title") or existing.get("title"),
|
||||
"variant_id": existing.get("variant_id"),
|
||||
"roadmap_major_step_index": int(midx),
|
||||
"is_ai_proposal": False,
|
||||
"slot_status": "matched",
|
||||
"roadmap_match_source": "rematch_suggestion",
|
||||
}
|
||||
)
|
||||
prop_by[int(midx)] = existing
|
||||
ordered: List[Dict[str, Any]] = []
|
||||
for midx in sorted(prop_by.keys()):
|
||||
ordered.append(prop_by[midx])
|
||||
return ordered
|
||||
|
||||
|
||||
def _build_progression_slot_diffs(
|
||||
baseline_steps: Sequence[Mapping[str, Any]],
|
||||
proposed_steps: Sequence[Mapping[str, Any]],
|
||||
@@ -2269,24 +2369,46 @@ def _build_progression_compare_response(
|
||||
if isinstance(proposed_eval, dict) and isinstance(proposed_eval.get("path_qa"), dict)
|
||||
else pipeline_qa
|
||||
)
|
||||
slot_diffs = _filter_trivial_slot_diffs(
|
||||
slot_diffs = _annotate_slot_diffs(
|
||||
_build_progression_slot_diffs(baseline_steps, proposed_steps),
|
||||
)
|
||||
actionable_diffs = _actionable_slot_diffs(slot_diffs)
|
||||
slot_diffs_source = "steps"
|
||||
rematch_log = (
|
||||
pipeline_qa.get("rematch_log")
|
||||
if isinstance(pipeline_qa.get("rematch_log"), list)
|
||||
else []
|
||||
)
|
||||
apply_steps = list(proposed_steps)
|
||||
if not actionable_diffs and rematch_log:
|
||||
rematch_raw = _build_rematch_suggestion_diffs(baseline_steps, rematch_log)
|
||||
rematch_diffs = _annotate_slot_diffs(rematch_raw)
|
||||
rematch_actionable = _actionable_slot_diffs(rematch_diffs)
|
||||
if rematch_actionable:
|
||||
actionable_diffs = rematch_actionable
|
||||
slot_diffs = rematch_diffs
|
||||
slot_diffs_source = "rematch_log"
|
||||
apply_steps = _overlay_rematch_suggestions_on_steps(proposed_steps, rematch_actionable)
|
||||
return {
|
||||
**dict(proposed),
|
||||
"comparison_mode": True,
|
||||
"baseline_steps": baseline_steps,
|
||||
"baseline_path_qa": baseline_qa,
|
||||
"proposed_steps": proposed_steps,
|
||||
"proposed_steps": apply_steps,
|
||||
"proposed_steps_pipeline": proposed_steps,
|
||||
"proposed_path_qa": fair_qa,
|
||||
"proposed_path_qa_pipeline": pipeline_qa,
|
||||
"slot_diffs": slot_diffs,
|
||||
"slot_diff_count": len(slot_diffs),
|
||||
"slot_diffs_actionable": actionable_diffs,
|
||||
"slot_diff_count": len(actionable_diffs),
|
||||
"slot_diff_count_including_trivial": len(slot_diffs),
|
||||
"slot_diffs_source": slot_diffs_source,
|
||||
"optimization_actionable": len(actionable_diffs) > 0,
|
||||
"baseline_quality_score": _path_qa_quality_score(baseline_qa),
|
||||
"proposed_quality_score": _path_qa_quality_score(fair_qa),
|
||||
"proposed_pipeline_quality_score": _path_qa_quality_score(pipeline_qa),
|
||||
"path_qa": fair_qa,
|
||||
"steps": proposed_steps,
|
||||
"steps": apply_steps,
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
"""Tests Vergleichs-Diffs (triviale ID-Tausche ausfiltern)."""
|
||||
"""Tests Vergleichs-Diffs (triviale ID-Tausche markieren, Rematch-Vorschläge)."""
|
||||
from planning_exercise_path_builder import (
|
||||
_actionable_slot_diffs,
|
||||
_annotate_slot_diffs,
|
||||
_build_progression_compare_response,
|
||||
_build_progression_slot_diffs,
|
||||
_filter_trivial_slot_diffs,
|
||||
_build_rematch_suggestion_diffs,
|
||||
)
|
||||
|
||||
|
||||
def test_filter_trivial_slot_diffs_same_title_different_id():
|
||||
def test_annotate_trivial_id_swap():
|
||||
diffs = [
|
||||
{
|
||||
"roadmap_major_step_index": 1,
|
||||
@@ -15,10 +18,13 @@ def test_filter_trivial_slot_diffs_same_title_different_id():
|
||||
"proposed_title": "Rhythmuswechsel in der Kumite-Beinarbeit",
|
||||
}
|
||||
]
|
||||
assert _filter_trivial_slot_diffs(diffs) == []
|
||||
annotated = _annotate_slot_diffs(diffs)
|
||||
assert len(annotated) == 1
|
||||
assert annotated[0]["trivial_id_swap"] is True
|
||||
assert _actionable_slot_diffs(annotated) == []
|
||||
|
||||
|
||||
def test_filter_trivial_slot_diffs_keeps_real_title_change():
|
||||
def test_annotate_keeps_real_title_change():
|
||||
diffs = [
|
||||
{
|
||||
"roadmap_major_step_index": 1,
|
||||
@@ -28,12 +34,12 @@ def test_filter_trivial_slot_diffs_keeps_real_title_change():
|
||||
"proposed_title": "Neu",
|
||||
}
|
||||
]
|
||||
filtered = _filter_trivial_slot_diffs(diffs)
|
||||
assert len(filtered) == 1
|
||||
assert filtered[0]["proposed_title"] == "Neu"
|
||||
annotated = _annotate_slot_diffs(diffs)
|
||||
assert annotated[0]["trivial_id_swap"] is False
|
||||
assert len(_actionable_slot_diffs(annotated)) == 1
|
||||
|
||||
|
||||
def test_build_slot_diffs_then_filter():
|
||||
def test_build_slot_diffs_then_annotate():
|
||||
baseline = [
|
||||
{"roadmap_major_step_index": 0, "exercise_id": 1, "title": "A"},
|
||||
{"roadmap_major_step_index": 1, "exercise_id": 10, "title": "Gleich"},
|
||||
@@ -43,5 +49,54 @@ def test_build_slot_diffs_then_filter():
|
||||
{"roadmap_major_step_index": 1, "exercise_id": 77, "title": "Gleich"},
|
||||
]
|
||||
raw = _build_progression_slot_diffs(baseline, proposed)
|
||||
assert len(raw) == 1
|
||||
assert _filter_trivial_slot_diffs(raw) == []
|
||||
annotated = _annotate_slot_diffs(raw)
|
||||
assert len(annotated) == 1
|
||||
assert annotated[0]["trivial_id_swap"] is True
|
||||
assert _actionable_slot_diffs(annotated) == []
|
||||
|
||||
|
||||
def test_rematch_suggestion_diffs_when_end_path_matches_baseline():
|
||||
baseline = [
|
||||
{"roadmap_major_step_index": 1, "exercise_id": None, "title": "Lernziel Slot 2"},
|
||||
{"roadmap_major_step_index": 4, "exercise_id": 50, "title": "Bestehend"},
|
||||
]
|
||||
proposed = list(baseline)
|
||||
rematch_log = [
|
||||
{
|
||||
"roadmap_major_step_index": 1,
|
||||
"action": "replaced",
|
||||
"round": 1,
|
||||
"new_exercise_id": 101,
|
||||
"new_title": "Rhythmuswechsel in der Kumite-Beinarbeit",
|
||||
"replaced_exercise_id": None,
|
||||
"replaced_title": None,
|
||||
},
|
||||
{
|
||||
"roadmap_major_step_index": 1,
|
||||
"action": "replaced",
|
||||
"round": 3,
|
||||
"new_exercise_id": 102,
|
||||
"new_title": "Kumite Beinarbeit — vertiefung",
|
||||
"replaced_exercise_id": 101,
|
||||
"replaced_title": "Rhythmuswechsel in der Kumite-Beinarbeit",
|
||||
},
|
||||
]
|
||||
diffs = _build_rematch_suggestion_diffs(baseline, rematch_log)
|
||||
assert len(diffs) == 1
|
||||
assert diffs[0]["proposed_exercise_id"] == 102
|
||||
assert diffs[0]["from_rematch_log"] is True
|
||||
|
||||
compare = _build_progression_compare_response(
|
||||
{"steps": baseline, "path_qa": {"overall_ok": True, "quality_score": 0.88}},
|
||||
{
|
||||
"steps": proposed,
|
||||
"path_qa": {
|
||||
"overall_ok": False,
|
||||
"quality_score": 0.65,
|
||||
"rematch_log": rematch_log,
|
||||
},
|
||||
},
|
||||
)
|
||||
assert compare["slot_diffs_source"] == "rematch_log"
|
||||
assert compare["slot_diff_count"] == 1
|
||||
assert compare["proposed_steps"][0]["exercise_id"] == 102
|
||||
Reference in new issue
Block a user