from datetime import datetime from .. import db class Assessment(db.Model): """Stores every stress prediction result for a user.""" __tablename__ = "assessments" id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey("users.id"), nullable=False) created_at = db.Column(db.DateTime, default=datetime.utcnow, index=True) # ── Input data ────────────────────────────────────────────────────────── # Psychometric features (stored as JSON blob for flexibility) psychometric_data = db.Column(db.JSON, nullable=True) # Raw text note text_note = db.Column(db.Text, nullable=True) # ── Prediction results ────────────────────────────────────────────────── psycho_label = db.Column(db.String(16), nullable=True) # High / Medium / Low psycho_score = db.Column(db.Float, nullable=True) text_label = db.Column(db.String(32), nullable=True) # e.g. Anxiety text_score = db.Column(db.Float, nullable=True) fused_label = db.Column(db.String(16), nullable=True) # Minimal..Critical fused_score = db.Column(db.Float, nullable=True) # Which modalities were used modality_used = db.Column(db.String(32), nullable=True) # both / psycho / text def to_dict(self): return { "id": self.id, "user_id": self.user_id, "created_at": self.created_at.isoformat(), "psychometric_data": self.psychometric_data, "text_note": self.text_note, "psycho_label": self.psycho_label, "psycho_score": self.psycho_score, "text_label": self.text_label, "text_score": self.text_score, "fused_label": self.fused_label, "fused_score": self.fused_score, "modality_used": self.modality_used, }