forked from roboticspro1/DeepLearningWeek-ByteMe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
88 lines (77 loc) · 3.24 KB
/
Copy pathutils.py
File metadata and controls
88 lines (77 loc) · 3.24 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
import pandas as pd
from openai import OpenAI
def load_data(filepath="data.csv"):
df = pd.read_csv(filepath)
df["timestamp"] = pd.to_datetime(df["timestamp"])
return df
def analyze_student_state(df):
"""Analyzes all data and returns a contradiction-free diagnostic profile per topic."""
topics_analysis = []
for topic in df["topic"].unique():
tdf = df[df["topic"] == topic].sort_values("timestamp")
# 1. Base Metrics
overall_accuracy = tdf["correct"].mean()
avg_time = tdf["time_taken"].mean()
# 2. Trend & Decay Detection (Split history in half)
mid = max(1, len(tdf) // 2)
past_acc = tdf.iloc[:mid]["correct"].mean()
recent_acc = tdf.iloc[mid:]["correct"].mean()
# 3. CONTRADICTION-FREE DIAGNOSTIC LOGIC
# If they used to know it, but recently failed -> Active Decay
if past_acc - recent_acc > 0.20:
diagnosis = "Active Decay (Forgetting)"
urgency = 95
color = "#ff4b4b" # Red
# If they are fast but wrong -> Careless/Fatigue
elif overall_accuracy < 0.5 and avg_time < 40:
diagnosis = "Careless Errors / Fatigue"
urgency = 80
color = "#ffb74d" # Orange
# If they are slow and wrong -> Conceptual Gap
elif overall_accuracy < 0.5 and avg_time >= 40:
diagnosis = "Deep Conceptual Gap"
urgency = 90
color = "#ff4b4b" # Red
# If they are right, but taking way too long -> Translation/Execution Bottleneck
elif overall_accuracy >= 0.5 and avg_time > 120:
diagnosis = "High Cognitive Load (Slow Execution)"
urgency = 60
color = "#4dabf5" # Blue
# Normal, good state
else:
diagnosis = "Retained Mastery"
urgency = 10
color = "#4caf50" # Green
topics_analysis.append({
"Topic": topic,
"Mastery (%)": overall_accuracy * 100,
"Recent Mastery (%)": recent_acc * 100,
"Avg Time (s)": avg_time,
"Diagnosis": diagnosis,
"Urgency": urgency,
"Color": color
})
# Sort by urgency so the most critical items are always first
return sorted(topics_analysis, key=lambda x: x["Urgency"], reverse=True)
def generate_micro_task(api_key, topic, diagnosis):
if not api_key:
return "⚠️ Enter API Key in the sidebar to generate a micro-task."
prompt = f"""
The student is studying '{topic}'.
Their diagnostic system flagged them with: '{diagnosis}'.
Do NOT give generic advice. Give them a single, highly specific 5-minute 'Micro-Task' to unblock them immediately.
Format as:
**Action:** [One sentence what to do]
**Why:** [One sentence why this fixes their specific {diagnosis} issue]
"""
try:
client = OpenAI(api_key=api_key)
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": prompt}],
temperature=0.7,
max_tokens=150
)
return response.choices[0].message.content
except Exception as e:
return "Error reaching AI."