-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathule.py
More file actions
executable file
·287 lines (225 loc) · 11.3 KB
/
ule.py
File metadata and controls
executable file
·287 lines (225 loc) · 11.3 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#!/usr/bin/env python3
# 🧠 ULE Universal Launcher
# Universal Learning Engine - Adaptive learning for any subject
# Created by Ryan Rustill
import os
import sys
import subprocess
from typing import List, Dict, Optional
# Add the current directory to Python path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from engine.ui.terminal_ui import Colors
class SubjectDiscovery:
"""Automatically discovers available learning subjects"""
def __init__(self, subjects_dir: str = "subjects"):
self.subjects_dir = subjects_dir
self.available_subjects = self._discover_subjects()
def _discover_subjects(self) -> Dict[str, Dict[str, str]]:
"""Scan subjects directory and find available learning modules"""
subjects = {}
if not os.path.exists(self.subjects_dir):
return subjects
for item in os.listdir(self.subjects_dir):
subject_path = os.path.join(self.subjects_dir, item)
if os.path.isdir(subject_path):
# Look for the main launcher file
launcher_patterns = [
f"ule_{item}.py",
f"{item}_ule.py",
f"launcher.py",
f"main.py"
]
for pattern in launcher_patterns:
launcher_path = os.path.join(subject_path, pattern)
if os.path.exists(launcher_path):
subjects[item] = {
'name': item.title(),
'path': subject_path,
'launcher': pattern,
'description': self._get_subject_description(item)
}
break
return subjects
def _get_subject_description(self, subject: str) -> str:
"""Get a description for the subject"""
descriptions = {
'python': 'Master Python fundamentals through code analysis',
'javascript': 'Learn JavaScript concepts and syntax',
'math': 'Mathematical reasoning and problem solving',
'logic': 'Logical reasoning and critical thinking',
'java': 'Java programming fundamentals',
'c': 'C programming language basics'
}
return descriptions.get(subject.lower(), f'Learn {subject.title()} concepts')
class ULELauncher:
"""Universal ULE launcher with subject selection"""
def __init__(self):
self.discovery = SubjectDiscovery()
self.should_continue = True
def clear_screen(self):
os.system('cls' if os.name == 'nt' else 'clear')
def show_header(self):
print(f"\n{Colors.CYAN}{Colors.BOLD}{'='*70}")
print("🧠 UNIVERSAL LEARNING ENGINE (ULE)")
print("Adaptive learning for any subject")
print("Created by Ryan Rustill")
print(f"{'='*70}{Colors.END}\n")
def show_main_menu(self):
"""Display the main subject selection menu"""
self.clear_screen()
self.show_header()
print(f"{Colors.YELLOW}{Colors.BOLD}🎯 AVAILABLE LEARNING SUBJECTS:{Colors.END}\n")
subjects = list(self.discovery.available_subjects.items())
if not subjects:
print(f"{Colors.RED}No learning subjects found in the subjects/ directory.{Colors.END}")
print(f"{Colors.WHITE}Make sure you have properly configured subject modules.{Colors.END}\n")
return None
# Display subjects with numbers
for i, (key, info) in enumerate(subjects, 1):
print(f"{Colors.CYAN}{i}.{Colors.END} {Colors.WHITE}{Colors.BOLD}{info['name']}{Colors.END}")
print(f" {Colors.WHITE}{info['description']}{Colors.END}\n")
print(f"{Colors.YELLOW}R.{Colors.END} {Colors.WHITE}Reset All Progress{Colors.END}")
print(f"{Colors.RED}Q.{Colors.END} {Colors.WHITE}Quit ULE{Colors.END}\n")
# Get user choice
while True:
try:
choice = input(f"{Colors.BOLD}Select a learning subject (1-{len(subjects)}, R, or Q): {Colors.END}").strip().upper()
if choice == 'Q':
return 'quit'
elif choice == 'R':
return 'reset'
choice_num = int(choice)
if 1 <= choice_num <= len(subjects):
return subjects[choice_num - 1][0] # Return the subject key
else:
print(f"{Colors.RED}Please enter a number between 1 and {len(subjects)}, R, or Q.{Colors.END}")
except ValueError:
print(f"{Colors.RED}Please enter a valid number, R, or Q.{Colors.END}")
def launch_subject(self, subject_key: str) -> bool:
"""Launch a specific subject module"""
subject_info = self.discovery.available_subjects[subject_key]
print(f"\n{Colors.GREEN}Loading {subject_info['name']} learning module...{Colors.END}")
print(f"{Colors.WHITE}When you're done, you'll return to this main menu.{Colors.END}\n")
# Change to subject directory and run the launcher
original_dir = os.getcwd()
try:
subject_dir = subject_info['path']
launcher_file = subject_info['launcher']
os.chdir(subject_dir)
# Run the subject launcher
result = subprocess.run([sys.executable, launcher_file],
capture_output=False,
text=True)
return result.returncode == 0
except Exception as e:
print(f"{Colors.RED}Error launching {subject_info['name']}: {e}{Colors.END}")
return False
finally:
os.chdir(original_dir)
def reset_all_progress(self) -> bool:
"""Reset all learning progress across all subjects"""
self.clear_screen()
self.show_header()
print(f"{Colors.YELLOW}{Colors.BOLD}⚠️ RESET ALL PROGRESS{Colors.END}\n")
print(f"{Colors.WHITE}This will permanently delete ALL your learning progress across ALL subjects.{Colors.END}")
print(f"{Colors.WHITE}This includes:{Colors.END}")
print(f"{Colors.WHITE}• All difficulty levels and adaptations{Colors.END}")
print(f"{Colors.WHITE}• All concept mastery data{Colors.END}")
print(f"{Colors.WHITE}• All session statistics{Colors.END}")
print(f"{Colors.WHITE}• All answered question tracking{Colors.END}\n")
# Find all progress files
progress_files = self._find_progress_files()
if progress_files:
print(f"{Colors.CYAN}Found {len(progress_files)} progress file(s):{Colors.END}")
for file in progress_files:
print(f" • {file}")
print()
else:
print(f"{Colors.GREEN}No progress files found - you're already starting fresh!{Colors.END}")
input(f"{Colors.WHITE}Press Enter to return to main menu...{Colors.END}")
return False
# Double confirmation
print(f"{Colors.RED}{Colors.BOLD}THIS CANNOT BE UNDONE!{Colors.END}\n")
confirm1 = input(f"{Colors.BOLD}Are you sure you want to reset ALL progress? (yes/no): {Colors.END}").strip().lower()
if confirm1 != 'yes':
print(f"{Colors.GREEN}Reset cancelled. Your progress is safe!{Colors.END}")
input(f"{Colors.WHITE}Press Enter to return to main menu...{Colors.END}")
return False
confirm2 = input(f"{Colors.BOLD}Type 'DELETE' to confirm: {Colors.END}").strip()
if confirm2 != 'DELETE':
print(f"{Colors.GREEN}Reset cancelled. Your progress is safe!{Colors.END}")
input(f"{Colors.WHITE}Press Enter to return to main menu...{Colors.END}")
return False
# Delete progress files
deleted_count = 0
for file_path in progress_files:
try:
os.remove(file_path)
deleted_count += 1
except Exception as e:
print(f"{Colors.RED}Error deleting {file_path}: {e}{Colors.END}")
# Show results
print(f"\n{Colors.GREEN}{Colors.BOLD}✅ PROGRESS RESET COMPLETE!{Colors.END}")
print(f"{Colors.WHITE}Deleted {deleted_count} progress file(s).{Colors.END}")
print(f"{Colors.WHITE}You now have a completely fresh start across all subjects!{Colors.END}\n")
input(f"{Colors.CYAN}Press Enter to return to main menu...{Colors.END}")
return True
def _find_progress_files(self) -> List[str]:
"""Find all progress files in the current directory and subject directories"""
progress_files = []
# Check root directory for progress files
for file in os.listdir('.'):
if file.endswith('_progress.json') or file == 'progress.json':
progress_files.append(os.path.abspath(file))
# Check subject directories
if os.path.exists('subjects'):
for subject_dir in os.listdir('subjects'):
subject_path = os.path.join('subjects', subject_dir)
if os.path.isdir(subject_path):
for file in os.listdir(subject_path):
if file.endswith('_progress.json') or file == 'progress.json':
progress_files.append(os.path.abspath(os.path.join(subject_path, file)))
return progress_files
def show_return_prompt(self):
"""Show return to main menu prompt"""
print(f"\n{Colors.CYAN}{Colors.BOLD}🏠 RETURNING TO MAIN MENU{Colors.END}")
input(f"{Colors.WHITE}Press Enter to continue...{Colors.END}")
def show_goodbye(self):
"""Show goodbye message"""
self.clear_screen()
print(f"\n{Colors.CYAN}{Colors.BOLD}{'='*70}")
print("🌟 Thank you for using ULE!")
print("Keep learning, keep growing!")
print(f"{'='*70}{Colors.END}\n")
def run(self):
"""Main launcher loop"""
try:
while self.should_continue:
choice = self.show_main_menu()
if choice == 'quit' or choice is None:
self.should_continue = False
continue
elif choice == 'reset':
self.reset_all_progress()
continue
# Launch the selected subject
success = self.launch_subject(choice)
if success:
self.show_return_prompt()
else:
print(f"{Colors.RED}Failed to launch subject. Press Enter to return to menu...{Colors.END}")
input()
except KeyboardInterrupt:
print(f"\n{Colors.YELLOW}Learning session interrupted.{Colors.END}")
finally:
self.show_goodbye()
def main():
"""Entry point for ULE universal launcher"""
try:
launcher = ULELauncher()
launcher.run()
except Exception as e:
print(f"Error: {e}")
sys.exit(1)
if __name__ == "__main__":
main()