Enhance Path Quality Assessment and Slot Management Features
Deploy Development / deploy (push) Successful in 42s
Test Suite / pytest-backend (push) Successful in 44s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 13s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Successful in 1m13s
Deploy Development / deploy (push) Successful in 42s
Test Suite / pytest-backend (push) Successful in 44s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 13s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Successful in 1m13s
- Added new functions for computing assignment quality scores and counting step assignment statistics, improving the evaluation of steps in path quality assessments. - Updated existing methods to incorporate the new scoring logic, enhancing the robustness of path evaluations. - Introduced UI components in the frontend to display detailed quality assessment results, including handling of split dimensions in path evaluations. - Enhanced tests to cover new functionalities and ensure accuracy in quality scoring and slot management processes.
This commit is contained in:
1 parent
7265cd5a01
commit
313d613b7c
8 files changed
+427
-55
No files matched your search
@@ -688,6 +688,160 @@ def find_step_pair_index(
|
||||
return None
|
||||
|
||||
|
||||
def count_step_assignment_stats(steps: Optional[Sequence[Mapping[str, Any]]]) -> Dict[str, int]:
|
||||
stats = {"total": 0, "empty": 0, "library_filled": 0, "ai_proposal": 0}
|
||||
for raw in steps or []:
|
||||
if not isinstance(raw, dict):
|
||||
continue
|
||||
stats["total"] += 1
|
||||
if raw.get("exercise_id") is not None and not raw.get("is_ai_proposal"):
|
||||
stats["library_filled"] += 1
|
||||
elif raw.get("is_ai_proposal"):
|
||||
stats["ai_proposal"] += 1
|
||||
else:
|
||||
stats["empty"] += 1
|
||||
return stats
|
||||
|
||||
|
||||
def compute_assignment_quality_score(
|
||||
*,
|
||||
steps: Optional[Sequence[Mapping[str, Any]]] = None,
|
||||
off_topic_steps: Optional[Sequence[Mapping[str, Any]]] = None,
|
||||
gaps: Optional[Sequence[Mapping[str, Any]]] = None,
|
||||
) -> float:
|
||||
"""QS der Übungsbesetzung — leere Slots stark abwerten."""
|
||||
stats = count_step_assignment_stats(steps)
|
||||
total = stats["total"]
|
||||
if total <= 0:
|
||||
return 0.45
|
||||
empty = stats["empty"]
|
||||
library = stats["library_filled"]
|
||||
ai = stats["ai_proposal"]
|
||||
fill_credit = (library + 0.55 * ai) / total
|
||||
score = 0.1 + 0.84 * fill_credit
|
||||
if empty > 0:
|
||||
score -= 0.22 * (empty / total)
|
||||
score -= 0.08 * len(off_topic_steps or [])
|
||||
score -= 0.03 * len(gaps or [])
|
||||
return max(0.08, min(0.98, round(score, 4)))
|
||||
|
||||
|
||||
def compute_roadmap_quality_score(
|
||||
*,
|
||||
llm_qa: Optional[Mapping[str, Any]] = None,
|
||||
llm_applied: bool = False,
|
||||
gaps: Optional[Sequence[Mapping[str, Any]]] = None,
|
||||
multistage_qa: Optional[Mapping[str, Any]] = None,
|
||||
) -> float:
|
||||
"""QS der Roadmap-/Stufenlogik — unabhängig von Slot-Befüllung."""
|
||||
if llm_applied and llm_qa and llm_qa.get("quality_score") is not None:
|
||||
try:
|
||||
return max(0.08, min(0.98, round(float(llm_qa["quality_score"]), 4)))
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
score = 0.9
|
||||
score -= 0.05 * len(gaps or [])
|
||||
hint_count = int((multistage_qa or {}).get("optimization_hint_count") or 0)
|
||||
score -= min(0.12, 0.015 * hint_count)
|
||||
return max(0.35, min(0.98, round(score, 4)))
|
||||
|
||||
|
||||
def build_assignment_qa_snapshot(
|
||||
*,
|
||||
steps: Optional[Sequence[Mapping[str, Any]]] = None,
|
||||
off_topic_steps: Optional[Sequence[Mapping[str, Any]]] = None,
|
||||
gaps: Optional[Sequence[Mapping[str, Any]]] = None,
|
||||
) -> Dict[str, Any]:
|
||||
off_topic = list(off_topic_steps or [])
|
||||
stats = count_step_assignment_stats(steps)
|
||||
score = compute_assignment_quality_score(
|
||||
steps=steps,
|
||||
off_topic_steps=off_topic,
|
||||
gaps=gaps,
|
||||
)
|
||||
issues: List[str] = []
|
||||
if stats["empty"] > 0:
|
||||
issues.append(
|
||||
f"{stats['empty']} von {stats['total']} Slot(s) ohne Übung — bitte Bibliothek oder KI-Vorschlag zuweisen",
|
||||
)
|
||||
if stats["ai_proposal"] > 0 and stats["library_filled"] == 0 and stats["empty"] > 0:
|
||||
issues.append(
|
||||
f"{stats['ai_proposal']} KI-Entwurf(e), aber noch {stats['empty']} leere Slot(s)",
|
||||
)
|
||||
for item in off_topic[:5]:
|
||||
title = (item.get("title") or "Schritt").strip()
|
||||
issues.append(f"„{title}“ passt nicht zum Stufen-Ziel")
|
||||
overall_ok = stats["empty"] == 0 and len(off_topic) == 0
|
||||
return {
|
||||
"overall_ok": overall_ok,
|
||||
"quality_score": score,
|
||||
"slot_count": stats["total"],
|
||||
"empty_slot_count": stats["empty"],
|
||||
"library_filled_count": stats["library_filled"],
|
||||
"ai_proposal_count": stats["ai_proposal"],
|
||||
"issues": issues,
|
||||
}
|
||||
|
||||
|
||||
def build_roadmap_qa_snapshot(
|
||||
*,
|
||||
llm_qa: Optional[Mapping[str, Any]] = None,
|
||||
llm_applied: bool = False,
|
||||
gaps: Optional[Sequence[Mapping[str, Any]]] = None,
|
||||
multistage_qa: Optional[Mapping[str, Any]] = None,
|
||||
roadmap_qa_mode: Optional[str] = None,
|
||||
) -> Dict[str, Any]:
|
||||
score = compute_roadmap_quality_score(
|
||||
llm_qa=llm_qa,
|
||||
llm_applied=llm_applied,
|
||||
gaps=gaps,
|
||||
multistage_qa=multistage_qa,
|
||||
)
|
||||
issues: List[str] = []
|
||||
if not llm_applied:
|
||||
for gap in gaps or []:
|
||||
issues.append(
|
||||
f"Übergang „{gap.get('from_title')}“ → „{gap.get('to_title')}“ schwach (Score {gap.get('gap_score')})",
|
||||
)
|
||||
if llm_applied and llm_qa:
|
||||
issues.extend(str(x).strip() for x in (llm_qa.get("issues") or []) if str(x).strip())
|
||||
overall_ok = bool(llm_qa.get("overall_ok", True)) if llm_applied and llm_qa else len(gaps or []) == 0
|
||||
snapshot: Dict[str, Any] = {
|
||||
"overall_ok": overall_ok,
|
||||
"quality_score": score,
|
||||
"issues": issues[:8],
|
||||
"llm_applied": bool(llm_applied),
|
||||
"roadmap_qa_mode": roadmap_qa_mode,
|
||||
}
|
||||
if llm_applied and llm_qa:
|
||||
snapshot["topic_coverage"] = llm_qa.get("topic_coverage")
|
||||
snapshot["recommendations"] = list(llm_qa.get("recommendations") or [])
|
||||
snapshot["sequence_notes"] = list(llm_qa.get("sequence_notes") or [])
|
||||
return snapshot
|
||||
|
||||
|
||||
def merge_path_quality_scores(
|
||||
roadmap_qa: Mapping[str, Any],
|
||||
assignment_qa: Mapping[str, Any],
|
||||
) -> float:
|
||||
"""Gesamt-QS: schwächere Dimension begrenzt — leere Slots senken den Pfad deutlich."""
|
||||
try:
|
||||
roadmap_score = float(roadmap_qa.get("quality_score"))
|
||||
except (TypeError, ValueError):
|
||||
roadmap_score = None
|
||||
try:
|
||||
assignment_score = float(assignment_qa.get("quality_score"))
|
||||
except (TypeError, ValueError):
|
||||
assignment_score = None
|
||||
if roadmap_score is not None and assignment_score is not None:
|
||||
return round(min(roadmap_score, assignment_score), 4)
|
||||
if assignment_score is not None:
|
||||
return assignment_score
|
||||
if roadmap_score is not None:
|
||||
return roadmap_score
|
||||
return 0.5
|
||||
|
||||
|
||||
def build_path_qa_summary(
|
||||
*,
|
||||
gaps: Sequence[Mapping[str, Any]],
|
||||
@@ -702,6 +856,7 @@ def build_path_qa_summary(
|
||||
reorder_notes: Optional[Sequence[str]] = None,
|
||||
roadmap_qa_mode: Optional[str] = None,
|
||||
multistage_qa: Optional[Mapping[str, Any]] = None,
|
||||
steps: Optional[Sequence[Mapping[str, Any]]] = None,
|
||||
) -> Dict[str, Any]:
|
||||
offers = list(gap_fill_offers or [])
|
||||
off_topic = list(off_topic_steps or [])
|
||||
@@ -726,31 +881,32 @@ def build_path_qa_summary(
|
||||
summary["qa_tiers"] = list(multistage_qa.get("qa_tiers") or [])
|
||||
summary["optimization_hints"] = list(multistage_qa.get("optimization_hints") or [])
|
||||
summary["optimization_hint_count"] = int(multistage_qa.get("optimization_hint_count") or 0)
|
||||
|
||||
assignment_qa = build_assignment_qa_snapshot(
|
||||
steps=steps,
|
||||
off_topic_steps=off_topic,
|
||||
gaps=gaps,
|
||||
)
|
||||
roadmap_qa = build_roadmap_qa_snapshot(
|
||||
llm_qa=llm_qa,
|
||||
llm_applied=llm_applied,
|
||||
gaps=gaps,
|
||||
multistage_qa=multistage_qa,
|
||||
roadmap_qa_mode=roadmap_qa_mode,
|
||||
)
|
||||
summary["assignment_qa"] = assignment_qa
|
||||
summary["roadmap_qa"] = roadmap_qa
|
||||
summary["quality_score"] = merge_path_quality_scores(roadmap_qa, assignment_qa)
|
||||
summary["overall_ok"] = bool(
|
||||
assignment_qa.get("overall_ok")
|
||||
and roadmap_qa.get("overall_ok", True),
|
||||
)
|
||||
summary["topic_coverage"] = roadmap_qa.get("topic_coverage")
|
||||
summary["recommendations"] = list(roadmap_qa.get("recommendations") or [])
|
||||
summary["sequence_notes"] = list(roadmap_qa.get("sequence_notes") or [])
|
||||
summary["issues"] = list(assignment_qa.get("issues") or []) + list(roadmap_qa.get("issues") or [])[:6]
|
||||
if llm_qa:
|
||||
summary["overall_ok"] = bool(llm_qa.get("overall_ok", True))
|
||||
summary["quality_score"] = llm_qa.get("quality_score")
|
||||
summary["issues"] = list(llm_qa.get("issues") or [])
|
||||
summary["sequence_notes"] = list(llm_qa.get("sequence_notes") or [])
|
||||
summary["topic_coverage"] = llm_qa.get("topic_coverage")
|
||||
summary["recommendations"] = list(llm_qa.get("recommendations") or [])
|
||||
summary["suggested_new_exercises"] = list(llm_qa.get("suggested_new_exercises") or [])
|
||||
else:
|
||||
summary["overall_ok"] = len(gaps) == 0 and len(off_topic) == 0
|
||||
summary["issues"] = [
|
||||
f"Lücke zwischen „{g.get('from_title')}“ und „{g.get('to_title')}“ (Score {g.get('gap_score')})"
|
||||
for g in gaps
|
||||
] if gaps else []
|
||||
if off_topic:
|
||||
summary["issues"] = list(summary["issues"]) + [
|
||||
f"Schritt „{o.get('title')}“ passt nicht zum Pfad-Thema"
|
||||
for o in off_topic
|
||||
]
|
||||
summary["quality_score"] = compute_deterministic_path_quality_score(
|
||||
gaps=gaps,
|
||||
off_topic_steps=off_topic,
|
||||
steps=steps,
|
||||
multistage_qa=multistage_qa,
|
||||
)
|
||||
return summary
|
||||
|
||||
|
||||
@@ -761,31 +917,34 @@ def compute_deterministic_path_quality_score(
|
||||
steps: Optional[Sequence[Mapping[str, Any]]] = None,
|
||||
multistage_qa: Optional[Mapping[str, Any]] = None,
|
||||
) -> float:
|
||||
"""Heuristische Pfad-QS ohne LLM — Basis für Slot-Vergleiche."""
|
||||
score = 0.92
|
||||
score -= 0.08 * len(off_topic_steps or [])
|
||||
score -= 0.05 * len(gaps or [])
|
||||
if steps:
|
||||
empty = sum(
|
||||
1
|
||||
for s in steps
|
||||
if isinstance(s, dict)
|
||||
and s.get("exercise_id") is None
|
||||
and not s.get("is_ai_proposal")
|
||||
)
|
||||
score -= 0.06 * empty
|
||||
hint_count = int((multistage_qa or {}).get("optimization_hint_count") or 0)
|
||||
score -= min(0.14, 0.02 * hint_count)
|
||||
return max(0.35, min(0.98, round(score, 4)))
|
||||
"""Heuristische Pfad-QS ohne LLM — Roadmap + Besetzung kombiniert."""
|
||||
roadmap_qa = build_roadmap_qa_snapshot(
|
||||
llm_qa=None,
|
||||
llm_applied=False,
|
||||
gaps=gaps,
|
||||
multistage_qa=multistage_qa,
|
||||
)
|
||||
assignment_qa = build_assignment_qa_snapshot(
|
||||
steps=steps,
|
||||
off_topic_steps=off_topic_steps,
|
||||
gaps=gaps,
|
||||
)
|
||||
return merge_path_quality_scores(roadmap_qa, assignment_qa)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"apply_llm_path_reorder",
|
||||
"build_assignment_qa_snapshot",
|
||||
"build_path_qa_summary",
|
||||
"build_roadmap_qa_snapshot",
|
||||
"compute_assignment_quality_score",
|
||||
"compute_deterministic_path_quality_score",
|
||||
"compute_roadmap_quality_score",
|
||||
"count_step_assignment_stats",
|
||||
"detect_off_topic_steps",
|
||||
"detect_path_gaps",
|
||||
"is_roadmap_planned_neighbor_pair",
|
||||
"merge_path_quality_scores",
|
||||
"strip_off_topic_steps_from_path",
|
||||
"find_step_pair_index",
|
||||
"insert_bridge_exercises",
|
||||
|
||||
Reference in new issue
Block a user