-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
55 lines (42 loc) · 2.22 KB
/
models.py
File metadata and controls
55 lines (42 loc) · 2.22 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
from sqlalchemy import Column, Integer, String, Float, Text, DateTime, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
from datetime import datetime
Base = declarative_base()
LEVEL_LABELS = {
1: "Very Easy — Grade 3",
2: "Easy — Grade 5",
3: "Normal — Grade 7",
4: "Advanced — Grade 9",
5: "Complex — Clinical",
}
class Patient(Base):
__tablename__ = "patients"
id = Column(Integer, primary_key=True, index=True)
name = Column(String(100), nullable=False)
created_at = Column(DateTime, default=datetime.utcnow)
sessions = relationship("Session", back_populates="patient", cascade="all, delete")
flagged_words = relationship("FlaggedWord", back_populates="patient", cascade="all, delete")
class Session(Base):
__tablename__ = "sessions"
id = Column(Integer, primary_key=True, index=True)
patient_id = Column(Integer, ForeignKey("patients.id"), nullable=False)
comprehension_score = Column(Integer, default=0) # 0-100
read_time_seconds = Column(Integer, default=0)
self_understanding = Column(Integer, default=0) # 1-4
difficulty_level = Column(Integer, default=3) # 1-5
flagged_word_count = Column(Integer, default=0)
word_frequencies = Column(Text, default="{}") # JSON: word -> count
hover_times = Column(Text, default="{}") # JSON: word -> ms
created_at = Column(DateTime, default=datetime.utcnow)
patient = relationship("Patient", back_populates="sessions")
flagged_words = relationship("FlaggedWord", back_populates="session", cascade="all, delete")
class FlaggedWord(Base):
__tablename__ = "flagged_words"
id = Column(Integer, primary_key=True, index=True)
patient_id = Column(Integer, ForeignKey("patients.id"), nullable=False)
session_id = Column(Integer, ForeignKey("sessions.id"), nullable=False)
word = Column(String(100), nullable=False)
created_at = Column(DateTime, default=datetime.utcnow)
patient = relationship("Patient", back_populates="flagged_words")
session = relationship("Session", back_populates="flagged_words")