🏓 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:
46
backend/app/models/player.py
Normal file
46
backend/app/models/player.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from sqlalchemy import Column, Integer, String, Float, DateTime, Enum, Boolean
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
from app.database import Base
|
||||
import enum
|
||||
|
||||
|
||||
class MembershipTier(str, enum.Enum):
|
||||
BRONZE = "bronze"
|
||||
SILVER = "silver"
|
||||
GOLD = "gold"
|
||||
PLATINUM = "platinum"
|
||||
ELITE = "elite"
|
||||
|
||||
|
||||
class Player(Base):
|
||||
__tablename__ = "players"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String(100), nullable=False)
|
||||
email = Column(String(255), unique=True, nullable=False)
|
||||
phone = Column(String(20))
|
||||
elo_rating = Column(Float, default=1000.0)
|
||||
membership_tier = Column(Enum(MembershipTier), default=MembershipTier.BRONZE)
|
||||
wins = Column(Integer, default=0)
|
||||
losses = Column(Integer, default=0)
|
||||
total_matches = Column(Integer, default=0)
|
||||
is_active = Column(Boolean, default=True)
|
||||
avatar_color = Column(String(7), default="#3B82F6")
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
||||
|
||||
# Relationships
|
||||
bookings = relationship("Booking", back_populates="player")
|
||||
match_players = relationship("MatchPlayer", back_populates="player")
|
||||
tournament_entries = relationship("TournamentEntry", back_populates="player")
|
||||
|
||||
@property
|
||||
def win_rate(self):
|
||||
if self.total_matches == 0:
|
||||
return 0
|
||||
return round(self.wins / self.total_matches * 100, 1)
|
||||
|
||||
@property
|
||||
def tier_label(self):
|
||||
return self.membership_tier.value.capitalize()
|
||||
Reference in New Issue
Block a user