forked from alexraison/Magic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
113 lines (74 loc) · 3.42 KB
/
models.py
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from app import db
from sqlalchemy.dialects.postgresql import JSON
from sqlalchemy import ForeignKeyConstraint
from sqlalchemy.orm import relationship, backref
class Set(db.Model):
__tablename__ = 'set'
id = db.Column(db.Integer, primary_key = True)
name = db.Column(db.String(50))
constructed = db.Column(db.Boolean)
tournaments = relationship('Tournament', backref='tournamentSet')
class TournamentType(db.Model):
__tablename__ = 'tournament_type'
id = db.Column(db.Integer, primary_key = True)
description = db.Column(db.String(50))
game_wins_required = db.Column(db.Integer)
tournaments = relationship('Tournament', backref='tournamentType')
class Tournament(db.Model):
__tablename__ = 'tournament'
id = db.Column(db.Integer, primary_key = True)
name = db.Column(db.String(50))
type = db.Column(db.Integer, db.ForeignKey('tournament_type.id'))
set_id = db.Column(db.Integer, db.ForeignKey('set.id'))
date = db.Column(db.Date)
winners = db.Column(db.String(300))
matches = relationship('Match', cascade="all, delete-orphan", backref='tournament')
statistics = relationship('Statistics', cascade="all, delete-orphan", backref='tournament')
class Match(db.Model):
__tablename__ = 'match'
id = db.Column(db.Integer, primary_key = True)
tournament_id = db.Column(db.Integer, db.ForeignKey('tournament.id'))
participants = relationship("MatchParticipant", cascade="all, delete-orphan", backref=backref("matches"))
class Player(db.Model):
__tablename__ = 'player'
id = db.Column(db.Integer, primary_key = True)
username = db.Column(db.String(30))
name = db.Column(db.String(30))
password = db.Column(db.String(30))
slack_user = db.Column(db.String(21))
def is_authenticated(self):
return True
def is_active(self):
return True
def is_anonymous(self):
return False
def get_id(self):
return self.id
entities = relationship("EntityParticipant", backref="player")
class Entity(db.Model):
__tablename__ = 'entity'
id = db.Column(db.Integer, primary_key = True)
matches = relationship("MatchParticipant", backref="entity")
participants = relationship("EntityParticipant", backref="entities")
class EntityParticipant(db.Model):
__tablename__ = 'entity_participant'
entity_id = db.Column(db.Integer, db.ForeignKey('entity.id'), primary_key = True)
player_id = db.Column(db.Integer, db.ForeignKey('player.id'), primary_key = True)
class MatchParticipant(db.Model):
__tablename__ = 'match_participant'
match_id = db.Column(db.Integer, db.ForeignKey('match.id'), primary_key = True)
entity_id = db.Column(db.Integer, db.ForeignKey('entity.id'), primary_key = True)
game_wins = db.Column(db.Integer)
class Statistics(db.Model):
__tablename__ = 'statistics'
tournament_id = db.Column(db.Integer, db.ForeignKey('tournament.id'), primary_key = True)
entity_id = db.Column(db.Integer, db.ForeignKey('entity.id'), primary_key = True)
position = db.Column(db.Integer)
match_wins = db.Column(db.Integer)
match_losses = db.Column(db.Integer)
match_win_percentage = db.Column(db.Float)
game_wins = db.Column(db.Integer)
game_losses = db.Column(db.Integer)
game_win_percentage = db.Column(db.Float)
matches_unfinished = db.Column(db.Integer)
entity = relationship("Entity", foreign_keys=[entity_id], backref="entity")