Implement Comparison Logic for Progression Path Suggestions
Deploy Development / deploy (push) Successful in 44s
Test Suite / pytest-backend (push) Successful in 45s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 14s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m18s
Deploy Development / deploy (push) Successful in 44s
Test Suite / pytest-backend (push) Successful in 45s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 14s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m18s
- Added `compare_with_assignments` flag to `ProgressionPathSuggestRequest` to enable comparison of proposed paths with existing slot assignments. - Introduced `_assignment_preservation_active` function to determine if existing assignments should be preserved during path suggestions. - Enhanced `suggest_progression_path` to handle comparison logic, including validation for minimum slot assignments required for comparison. - Implemented `_build_progression_compare_response` to structure the response for comparison results, including slot differences and quality scores. - Updated frontend components to support new comparison features, including handling of slot assignments and optimization comparisons. - Bumped version to reflect the new features and improvements.
This commit is contained in:
1 parent
b8f65e04c5
commit
5ed06002d9
7 files changed
+695
-26
No files matched your search
@@ -141,6 +141,7 @@ class ProgressionPathSuggestRequest(BaseModel):
|
||||
roadmap_notes: Optional[str] = Field(default=None, max_length=2000)
|
||||
progression_graph_id: Optional[int] = Field(default=None, ge=1)
|
||||
exercise_kind_any: Optional[List[str]] = None
|
||||
compare_with_assignments: bool = False
|
||||
planning_catalog_context: Optional[ProgressionPlanningCatalogContext] = None
|
||||
|
||||
|
||||
@@ -676,6 +677,11 @@ def _slot_assignments_by_major_index(
|
||||
return out
|
||||
|
||||
|
||||
def _assignment_preservation_active(body: ProgressionPathSuggestRequest) -> bool:
|
||||
"""Trainer-Pfad schützen — nur bei explizitem Flag (Frontend entscheidet pro Aktion)."""
|
||||
return bool(body.preserve_slot_assignments)
|
||||
|
||||
|
||||
def _path_step_from_slot_assignment(
|
||||
cur,
|
||||
*,
|
||||
@@ -1848,11 +1854,33 @@ def _build_steps_roadmap_first(
|
||||
if roadmap_ctx.roadmap:
|
||||
majors_by_index = {m.index: m for m in roadmap_ctx.roadmap.major_steps}
|
||||
|
||||
preserve_assignments = _assignment_preservation_active(body)
|
||||
|
||||
for step_index, stage_spec in enumerate(stage_specs):
|
||||
major_idx = stage_spec.major_step_index
|
||||
major = majors_by_index.get(major_idx)
|
||||
slot_priority_id: Optional[int] = None
|
||||
|
||||
if preserve_assignments and major_idx in assignments:
|
||||
direct = _path_step_from_slot_assignment(
|
||||
cur,
|
||||
assignment=assignments[major_idx],
|
||||
stage_spec=stage_spec,
|
||||
major_step=major,
|
||||
tenant=tenant,
|
||||
progression_graph_id=body.progression_graph_id,
|
||||
)
|
||||
if direct:
|
||||
direct["slot_status"] = "preserved"
|
||||
direct["roadmap_match_source"] = "slot_best_match"
|
||||
steps.append(direct)
|
||||
eid = int(direct["exercise_id"])
|
||||
used.add(eid)
|
||||
planned_ids.append(eid)
|
||||
anchor_id = eid
|
||||
anchor_variant_id = direct.get("variant_id")
|
||||
continue
|
||||
|
||||
if major_idx in assignments:
|
||||
try:
|
||||
slot_priority_id = int(assignments[major_idx].exercise_id)
|
||||
@@ -2123,6 +2151,88 @@ def _run_evaluate_only_path_qa(
|
||||
}
|
||||
|
||||
|
||||
def _path_qa_quality_score(path_qa: Optional[Mapping[str, Any]]) -> Optional[float]:
|
||||
if not path_qa:
|
||||
return None
|
||||
raw = path_qa.get("quality_score")
|
||||
try:
|
||||
return float(raw) if raw is not None else None
|
||||
except (TypeError, ValueError):
|
||||
return None
|
||||
|
||||
|
||||
def _steps_by_major_index(steps: Sequence[Mapping[str, Any]]) -> Dict[int, Dict[str, Any]]:
|
||||
out: Dict[int, Dict[str, Any]] = {}
|
||||
for raw in steps or []:
|
||||
if not isinstance(raw, dict):
|
||||
continue
|
||||
midx = raw.get("roadmap_major_step_index")
|
||||
if midx is None:
|
||||
continue
|
||||
try:
|
||||
out[int(midx)] = dict(raw)
|
||||
except (TypeError, ValueError):
|
||||
continue
|
||||
return out
|
||||
|
||||
|
||||
def _build_progression_slot_diffs(
|
||||
baseline_steps: Sequence[Mapping[str, Any]],
|
||||
proposed_steps: Sequence[Mapping[str, Any]],
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""Gegenüberstellung je Roadmap-Slot — nur geänderte oder neu leere Slots."""
|
||||
base_by = _steps_by_major_index(baseline_steps)
|
||||
prop_by = _steps_by_major_index(proposed_steps)
|
||||
diffs: List[Dict[str, Any]] = []
|
||||
for midx in sorted(set(base_by.keys()) | set(prop_by.keys())):
|
||||
base = base_by.get(midx, {})
|
||||
prop = prop_by.get(midx, {})
|
||||
base_id = base.get("exercise_id")
|
||||
prop_id = prop.get("exercise_id")
|
||||
base_title = (base.get("title") or "").strip() or None
|
||||
prop_title = (prop.get("title") or "").strip() or None
|
||||
if base_id is not None and prop_id is not None and int(base_id) == int(prop_id):
|
||||
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(prop_id) if prop_id is not None else None,
|
||||
"proposed_title": prop_title,
|
||||
"baseline_slot_status": base.get("slot_status"),
|
||||
"proposed_slot_status": prop.get("slot_status"),
|
||||
"changed": base_id != prop_id or base_title != prop_title,
|
||||
}
|
||||
)
|
||||
return diffs
|
||||
|
||||
|
||||
def _build_progression_compare_response(
|
||||
baseline: Mapping[str, Any],
|
||||
proposed: Mapping[str, Any],
|
||||
) -> Dict[str, Any]:
|
||||
baseline_steps = list(baseline.get("steps") or [])
|
||||
proposed_steps = list(proposed.get("steps") or [])
|
||||
baseline_qa = baseline.get("path_qa") if isinstance(baseline.get("path_qa"), dict) else {}
|
||||
proposed_qa = proposed.get("path_qa") if isinstance(proposed.get("path_qa"), dict) else {}
|
||||
slot_diffs = _build_progression_slot_diffs(baseline_steps, proposed_steps)
|
||||
return {
|
||||
**dict(proposed),
|
||||
"comparison_mode": True,
|
||||
"baseline_steps": baseline_steps,
|
||||
"baseline_path_qa": baseline_qa,
|
||||
"proposed_steps": proposed_steps,
|
||||
"proposed_path_qa": proposed_qa,
|
||||
"slot_diffs": slot_diffs,
|
||||
"slot_diff_count": len(slot_diffs),
|
||||
"baseline_quality_score": _path_qa_quality_score(baseline_qa),
|
||||
"proposed_quality_score": _path_qa_quality_score(proposed_qa),
|
||||
"path_qa": proposed_qa,
|
||||
"steps": proposed_steps,
|
||||
}
|
||||
|
||||
|
||||
def suggest_progression_path(
|
||||
cur,
|
||||
*,
|
||||
@@ -2133,6 +2243,32 @@ def suggest_progression_path(
|
||||
if not _has_planning_role(role):
|
||||
raise HTTPException(status_code=403, detail="Nur Trainer dürfen Pfad-Vorschläge abrufen")
|
||||
|
||||
if body.compare_with_assignments:
|
||||
assignments = _slot_assignments_by_major_index(body.slot_assignments)
|
||||
if len(assignments) < 1:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="compare_with_assignments erfordert mindestens ein slot_assignment",
|
||||
)
|
||||
baseline_body = body.model_copy(
|
||||
update={
|
||||
"evaluate_only": True,
|
||||
"evaluate_steps": list(body.slot_assignments or []),
|
||||
"compare_with_assignments": False,
|
||||
"preserve_slot_assignments": True,
|
||||
}
|
||||
)
|
||||
baseline = suggest_progression_path(cur, tenant=tenant, body=baseline_body)
|
||||
proposed_body = body.model_copy(
|
||||
update={
|
||||
"compare_with_assignments": False,
|
||||
"preserve_slot_assignments": False,
|
||||
"evaluate_only": False,
|
||||
}
|
||||
)
|
||||
proposed = suggest_progression_path(cur, tenant=tenant, body=proposed_body)
|
||||
return _build_progression_compare_response(baseline, proposed)
|
||||
|
||||
goal_query = _normalize_query(body.query)
|
||||
if len(goal_query) < 3:
|
||||
raise HTTPException(status_code=400, detail="Ziel-Anfrage: mindestens 3 Zeichen")
|
||||
@@ -2431,6 +2567,7 @@ def suggest_progression_path(
|
||||
reorder_notes: List[str] = []
|
||||
|
||||
roadmap_qa_mode: Optional[str] = None
|
||||
preserve_assignments = _assignment_preservation_active(body)
|
||||
if body.include_path_qa:
|
||||
if roadmap_first:
|
||||
roadmap_qa_mode = "roadmap_first_lite"
|
||||
@@ -2466,7 +2603,9 @@ def suggest_progression_path(
|
||||
elif gaps and roadmap_first:
|
||||
unfilled_gaps = list(gaps)
|
||||
|
||||
if body.include_llm_path_qa and not roadmap_first:
|
||||
if body.include_llm_path_qa and (
|
||||
not roadmap_first or preserve_assignments
|
||||
):
|
||||
llm_qa, llm_qa_applied = try_llm_qa_progression_path(
|
||||
cur,
|
||||
goal_query=goal_query,
|
||||
@@ -2497,11 +2636,14 @@ def suggest_progression_path(
|
||||
goal_query=goal_query,
|
||||
)
|
||||
off_topic_before_strip = list(off_topic_steps)
|
||||
steps, stripped_off_topic = strip_off_topic_steps_from_path(
|
||||
steps,
|
||||
off_topic_steps,
|
||||
min_remaining=0 if roadmap_first else 2,
|
||||
)
|
||||
if preserve_assignments:
|
||||
stripped_off_topic = []
|
||||
else:
|
||||
steps, stripped_off_topic = strip_off_topic_steps_from_path(
|
||||
steps,
|
||||
off_topic_steps,
|
||||
min_remaining=0 if roadmap_first else 2,
|
||||
)
|
||||
if stripped_off_topic:
|
||||
off_topic_steps = []
|
||||
gaps = detect_path_gaps(
|
||||
@@ -2511,7 +2653,7 @@ def suggest_progression_path(
|
||||
roadmap_first=roadmap_first,
|
||||
)
|
||||
|
||||
if roadmap_first and roadmap_ctx is not None:
|
||||
if roadmap_first and roadmap_ctx is not None and not preserve_assignments:
|
||||
(
|
||||
steps,
|
||||
rematch_log,
|
||||
@@ -2545,7 +2687,7 @@ def suggest_progression_path(
|
||||
roadmap_first=roadmap_first,
|
||||
)
|
||||
|
||||
if body.include_llm_path_qa and roadmap_first:
|
||||
if body.include_llm_path_qa and roadmap_first and not preserve_assignments:
|
||||
gaps = detect_path_gaps(
|
||||
cur,
|
||||
steps,
|
||||
@@ -2656,6 +2798,8 @@ def suggest_progression_path(
|
||||
path_qa["refine_applied"] = True
|
||||
path_qa["refine_log"] = refine_log
|
||||
path_qa["refine_count"] = len(refine_log)
|
||||
if preserve_assignments:
|
||||
path_qa["assignments_preserved"] = True
|
||||
|
||||
filled_library_steps = sum(1 for s in steps if s.get("exercise_id") is not None)
|
||||
match_summary = {
|
||||
|
||||
Reference in new issue
Block a user