-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared_state.py
More file actions
54 lines (48 loc) · 1.31 KB
/
shared_state.py
File metadata and controls
54 lines (48 loc) · 1.31 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
import json
from pathlib import Path
from datetime import datetime
DATA_FILE = Path("shared_questions.json")
HISTORY_FILE = Path("student_history.json")
def save_questions(questions):
"""Teacher saves generated questions"""
try:
with open(DATA_FILE, 'w') as f:
json.dump({
'questions': questions,
'timestamp': datetime.now().isoformat()
}, f)
return True
except:
return False
def load_questions():
"""Student loads questions"""
if DATA_FILE.exists():
try:
with open(DATA_FILE, 'r') as f:
data = json.load(f)
return data.get('questions', [])
except:
pass
return []
def save_student_result(result):
"""Save student assessment result"""
history = load_student_history()
history.append(result)
try:
with open(HISTORY_FILE, 'w') as f:
json.dump(history, f)
except:
pass
def load_student_history():
"""Load all student results"""
if HISTORY_FILE.exists():
try:
with open(HISTORY_FILE, 'r') as f:
return json.load(f)
except:
pass
return []
def clear_questions():
"""Clear current assessment"""
if DATA_FILE.exists():
DATA_FILE.unlink()