Enhance Rematch Logic and Slot Filtering in Planning Path
Deploy Development / deploy (push) Successful in 41s
Test Suite / pytest-backend (push) Successful in 45s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 13s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m13s
Deploy Development / deploy (push) Successful in 41s
Test Suite / pytest-backend (push) Successful in 45s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 13s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m13s
- Introduced `filter_rematch_slot_indices` to exclude preserved slots from rematching, improving the accuracy of slot assignments. - Added `_slot_priority_for_rematch` to prioritize existing slot assignments during rematching, enhancing the robustness of the rematch process. - Updated `_run_roadmap_rematch_loop` to utilize the new filtering and prioritization logic, ensuring better handling of rematch scenarios. - Enhanced tests in `test_planning_path_rematch.py` to validate the new filtering behavior and ensure correct exercise restoration when not rejected. - Bumped version to reflect the new features and improvements.
This commit is contained in:
1 parent
f3710ac0a1
commit
b8f65e04c5
4 files changed
+223
-6
No files matched your search
@@ -8,6 +8,40 @@ from typing import Any, Dict, List, Mapping, Optional, Sequence, Set, Tuple
|
||||
from planning_progression_roadmap import ProgressionRoadmapContext, StageSpecArtifact
|
||||
|
||||
|
||||
def _slot_priority_for_rematch(
|
||||
body,
|
||||
*,
|
||||
major_idx: int,
|
||||
old: Optional[Mapping[str, Any]],
|
||||
rejected_by_major: Optional[Mapping[int, Set[int]]],
|
||||
) -> Optional[int]:
|
||||
"""Bestehende Slot-Zuordnung beim Rematch bevorzugen — außer explizit abgelehnt."""
|
||||
priority_id: Optional[int] = None
|
||||
if body is not None:
|
||||
for raw in getattr(body, "slot_assignments", None) or []:
|
||||
midx = getattr(raw, "roadmap_major_step_index", None)
|
||||
if midx is None or int(midx) != int(major_idx):
|
||||
continue
|
||||
eid = getattr(raw, "exercise_id", None)
|
||||
if eid is not None:
|
||||
try:
|
||||
priority_id = int(eid)
|
||||
except (TypeError, ValueError):
|
||||
priority_id = None
|
||||
break
|
||||
if priority_id is None and old and old.get("exercise_id") is not None:
|
||||
try:
|
||||
priority_id = int(old["exercise_id"])
|
||||
except (TypeError, ValueError):
|
||||
priority_id = None
|
||||
if priority_id is None or priority_id < 1:
|
||||
return None
|
||||
rejected = rejected_by_major.get(int(major_idx), set()) if rejected_by_major else set()
|
||||
if priority_id in rejected:
|
||||
return None
|
||||
return priority_id
|
||||
|
||||
|
||||
def collect_rematch_slot_indices(
|
||||
*,
|
||||
stripped_off_topic: Sequence[Mapping[str, Any]],
|
||||
@@ -80,6 +114,43 @@ def collect_rematch_slot_indices(
|
||||
return indices, reasons
|
||||
|
||||
|
||||
def filter_rematch_slot_indices(
|
||||
steps: Sequence[Mapping[str, Any]],
|
||||
slot_indices: Set[int],
|
||||
*,
|
||||
stripped_off_topic: Sequence[Mapping[str, Any]],
|
||||
off_topic_steps: Sequence[Mapping[str, Any]],
|
||||
) -> Set[int]:
|
||||
"""Trainer-Zuordnungen (slot_best_match) nicht rematchen, außer Slot ist explizit beanstandet."""
|
||||
flagged: Set[int] = set()
|
||||
for item in list(stripped_off_topic or []) + list(off_topic_steps or []):
|
||||
if not isinstance(item, dict):
|
||||
continue
|
||||
midx = item.get("roadmap_major_step_index")
|
||||
if midx is not None:
|
||||
try:
|
||||
flagged.add(int(midx))
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
|
||||
preserved: Set[int] = set()
|
||||
for raw in steps or []:
|
||||
if not isinstance(raw, dict):
|
||||
continue
|
||||
midx = raw.get("roadmap_major_step_index")
|
||||
if midx is None:
|
||||
continue
|
||||
try:
|
||||
major_idx = int(midx)
|
||||
except (TypeError, ValueError):
|
||||
continue
|
||||
if raw.get("roadmap_match_source") == "slot_best_match" or raw.get("slot_status") == "preserved":
|
||||
if major_idx not in flagged:
|
||||
preserved.add(major_idx)
|
||||
|
||||
return {idx for idx in slot_indices if idx not in preserved}
|
||||
|
||||
|
||||
def _context_before_major(
|
||||
steps_by_major: Mapping[int, Mapping[str, Any]],
|
||||
target_major: int,
|
||||
@@ -178,6 +249,12 @@ def rematch_roadmap_slots(
|
||||
anchor_id=anchor_id,
|
||||
anchor_variant_id=anchor_variant_id,
|
||||
used=used,
|
||||
slot_priority_exercise_id=_slot_priority_for_rematch(
|
||||
body,
|
||||
major_idx=major_idx,
|
||||
old=old,
|
||||
rejected_by_major=rejected_by_major,
|
||||
),
|
||||
)
|
||||
|
||||
reason = str(rematch_reasons.get(int(major_idx)) or "rematch_slot")
|
||||
@@ -186,12 +263,10 @@ def rematch_roadmap_slots(
|
||||
new_eid = int(new_step.get("exercise_id") or 0)
|
||||
except (TypeError, ValueError):
|
||||
new_eid = 0
|
||||
hist = (
|
||||
slot_assignment_history.get(int(major_idx), set())
|
||||
if slot_assignment_history
|
||||
else set()
|
||||
rejected = (
|
||||
rejected_by_major.get(int(major_idx), set()) if rejected_by_major else set()
|
||||
)
|
||||
if new_eid > 0 and new_eid in hist:
|
||||
if new_eid > 0 and new_eid in rejected:
|
||||
new_step = None
|
||||
if new_step:
|
||||
steps_by_major[int(major_idx)] = new_step
|
||||
@@ -207,6 +282,26 @@ def rematch_roadmap_slots(
|
||||
}
|
||||
)
|
||||
else:
|
||||
if old and old.get("exercise_id") is not None:
|
||||
try:
|
||||
old_eid = int(old["exercise_id"])
|
||||
except (TypeError, ValueError):
|
||||
old_eid = 0
|
||||
rejected = (
|
||||
rejected_by_major.get(int(major_idx), set()) if rejected_by_major else set()
|
||||
)
|
||||
if old_eid > 0 and old_eid not in rejected:
|
||||
steps_by_major[int(major_idx)] = dict(old)
|
||||
rematch_log.append(
|
||||
{
|
||||
"roadmap_major_step_index": int(major_idx),
|
||||
"action": "restored",
|
||||
"reason": reason,
|
||||
"restored_exercise_id": old_eid,
|
||||
"restored_title": old.get("title"),
|
||||
}
|
||||
)
|
||||
continue
|
||||
goal = (stage_spec.learning_goal or "").strip()
|
||||
major = None
|
||||
if roadmap_ctx.roadmap:
|
||||
@@ -278,6 +373,7 @@ def prune_stripped_after_rematch(
|
||||
|
||||
__all__ = [
|
||||
"collect_rematch_slot_indices",
|
||||
"filter_rematch_slot_indices",
|
||||
"prune_stripped_after_rematch",
|
||||
"rematch_roadmap_slots",
|
||||
]
|
||||
Reference in new issue
Block a user