Enhance Skill Scoring and Profile Features
Deploy Development / deploy (push) Successful in 39s
Test Suite / pytest-backend (push) Successful in 42s
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 1m15s

- Updated the skill scoring specification to include club-specific metrics and improved aggregation methods for skill profiles.
- Introduced new API endpoints for batch skill profile summaries, allowing for efficient retrieval of compact skill data.
- Enhanced frontend components to display skill profiles with club comparisons, improving user interaction and visibility of skill strengths.
- Added filtering options for skills in the framework programs, enabling users to refine selections based on training weight relative to club maximums.
- Improved CSS styles for skill profile displays, ensuring a cohesive and user-friendly interface across the application.
This commit is contained in:
Lars committed 2026-05-21 09:05:13 +02:00
1 parent 5200895a73
commit 78c6c51520
15 files changed
+1131 -141

No files matched your search

+172 -28
View File
@@ -17,10 +17,13 @@ from skill_scoring import (
collect_module_exercise_occurrences,
collect_progression_graph_exercise_occurrences,
collect_unit_exercise_occurrences,
compute_club_corpus_reference,
compute_corpus_skill_max_weights,
compute_skill_profile,
match_score_for_skill_ids,
profile_for_occurrences,
reference_scale_meta,
top_categories_summary,
)
from routers.training_framework_programs import _framework_access
@@ -70,12 +73,9 @@ def framework_program_skill_profile(
)
slots_raw = [r2d(r) for r in cur.fetchall()]
ref_max = compute_corpus_skill_max_weights(
cur,
profile_id=profile_id,
role=role,
effective_club_id=tenant.effective_club_id,
)
corpus = _load_club_corpus(cur, tenant)
ref_max = corpus["max_by_skill"]
ref_by_skill = corpus["ref_by_skill"]
all_occurrences: List[ExerciseOccurrence] = []
slot_profiles: List[Dict[str, Any]] = []
@@ -118,14 +118,22 @@ def framework_program_skill_profile(
if all_occurrences
else _empty_profile()
)
_enrich_profile_club_best(overall, ref_by_skill, "framework_program", framework_id)
for slot in slot_profiles:
_enrich_profile_club_best(
slot.get("profile") or {},
ref_by_skill,
"framework_program",
framework_id,
)
return {
"artifact_type": "framework_program",
"artifact_id": framework_id,
"artifact_title": row.get("title"),
"reference_scale": {
"skills_in_corpus": len(ref_max),
"description": "universal_percent = Anteil am höchsten Trainingsgewicht dieser Fähigkeit in der sichtbaren Bibliothek",
"reference_scale": reference_scale_meta(corpus),
"club_best_by_skill": {
str(k): v for k, v in ref_by_skill.items()
},
"overall": overall,
"slots": slot_profiles,
@@ -142,24 +150,23 @@ def training_module_skill_profile(
with get_db() as conn:
cur = get_cursor(conn)
row = _module_access(cur, module_id, profile_id, role)
ref_max = compute_corpus_skill_max_weights(
cur,
profile_id=profile_id,
role=role,
effective_club_id=tenant.effective_club_id,
)
corpus = _load_club_corpus(cur, tenant)
ref_max = corpus["max_by_skill"]
ref_by_skill = corpus["ref_by_skill"]
occurrences = collect_module_exercise_occurrences(cur, module_id)
overall = (
profile_for_occurrences(cur, occurrences, reference_max_by_skill=ref_max)
if occurrences
else _empty_profile()
)
_enrich_profile_club_best(overall, ref_by_skill, "training_module", module_id)
return {
"artifact_type": "training_module",
"artifact_id": module_id,
"artifact_title": row.get("title"),
"reference_scale": {
"skills_in_corpus": len(ref_max),
"reference_scale": reference_scale_meta(corpus),
"club_best_by_skill": {
str(k): v for k, v in ref_by_skill.items()
},
"overall": overall,
}
@@ -175,12 +182,9 @@ def progression_graph_skill_profile(
with get_db() as conn:
cur = get_cursor(conn)
row = _require_graph_read(cur, graph_id, profile_id, role)
ref_max = compute_corpus_skill_max_weights(
cur,
profile_id=profile_id,
role=role,
effective_club_id=tenant.effective_club_id,
)
corpus = _load_club_corpus(cur, tenant)
ref_max = corpus["max_by_skill"]
ref_by_skill = corpus["ref_by_skill"]
occurrences = collect_progression_graph_exercise_occurrences(cur, graph_id)
overall = (
profile_for_occurrences(
@@ -192,17 +196,96 @@ def progression_graph_skill_profile(
if occurrences
else _empty_profile()
)
_enrich_profile_club_best(overall, ref_by_skill, "progression_graph", graph_id)
return {
"artifact_type": "progression_graph",
"artifact_id": graph_id,
"artifact_title": row.get("name"),
"reference_scale": {
"skills_in_corpus": len(ref_max),
"reference_scale": reference_scale_meta(corpus),
"club_best_by_skill": {
str(k): v for k, v in ref_by_skill.items()
},
"overall": overall,
}
@router.post("/skill-profiles/batch-summaries")
def batch_skill_profile_summaries(
data: dict,
tenant: TenantContext = Depends(get_tenant_context),
):
"""
Kompakte Fähigkeiten-Profile für Listen (ein Corpus-Scan, Batch-SQL).
Body: { framework_program_ids?: number[], training_module_ids?: number[] }
"""
fp_ids = _parse_id_list(data.get("framework_program_ids"))
mod_ids = _parse_id_list(data.get("training_module_ids"))
if not fp_ids and not mod_ids:
raise HTTPException(
status_code=400,
detail="framework_program_ids oder training_module_ids erforderlich",
)
profile_id = tenant.profile_id
role = tenant.global_role
summaries: Dict[str, Dict[str, Any]] = {}
with get_db() as conn:
cur = get_cursor(conn)
corpus = compute_club_corpus_reference(
cur,
profile_id=tenant.profile_id,
effective_club_id=tenant.effective_club_id,
include_artifact_summaries=True,
)
ref_by_skill = corpus["ref_by_skill"]
all_summaries = corpus.get("artifact_summaries") or {}
if fp_ids:
allowed_fp = []
for fid in fp_ids:
try:
_framework_access(cur, fid, profile_id, role)
allowed_fp.append(fid)
except HTTPException:
pass
for fid in allowed_fp:
key = f"framework_program:{fid}"
if key in all_summaries:
summaries[key] = all_summaries[key]
if mod_ids:
allowed_mod = []
for mid in mod_ids:
try:
_module_access(cur, mid, profile_id, role)
allowed_mod.append(mid)
except HTTPException:
pass
for mid in allowed_mod:
key = f"training_module:{mid}"
if key in all_summaries:
summaries[key] = all_summaries[key]
skill_ids_seen: set[int] = set()
for summary in summaries.values():
for sk in summary.get("skills") or []:
if sk.get("skill_id") is not None:
skill_ids_seen.add(int(sk["skill_id"]))
club_best_subset = {
str(sid): ref_by_skill[sid]
for sid in skill_ids_seen
if sid in ref_by_skill
}
return {
"reference_scale": reference_scale_meta(corpus),
"club_best_by_skill": club_best_subset,
"summaries": summaries,
}
@router.get("/skill-discovery/suggestions")
def skill_discovery_suggestions(
skill_ids: str = Query(..., description="Komma-getrennte skill-IDs"),
@@ -278,7 +361,7 @@ def skill_discovery_suggestions(
"match": match,
"skill_profile_summary": {
"total_score": prof.get("total_score"),
"top_by_category": _top_categories_summary(prof),
"top_by_category": top_categories_summary(prof),
},
}
)
@@ -322,7 +405,7 @@ def skill_discovery_suggestions(
"match": match,
"skill_profile_summary": {
"total_score": prof.get("total_score"),
"top_by_category": _top_categories_summary(prof),
"top_by_category": top_categories_summary(prof),
},
}
)
@@ -368,7 +451,7 @@ def skill_discovery_suggestions(
"match": match,
"skill_profile_summary": {
"total_score": prof.get("total_score"),
"top_by_category": _top_categories_summary(prof),
"top_by_category": top_categories_summary(prof),
},
}
)
@@ -405,5 +488,66 @@ def _top_categories_summary(profile: Dict[str, Any], limit: int = 6) -> List[Dic
return out
def _parse_id_list(raw: Any, *, max_count: int = 120) -> List[int]:
if not raw:
return []
if not isinstance(raw, list):
raise HTTPException(status_code=400, detail="ID-Listen müssen Arrays sein")
out: List[int] = []
for item in raw:
try:
n = int(item)
except (TypeError, ValueError):
raise HTTPException(status_code=400, detail="Ungültige ID in Liste") from None
if n > 0 and n not in out:
out.append(n)
if len(out) >= max_count:
break
return out
def _load_club_corpus(cur, tenant: TenantContext) -> Dict[str, Any]:
return compute_club_corpus_reference(
cur,
profile_id=tenant.profile_id,
effective_club_id=tenant.effective_club_id,
)
def _enrich_profile_club_best(
profile: Dict[str, Any],
ref_by_skill: Dict[int, Dict[str, Any]],
artifact_type: Optional[str] = None,
artifact_id: Optional[int] = None,
) -> None:
"""Hängt Vereins-Referenz-Artefakt an Fähigkeiten an (wenn nicht selbst Spitze)."""
if not profile or not ref_by_skill:
return
def attach(sk: Optional[Dict[str, Any]]) -> None:
if not sk or sk.get("skill_id") is None:
return
sid = int(sk["skill_id"])
ref = ref_by_skill.get(sid)
if not ref:
return
if (
artifact_type
and artifact_id is not None
and ref.get("artifact_type") == artifact_type
and int(ref.get("artifact_id") or 0) == int(artifact_id)
):
return
w = float(sk.get("weight") or 0)
if w < float(ref.get("weight") or 0) - 0.01:
sk["club_best"] = ref
for sk in profile.get("skills") or []:
attach(sk)
for mc in profile.get("by_main_category") or []:
for cat in mc.get("categories") or []:
attach(cat.get("top_skill"))
def _empty_profile() -> Dict[str, Any]:
return compute_skill_profile([], {})