コード例 #1
0
class ExternalTeamIdentifier(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    team_id = db.Column(db.Integer, db.ForeignKey("team.id"))
    source_id = db.Column(db.Integer, db.ForeignKey("data_source.id"))
    value = db.Column(db.String(128))
    external_id = db.Column(db.Integer, nullable=True)

    team = db.relationship("Team", backref="external_identifiers")
    source = db.relationship("DataSource")
コード例 #2
0
ファイル: models.py プロジェクト: exleym/Hatchet
class Ranking(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    week_id = db.Column(db.Integer, db.ForeignKey("week.id"))
    poll_id = db.Column(db.Integer, db.ForeignKey("poll.id"))
    team_id = db.Column(db.Integer, db.ForeignKey("team.id"))
    rank = db.Column(db.Integer)
    prior_rank = db.Column(db.Integer)

    poll = db.relationship("Poll")
    team = db.relationship("Team")
コード例 #3
0
ファイル: models.py プロジェクト: exleym/Hatchet
class Rating(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    game_id = db.Column(db.Integer, db.ForeignKey("game.id"))
    network_id = db.Column(db.Integer, db.ForeignKey("network.id"))
    rating = db.Column(db.Float, nullable=True)
    viewers = db.Column(db.Float, nullable=True)

    game = db.relationship("Game", backref=backref("rating", uselist=False))
コード例 #4
0
ファイル: models.py プロジェクト: exleym/Hatchet
class Play(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    quarter = db.Column(db.Integer)
    play_number = db.Column(db.Integer)
    game_clock = db.Column(db.Time)
    game_id = db.Column(db.Integer, db.ForeignKey('game.id'))
    down = db.Column(db.Integer)
    to_go = db.Column(db.Float)
    play_occurred = db.Column(db.Boolean)
    penalty_occurred = db.Column(db.Boolean)

    game = db.relationship("Game", backref="plays")
コード例 #5
0
ファイル: models.py プロジェクト: exleym/Hatchet
class Stadium(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    code = db.Column(db.String(16))
    name = db.Column(db.String(128))
    state = db.Column(db.String(2))
    city = db.Column(db.String(64))
    latitude = db.Column(db.String(16))
    longitude = db.Column(db.String(16))
    built = db.Column(db.Integer)
    capacity = db.Column(db.Integer)
    surface_id = db.Column(db.Integer, db.ForeignKey("surface.id"))

    surface = db.relationship("Surface", backref="stadiums")

    def __repr__(self):
        return f"<Stadium(id={self.id}, name='{self.name}')>"
コード例 #6
0
ファイル: models.py プロジェクト: exleym/Hatchet
class Conference(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    subdivision_id = db.Column(db.Integer, db.ForeignKey("subdivision.id"))
    code = db.Column(db.String(8), unique=True, nullable=False)
    name = db.Column(db.String(256), unique=True, nullable=False)
    short_name = db.Column(db.String(32), unique=True, nullable=True)
    inception_year = db.Column(db.Integer)

    subdivision = db.relationship("Subdivision", backref="conferences")

    @property
    def links(self):
        return dict()

    def __repr__(self):
        return f"<Conference(id={self.id}, code='{self.code}'," \
               f" name='{self.name}', short_name='{self.short_name}')>"
コード例 #7
0
ファイル: models.py プロジェクト: exleym/Hatchet
class Game(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    game_time = db.Column(db.DateTime, nullable=False, index=True)
    stadium_id = db.Column(db.Integer, db.ForeignKey('stadium.id'))
    espn_id = db.Column(db.Integer, nullable=True)

    participants = db.relationship('GameParticipant', backref='game')

    @property
    def date(self):
        return self.game_time.date()

    @property
    def kickoff_time(self):
        return self.game_time.strftime('%H:%M:%S')

    @property
    def winner(self):
        max_score = 0
        max_scorer = None
        for p in self.participants:
            if p.score and p.score > max_score:
                max_score = p.score
                max_scorer = p
        return max_scorer

    @property
    def loser(self):
        min_score = 9999
        min_scorer = None
        for p in self.participants:
            if p.score and p.score < min_score:
                min_score = p.score
                min_scorer = p
        return min_scorer

    def __repr__(self):
        return f"<Game(id={self.id})>"
コード例 #8
0
ファイル: models.py プロジェクト: exleym/Hatchet
class Division(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    conference_id = db.Column(db.Integer, db.ForeignKey('conference.id'))
    name = db.Column(db.String, nullable=True)

    conference = db.relationship('Conference', backref='divisions')

    @property
    def standings(self):
        teams = self.members
        teams.sort(key=lambda x: x.wins, reverse=True)
        return teams

    @property
    def full_name(self):
        conference = self.conference.short_name or self.conference.name
        if self.name:
            return f"{conference} - {self.name}"
        return self.conference.name

    def __repr__(self):
        return f"<Division(id={self.id}, conference_id={self.conference_id}," \
               f" name='{self.name}')>"
コード例 #9
0
ファイル: models.py プロジェクト: exleym/Hatchet
class Team(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    code = db.Column(db.String(8), unique=True)
    name = db.Column(db.String(128), unique=True, nullable=False)
    short_name = db.Column(db.String(64), nullable=True)
    mascot = db.Column(db.String(128), nullable=False)
    conference_id = db.Column(db.Integer, db.ForeignKey('conference.id'))
    division_id = db.Column(db.Integer, db.ForeignKey('division.id'))
    stadium_id = db.Column(db.Integer, db.ForeignKey('stadium.id'))

    conference = db.relationship('Conference', backref='members')
    division = db.relationship('Division', backref='members')
    stadium = db.relationship('Stadium', uselist=False, backref='team')
    played_in = db.relationship('GameParticipant', backref='team')

    @property
    def games(self):
        return [g.game for g in self.played_in]

    @property
    def home_games(self):
        return [g.game for g in self.played_in if g.location_type_id == 1]

    @property
    def wins(self):
        return len([
            g for g in self.games if g.winner and g.winner.team_id == self.id
        ])

    @property
    def losses(self):
        return len([
            g for g in self.games if g.winner and g.winner.team_id != self.id
        ])

    @property
    def conference_wins(self):
        return len([
            g for g in self.games if g.winner and g.winner.team_id == self.id
            and g.loser.team.conference_id == self.conference_id
        ])

    @property
    def conference_losses(self):
        return len([
            g for g in self.games if g.winner and g.winner.team_id != self.id
            and g.winner.team.conference_id == self.conference_id
        ])

    def record(self, season: int):
        return {
            "season": season,
            "wins": self.wins,
            "losses": self.losses,
            "confWins": self.conference_wins,
            "confLosses": self.conference_losses
        }

    def __repr__(self):
        return f"<Team(id={self.id}, name='{self.name}', " \
               f"mascot='{self.mascot}', code='{self.code}')>"