forked from johnny603/lux
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlearning_paths.py
More file actions
42 lines (38 loc) · 1.32 KB
/
Copy pathlearning_paths.py
File metadata and controls
42 lines (38 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from __future__ import annotations
from typing import Dict, List, Optional
def build_learning_path(state: Dict, levels: Optional[List[Dict]] = None, limit: int = 5) -> Dict:
levels = levels or []
solved = set(state.get("solved", {}).keys())
unsolved = [lvl for lvl in levels if str(lvl.get("id")) not in solved]
if not unsolved:
return {
"summary": "You have completed the available puzzles.",
"recommended_levels": [],
"limit": limit,
}
ordered = sorted(
unsolved,
key=lambda lvl: (
(lvl.get("difficulty") or "").lower() != "easy",
(lvl.get("difficulty") or "").lower() not in {"easy", "medium"},
(lvl.get("category") or "").lower(),
(lvl.get("title") or "").lower(),
),
)
recommended = ordered[: max(1, int(limit))]
summary = (
f"Focus on {len(recommended)} next steps that balance difficulty and your recent progress."
)
return {
"summary": summary,
"recommended_levels": [
{
"id": lvl.get("id"),
"title": lvl.get("title"),
"category": lvl.get("category"),
"difficulty": lvl.get("difficulty"),
}
for lvl in recommended
],
"limit": limit,
}