Exemplo n.º 1
0
class UsersGames(db.Model):
    ''' this maps users to games, and provides the score and placement '''
    __tablename = 'user_game'
    user_id = db.Column('user_id',
                        db.Integer(),
                        db.ForeignKey('user.id'),
                        primary_key=True)
    game_id = db.Column('game_id',
                        db.Unicode(255),
                        db.ForeignKey('game.id'),
                        primary_key=True)
    score = db.Column(db.Integer())
    place = db.Column(db.Integer())

    player = db.relationship(User,
                             backref=db.backref('played_games',
                                                lazy='dynamic',
                                                cascade="all, delete-orphan"))

    game = db.relationship(
        Game,
        backref=db.backref(
            'games_players',
            lazy='immediate',
            cascade="all, delete-orphan",
            collection_class=attribute_mapped_collection("place"),
        ),
    )

    def __init__(self, user=None, game=None, score=-9999, place=-1):
        self.user = user
        self.game = game
        self.score = score
        self.place = place
Exemplo n.º 2
0
class SeasonsPlayers(db.Model):
    '''
    Stores score for each player for each season
    '''
    __tablename__ = 'seasonsplayers'

    season_id = db.Column(db.Integer,
                          db.ForeignKey('season.season_id'),
                          nullable=False,
                          primary_key=True)

    player_id = db.Column(db.Integer,
                          db.ForeignKey('player.player_id'),
                          nullable=False,
                          primary_key=True)

    score = db.Column(db.Integer, default=0, nullable=True)  # score x 10
    place = db.Column(db.Integer, nullable=True)
    note = db.Column(db.UnicodeText(), nullable=True)

    player = db.relationship(
        Player,
        backref=db.backref(
            'played_seasons',
            lazy='joined',
            cascade="all,delete-orphan",
        ),
    )

    season = db.relationship(
        Season,
        backref=db.backref(
            'seasons_players',
            lazy='dynamic',
            cascade="all, delete-orphan",
            collection_class=attribute_mapped_collection("place"),
        ),
    )

    def __init__(self,
                 player=None,
                 season_id=None,
                 score=None,
                 place=None,
                 note=None):
        self.player = player
        self.season_id = season_id
        self.score = score
        self.place = place
        self.note = note

    def __str__(self):
        return ('id: ' + self.season_id + '\n player: ' + self.player_id +
                '\n started: ' + str(self.firstgame) + '\n score: ' +
                str(self.aggscore))
Exemplo n.º 3
0
class PlayersGames(db.Model):
    ''' this maps players to games, and provides the score and placement '''
    __tablename = 'playersgames'
    player_id = db.Column('player_id',
                          db.Integer,
                          db.ForeignKey('player.player_id'),
                          primary_key=True)
    game_id = db.Column('game_id',
                        db.Integer,
                        db.ForeignKey('game.game_id'),
                        primary_key=True)
    score = db.Column(db.Integer)
    penalties = db.Column(db.Integer)
    place = db.Column(db.Integer)
    note = db.Column(db.UnicodeText())

    player = db.relationship(
        Player,
        backref=db.backref(
            'played_games',
            lazy='joined',
            cascade="all,delete-orphan",
        ),
    )

    game = db.relationship(
        Game,
        backref=db.backref(
            'games_players',
            lazy='dynamic',
            cascade="all, delete-orphan",
            collection_class=attribute_mapped_collection("place"),
        ),
    )

    def __init__(self, player=None, game=None, score=-9999, place=-1):
        self.player = player
        self.game = game
        self.score = score
        self.place = place
Exemplo n.º 4
0
class Game(db.Model):
    '''
    The heart of the database: an individual game record
    '''
    __tablename__ = 'game'
    game_id = db.Column(db.Integer, primary_key=True)
    description = db.Column(db.UnicodeText(), default=make_desc)
    json = db.Column(db.UnicodeText())
    log = db.Column(db.LargeBinary())
    public = db.Column(db.Boolean())
    started = db.Column(db.DateTime())
    last_updated = db.Column(db.DateTime(),
                             default=datetime.utcnow,
                             onupdate=datetime.utcnow)
    is_active = db.Column(db.Boolean())
    season_id = db.Column(
        'season_id',
        db.Integer,
        db.ForeignKey('season.season_id'),
    )
    season_index = db.Column(db.Integer)
    table = db.Column(db.UnicodeText())
    note = db.Column(db.UnicodeText())

    players = association_proxy('games_players', 'player')
    player_names = association_proxy('games_players', 'player.name')
    scores = association_proxy('games_players', 'score')
    places = association_proxy('games_players', 'place')

    def __str__(self):
        return ('id: ' + self.game_id + '\n desc: ' + self.description +
                '\n started: ' + str(self.started) + '\n last_updated: ' +
                str(self.last_updated) + '\n public: ' + str(self.public) +
                '\n is_active: ' + str(self.is_active))

    def get_score_table(self):
        if self.json is None:
            return {}
        json = json_loads(self.json)
        if 'hands' in json and 'deltas' not in json['hands'][-1]:
            del json['hands'][-1]

        return json