File size: 1,672 Bytes
20cccb6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5ed9749
20cccb6
 
 
 
 
 
 
 
 
 
 
 
 
ad1ff58
20cccb6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Standard Library Imports
from enum import Enum

# Third-Party Library Imports
from sqlalchemy import (
    Boolean,
    Column,
    DateTime,
    Index,
    Integer,
    String,
    Text,
    func,
)
from sqlalchemy import (
    Enum as saEnum,
)
from sqlalchemy import (
    text as sa_text,
)

# Local Application Imports
from .database import Base


class OptionEnum(str, Enum):
    OPTION_A = "option_a"
    OPTION_B = "option_b"

class VoteResult(Base):
    __tablename__ = "vote_results"

    id = Column(Integer, primary_key=True, autoincrement=True)
    created_at = Column(DateTime, nullable=False, server_default=func.now())
    comparison_type = Column(String(50), nullable=False)
    winning_provider = Column(String(50), nullable=False)
    winning_option = Column(saEnum(OptionEnum), nullable=False)  # type: ignore
    option_a_provider = Column(String(50), nullable=False)
    option_b_provider = Column(String(50), nullable=False)
    option_a_generation_id = Column(String(100), nullable=True)
    option_b_generation_id = Column(String(100), nullable=True)
    voice_description = Column(Text, nullable=False)
    text = Column(Text, nullable=False)
    is_custom_text = Column(Boolean, nullable=False, server_default=sa_text("false"))

    __table_args__ = (
        Index("idx_created_at", "created_at"),
        Index("idx_comparison_type", "comparison_type"),
        Index("idx_winning_provider", "winning_provider"),
    )

    def __repr__(self):
        return (
            f"<VoteResult(id={self.id}, created_at={self.created_at}, "
            f"comparison_type={self.comparison_type}, winning_provider={self.winning_provider})>"
        )