File size: 2,508 Bytes
e4e1bf1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
import os

class MemoryManager:
    def __init__(self, file_path="memory/student_state.json"):
        self.file_path = file_path
        self.state = self._load_state()

    def _load_state(self):
        if os.path.exists(self.file_path):
            with open(self.file_path, 'r') as f:
                try:
                    return json.load(f)
                except:
                    pass
        return {
            "current_topic": "Contract Law",
            "weak_areas": [],
            "strong_areas": [],
            "history": [],
            "accuracy": {},
            "attempts": {},
            "last_result": None
        }

    def save_state(self):
        with open(self.file_path, 'w') as f:
            json.dump(self.state, f, indent=4)

    def update_performance(self, topic, is_correct):
        # Update last result for planner
        self.state["last_result"] = "correct" if is_correct else "incorrect"
        
        # Update attempts
        self.state["attempts"][topic] = self.state["attempts"].get(topic, 0) + 1
        
        # Data-driven accuracy update
        acc = self.state["accuracy"].get(topic, 0.5)
        if is_correct:
            acc += 0.1
        else:
            acc -= 0.1
        self.state["accuracy"][topic] = max(0.0, min(1.0, acc))

        # Evolution logic
        acc_val = self.state["accuracy"][topic]
        if acc_val > 0.8:
            if topic in self.state["weak_areas"]: self.state["weak_areas"].remove(topic)
            if topic not in self.state["strong_areas"]: self.state["strong_areas"].append(topic)
        elif acc_val < 0.4:
            if topic in self.state["strong_areas"]: self.state["strong_areas"].remove(topic)
            if topic not in self.state["weak_areas"]: self.state["weak_areas"].append(topic)

        self.save_state()

    def add_history(self, entry):
        self.state["history"].append(entry)
        if len(self.state["history"]) > 50: # Cap history
            self.state["history"] = self.state["history"][-50:]
        self.save_state()

    def get_state(self):
        return self.state

    def get_dashboard_data(self):
        return {
            "weak_areas": self.state["weak_areas"],
            "strong_areas": self.state["strong_areas"],
            "accuracy": self.state["accuracy"],
            "current_topic": self.state["current_topic"]
        }

    def set_current_topic(self, topic):
        self.state["current_topic"] = topic
        self.save_state()