🏓 Initial ServeSync demo build
- FastAPI backend with PostgreSQL + Redis - 4 core features: Registration, Courts, Matchmaking, Tournament - Double elimination tournament with bracket visualization - ELO-based matchmaking (Stage 1 Open, Stage 2 Skill-Based) - Real-time WebSocket updates - TV Screen display for courts - Vue 3 + Tailwind CSS frontend - Seed data: 12 players, 4 courts, active matches, tournament in progress - Docker compose stack with Nginx reverse proxy
This commit is contained in:
93
backend/app/models/tournament.py
Normal file
93
backend/app/models/tournament.py
Normal file
@@ -0,0 +1,93 @@
|
||||
from sqlalchemy import Column, Integer, ForeignKey, DateTime, Float, String, Enum, Boolean, JSON
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
from app.database import Base
|
||||
import enum
|
||||
|
||||
|
||||
class TournamentStatus(str, enum.Enum):
|
||||
REGISTRATION = "registration"
|
||||
IN_PROGRESS = "in_progress"
|
||||
COMPLETED = "completed"
|
||||
|
||||
|
||||
class BracketType(str, enum.Enum):
|
||||
WINNERS = "winners"
|
||||
LOSERS = "losers"
|
||||
GRAND_FINAL = "grand_final"
|
||||
|
||||
|
||||
class TournamentMatchStatus(str, enum.Enum):
|
||||
PENDING = "pending"
|
||||
IN_PROGRESS = "in_progress"
|
||||
COMPLETED = "completed"
|
||||
|
||||
|
||||
class Tournament(Base):
|
||||
__tablename__ = "tournaments"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String(200), nullable=False)
|
||||
status = Column(Enum(TournamentStatus), default=TournamentStatus.REGISTRATION)
|
||||
max_participants = Column(Integer, default=8)
|
||||
current_round = Column(Integer, default=1)
|
||||
bracket_data = Column(JSON, nullable=True)
|
||||
started_at = Column(DateTime(timezone=True), nullable=True)
|
||||
ended_at = Column(DateTime(timezone=True), nullable=True)
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
# Relationships
|
||||
entries = relationship("TournamentEntry", back_populates="tournament")
|
||||
tournament_matches = relationship("TournamentMatch", back_populates="tournament")
|
||||
|
||||
|
||||
class TournamentEntry(Base):
|
||||
__tablename__ = "tournament_entries"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
tournament_id = Column(Integer, ForeignKey("tournaments.id"), nullable=False)
|
||||
player_id = Column(Integer, ForeignKey("players.id"), nullable=False)
|
||||
seed = Column(Integer, nullable=True)
|
||||
final_rank = Column(Integer, nullable=True)
|
||||
is_eliminated = Column(Boolean, default=False)
|
||||
losses = Column(Integer, default=0)
|
||||
wins = Column(Integer, default=0)
|
||||
is_in_losers = Column(Boolean, default=False)
|
||||
registered_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
# Relationships
|
||||
tournament = relationship("Tournament", back_populates="entries")
|
||||
player = relationship("Player", back_populates="tournament_entries")
|
||||
|
||||
|
||||
class TournamentMatch(Base):
|
||||
__tablename__ = "tournament_matches"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
tournament_id = Column(Integer, ForeignKey("tournaments.id"), nullable=False)
|
||||
match_id = Column(Integer, ForeignKey("matches.id"), nullable=True)
|
||||
round_number = Column(Integer, nullable=False)
|
||||
match_number = Column(Integer, nullable=False)
|
||||
bracket_type = Column(Enum(BracketType), default=BracketType.WINNERS)
|
||||
status = Column(Enum(TournamentMatchStatus), default=TournamentMatchStatus.PENDING)
|
||||
|
||||
# Players
|
||||
player1_id = Column(Integer, ForeignKey("players.id"), nullable=True)
|
||||
player2_id = Column(Integer, ForeignKey("players.id"), nullable=True)
|
||||
player3_id = Column(Integer, ForeignKey("players.id"), nullable=True) # doubles team2 p1
|
||||
player4_id = Column(Integer, ForeignKey("players.id"), nullable=True) # doubles team2 p2
|
||||
|
||||
# Scores
|
||||
team1_score = Column(Integer, default=0)
|
||||
team2_score = Column(Integer, default=0)
|
||||
winner_team = Column(Integer, nullable=True)
|
||||
|
||||
# Next match routing
|
||||
winner_next_match = Column(Integer, nullable=True)
|
||||
loser_next_match = Column(Integer, nullable=True)
|
||||
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
completed_at = Column(DateTime(timezone=True), nullable=True)
|
||||
|
||||
# Relationships
|
||||
tournament = relationship("Tournament", back_populates="tournament_matches")
|
||||
Reference in New Issue
Block a user