olivas/backend/app/models/analysis.py
DJP 92062b254d Add score clarity, AI design score, image format fix, cost tracking
- Replace bare score badge with rich ScoreCard component showing
  color-coded score (green/amber/red), label, and hover tooltip
  explaining what the 0-100 Attention Focus score means
- Add AI Design Effectiveness Score (1-10) from Claude alongside
  qualitative insights, with score_reason explanation
- Fix image/png media type error by converting all images to PNG
  before sending to Claude API
- Save ai_score and ai_score_reason to DB
- Display AI score badge in InsightsPanel with color coding

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 20:37:03 -05:00

41 lines
1.8 KiB
Python

import uuid
from datetime import datetime
from sqlalchemy import Float, ForeignKey, Integer, JSON, String, func
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.models.base import Base
class Analysis(Base):
__tablename__ = "analyses"
id: Mapped[str] = mapped_column(
String(36), primary_key=True, default=lambda: str(uuid.uuid4())
)
project_id: Mapped[str] = mapped_column(ForeignKey("projects.id"), index=True)
user_id: Mapped[str] = mapped_column(String(36), index=True)
name: Mapped[str] = mapped_column(String(255))
model_used: Mapped[str] = mapped_column(String(50), default="deepgaze_iie")
status: Mapped[str] = mapped_column(String(20), default="pending")
original_filename: Mapped[str] = mapped_column(String(255))
image_width: Mapped[int] = mapped_column(Integer)
image_height: Mapped[int] = mapped_column(Integer)
file_format: Mapped[str] = mapped_column(String(10))
storage_path: Mapped[str] = mapped_column(String(512))
gaze_sequence: Mapped[dict | None] = mapped_column(JSON, nullable=True)
hotspots: Mapped[dict | None] = mapped_column(JSON, nullable=True)
overall_score: Mapped[float | None] = mapped_column(Float, nullable=True)
ai_insights: Mapped[dict | None] = mapped_column(JSON, nullable=True)
ai_score: Mapped[int | None] = mapped_column(Integer, nullable=True)
ai_score_reason: Mapped[str | None] = mapped_column(String(500), nullable=True)
ai_cost_usd: Mapped[float | None] = mapped_column(Float, nullable=True)
created_at: Mapped[datetime] = mapped_column(server_default=func.now())
project: Mapped["Project"] = relationship(back_populates="analyses") # noqa: F821
aois: Mapped[list["AOI"]] = relationship( # noqa: F821
back_populates="analysis", cascade="all, delete-orphan"
)