olivas/backend/app/models/analysis.py
DJP c1b80eb9a7 Replace entropy score with composite Design Effectiveness Score
The pure Shannon entropy score penalized well-designed ads with multiple
intentional visual elements (e.g. hero product + text + logo scored ~8/100).

New composite score (0-100) weights four components:
- Peak Dominance (30%): strength of #1 hotspot vs rest
- Hierarchy Clarity (25%): monotonic intensity ordering
- Gaze Coherence (25%): smooth spatial gaze path
- Entropy Concentration (20%): sqrt-softened entropy

The raw entropy score is preserved as entropy_score for users who want it,
visible in the ScoreCard hover tooltip and PDF report.

Also adds auto-create DB tables on startup for fresh Docker deploys.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 22:50:12 -05:00

42 lines
1.9 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)
entropy_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"
)