Implement Peer Learning Goals and Stage Fit Enhancements
Deploy Development / deploy (push) Successful in 42s
Test Suite / pytest-backend (push) Successful in 43s
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 1m33s

- Introduced `_peer_stage_learning_goals` to retrieve learning goals from peer stages, enhancing the ability to filter exercises based on cross-slot collisions.
- Added `_filter_learning_goal_candidate_ids` to refine candidate selection by incorporating peer learning goals and stage fit criteria, improving exercise relevance in suggestions.
- Enhanced `pick_best_path_hit` and `_match_roadmap_slot` to utilize peer learning goals for better exercise selection and to prevent conflicts with titles from other stages.
- Updated `stage_refinement_criteria_from_learning_goal` to provide clearer criteria for stage refinement based on learning goals.
- Bumped version to 0.8.229 to reflect the new features and improvements.
This commit is contained in:
Lars committed 2026-06-12 07:40:26 +02:00
1 parent a49987408b
commit 8a4be795f4
5 files changed
+241 -43

No files matched your search

+98 -11
View File
@@ -53,6 +53,8 @@ from planning_exercise_semantics import (
resolve_path_anti_patterns,
resolve_path_primary_topic,
exercise_passes_path_semantic_gate,
exercise_passes_stage_fit,
exercise_title_matches_peer_stage_goal,
pick_best_path_hit,
resolve_semantic_skill_weights,
step_phase_for_index,
@@ -201,6 +203,78 @@ def _roadmap_structured_from_body(body: ProgressionPathSuggestRequest) -> Option
)
def _peer_stage_learning_goals(
roadmap_ctx: ProgressionRoadmapContext,
*,
current_major_index: int,
) -> List[str]:
goals: List[str] = []
for spec in roadmap_ctx.stage_specs or []:
if int(spec.major_step_index) == int(current_major_index):
continue
lg = (spec.learning_goal or "").strip()
if lg and lg not in goals:
goals.append(lg)
return goals
def _filter_learning_goal_candidate_ids(
cur,
*,
tenant: TenantContext,
progression_graph_id: Optional[int],
candidate_ids: Sequence[int],
stage_goal: str,
stage_match_brief: PlanningSemanticBrief,
stage_anti: Optional[List[str]],
path_primary: str,
path_tech_excludes: Optional[List[str]],
peer_learning_goals: Sequence[str],
) -> List[int]:
"""Learning-Goal-Kandidaten nur, wenn sie Stufen-Gate und Peer-Check bestehen."""
if not candidate_ids:
return []
vis_sql, vis_params = _planning_visibility_sql(cur, tenant, progression_graph_id)
rows = _load_supplemental_exercise_rows(
cur,
tenant=tenant,
progression_graph_id=progression_graph_id,
exercise_ids=list(candidate_ids),
vis_sql=vis_sql,
vis_params=vis_params,
)
out: List[int] = []
for row in rows:
try:
eid = int(row.get("id") or 0)
except (TypeError, ValueError):
continue
if eid <= 0:
continue
title = str(row.get("title") or "")
if peer_learning_goals and exercise_title_matches_peer_stage_goal(
title,
current_learning_goal=stage_goal,
peer_learning_goals=peer_learning_goals,
):
continue
summary = str(row.get("summary") or "")
goal_text = str(row.get("goal") or row.get("exercise_goal") or "")
if exercise_passes_stage_fit(
learning_goal=stage_goal,
title=title,
summary=summary,
goal=goal_text,
stage_brief=stage_match_brief,
anti_patterns=stage_anti,
path_primary_topic=path_primary or None,
path_technique_excludes=path_tech_excludes,
relaxed=True,
):
out.append(eid)
return out
def _pick_best_path_hit(
hits: List[Dict[str, Any]],
used_exercise_ids: Set[int],
@@ -212,6 +286,7 @@ def _pick_best_path_hit(
stage_match_brief: Optional[PlanningSemanticBrief] = None,
path_primary_topic: Optional[str] = None,
path_technique_excludes: Optional[List[str]] = None,
peer_learning_goals: Optional[List[str]] = None,
) -> Optional[Dict[str, Any]]:
return pick_best_path_hit(
hits,
@@ -223,6 +298,7 @@ def _pick_best_path_hit(
stage_match_brief=stage_match_brief,
path_primary_topic=path_primary_topic,
path_technique_excludes=path_technique_excludes,
peer_learning_goals=peer_learning_goals,
)
@@ -366,13 +442,12 @@ def _fetch_learning_goal_library_candidate_ids(
learning_goal: str,
limit: int = 24,
) -> List[int]:
"""Sichtbare Übungen, deren Titel/Volltext zum Stufen-Lernziel passt."""
"""Sichtbare Übungen mit exakt passendem Titel oder Volltext-Treffer (kein breites LIKE)."""
lg = (learning_goal or "").strip()
if len(lg) < 3:
return []
vis_sql, vis_params = _planning_visibility_sql(cur, tenant, progression_graph_id)
tsq = _safe_tsquery_fragment(lg)
like_pat = f"%{lg[:100].lower()}%"
try:
cur.execute(
f"""
@@ -382,7 +457,6 @@ def _fetch_learning_goal_library_candidate_ids(
AND COALESCE(e.status, '') <> %s
AND (
lower(trim(e.title)) = lower(trim(%s))
OR lower(e.title) LIKE %s
OR (%s <> '' AND e.search_vector @@ plainto_tsquery('german', %s))
)
ORDER BY
@@ -395,7 +469,6 @@ def _fetch_learning_goal_library_candidate_ids(
*vis_params,
"archived",
lg,
like_pat,
tsq,
tsq,
lg,
@@ -411,14 +484,11 @@ def _fetch_learning_goal_library_candidate_ids(
FROM exercises e
WHERE ({vis_sql})
AND COALESCE(e.status, '') <> %s
AND (
lower(trim(e.title)) = lower(trim(%s))
OR lower(e.title) LIKE %s
)
ORDER BY CASE WHEN lower(trim(e.title)) = lower(trim(%s)) THEN 0 ELSE 1 END, e.id ASC
AND lower(trim(e.title)) = lower(trim(%s))
ORDER BY e.id ASC
LIMIT %s
""",
[*vis_params, "archived", lg, like_pat, lg, int(limit)],
[*vis_params, "archived", lg, int(limit)],
)
out: List[int] = []
for row in cur.fetchall() or []:
@@ -1092,14 +1162,30 @@ def _match_roadmap_slot(
major_step=major,
)
step_kind = resolve_step_exercise_kind_filter(stage_spec, body.exercise_kind_any)
peer_goals = _peer_stage_learning_goals(
roadmap_ctx,
current_major_index=int(stage_spec.major_step_index),
)
supplemental_ids = _supplemental_exercise_ids_from_body(cur, body)
lg_candidates = _fetch_learning_goal_library_candidate_ids(
lg_candidates_raw = _fetch_learning_goal_library_candidate_ids(
cur,
tenant=tenant,
progression_graph_id=body.progression_graph_id,
learning_goal=stage_goal,
)
lg_candidates = _filter_learning_goal_candidate_ids(
cur,
tenant=tenant,
progression_graph_id=body.progression_graph_id,
candidate_ids=lg_candidates_raw,
stage_goal=stage_goal,
stage_match_brief=stage_match_brief,
stage_anti=stage_anti,
path_primary=path_primary,
path_tech_excludes=path_tech_excludes,
peer_learning_goals=peer_goals,
)
supplemental_ids = list(
dict.fromkeys(
int(x)
@@ -1163,6 +1249,7 @@ def _match_roadmap_slot(
stage_match_brief=stage_match_brief,
path_primary_topic=path_primary or None,
path_technique_excludes=path_tech_excludes or None,
peer_learning_goals=peer_goals,
)
if not hit: