summaryrefslogtreecommitdiff
path: root/src/match_up/data.py
blob: d8996fe34a9f96409dc015edda08b16e4ad97954 (plain) (blame)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from dataclasses import dataclass
from sqlalchemy import Column, String, Integer
from sqlalchemy.ext.declarative import declarative_base


MIN_LEVEL = 1
MAX_LEVEL = 10
PLAYER_PER_COURT = 4
GUEST_LEVELS = [1, 3, 5]
GUESTS_PER_LEVEL = 4

BASE = declarative_base()


class Player(BASE):
    __tablename__ = "players"
    id = Column("id", Integer, primary_key=True)
    first = Column("first", String)
    last = Column("last", String)
    level = Column("level", Integer)
    team = Column("team", Integer)
    status = Column("status", Integer)
    count = Column("count", Integer)


    def __init__(
        self,
        id: int,
        first: str = "",
        last: str = "",
        level: int = 0,
        team: int = 0,
        status: bool = True,
        count: int = 0,
    ):
        self.id = id
        self.first = first
        self.last = last
        self.status = status
        self.team = team
        self.level = level
        self.count = count

    def __repr__(self):
        team = f" of Team {self.team}" if self.team else ""
        status = "active" if self.status else "inactive"
        return f"{self.first} {self.last} (Level {self.level}){team} is {status} and has played {self.count} games"


class DisplayPlayer:
    id: int
    first: str
    last: str
    status: bool

    def __init__(self, player: Player):
        self.id = int(player.id)
        self.first = str(player.first)
        self.last = str(player.last)
        self.status = bool(player.status)

    def __repr__(self):
        status = "active" if self.status else "inactive"
        return f"{self.first} {self.last} is {status}"


@dataclass
class Team:
    player1: DisplayPlayer
    player2: DisplayPlayer


@dataclass
class Game:
    court: int
    team1: Team
    team2: Team