cryogenic22 commited on
Commit
284a75b
·
verified ·
1 Parent(s): e205871

Create components/learning_paths.py

Browse files
Files changed (1) hide show
  1. src/components/learning_paths.py +89 -0
src/components/learning_paths.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datetime import datetime
2
+ from typing import Dict, List, Optional
3
+ import streamlit as st
4
+ from src.services.learning_service import LearningService
5
+ from src.utils.session import get_user_progress
6
+
7
+ class LearningPaths:
8
+ def __init__(self):
9
+ self.service = LearningService()
10
+
11
+ @staticmethod
12
+ def display():
13
+ paths = LearningPaths()
14
+ paths.display_interface()
15
+
16
+ def display_interface(self):
17
+ """Display the learning paths interface"""
18
+ st.header("Learning Paths")
19
+
20
+ # Path selection
21
+ selected_path = st.selectbox(
22
+ "Select Learning Path",
23
+ options=list(self.service.curriculum.keys()),
24
+ format_func=lambda x: self.service.curriculum[x]['name'],
25
+ key="path_selector"
26
+ )
27
+
28
+ # Display selected path details
29
+ if selected_path:
30
+ self.display_path_details(selected_path)
31
+
32
+ def display_path_details(self, path_id: str):
33
+ """Display detailed view of a learning path"""
34
+ path = self.service.curriculum[path_id]
35
+
36
+ # Path header and description
37
+ st.subheader(path['name'])
38
+ st.write(path['description'])
39
+
40
+ # Prerequisites check
41
+ if path['prerequisites']:
42
+ prereq_met = self.service.check_prerequisites(path['prerequisites'])
43
+ if not prereq_met:
44
+ st.warning("⚠️ Please complete the prerequisite paths first: " +
45
+ ", ".join([self.service.curriculum[p]['name'] for p in path['prerequisites']]))
46
+ return
47
+
48
+ # Progress overview
49
+ total_modules = len(path['modules'])
50
+ progress = self.service.get_path_progress(path_id)
51
+ st.progress(progress,
52
+ f"Progress: {int(progress * total_modules)}/{total_modules} modules completed")
53
+
54
+ # Display modules
55
+ for module in path['modules']:
56
+ self.display_module(module, path_id)
57
+
58
+ def display_module(self, module: Dict, path_id: str):
59
+ """Display individual module with its details and status"""
60
+ completed = self.service.is_module_completed(module['id'])
61
+
62
+ with st.expander(
63
+ f"{'✅' if completed else '📝'} {module['name']} "
64
+ f"({module['difficulty']} • {module['estimated_hours']}h)",
65
+ expanded=not completed
66
+ ):
67
+ # Module description and concepts
68
+ st.write("**Key Concepts:**")
69
+ for concept in module['concepts']:
70
+ mastery = self.service.get_concept_mastery(concept)
71
+ st.write(f"- {concept.replace('_', ' ').title()}: {self.service.format_mastery(mastery)}")
72
+
73
+ # Module actions
74
+ cols = st.columns([1, 1, 1])
75
+
76
+ with cols[0]:
77
+ if st.button("Start Learning", key=f"start_{module['id']}", disabled=completed):
78
+ self.service.start_module(module['id'], path_id)
79
+ st.rerun()
80
+
81
+ with cols[1]:
82
+ if st.button("Take Quiz", key=f"quiz_{module['id']}"):
83
+ self.service.launch_quiz(module['id'])
84
+ st.rerun()
85
+
86
+ with cols[2]:
87
+ if st.button("Mark Complete", key=f"complete_{module['id']}", disabled=completed):
88
+ self.service.complete_module(module['id'], path_id)
89
+ st.rerun()