Beispiel #1
0
def get_results(game_id):
    """Return result from game"""
    game = Game.query.filter(Game.game_id == game_id).first()
    if game is None:
        game = update_game(game_id)

    game.last_result_time = datetime.now()
    current_day = get_day(game)

    for day_index in range(game.last_day, current_day):
        day_index += 1

        result = get_score(game, day_index)
        result.pop(0)

        player_id = 0

        for score in result:
            player_id += 1
            if score >= 20:
                player = game.players.filter(
                    Player.player_id == player_id).first()
                day = player.days.filter(Day.day == day_index).first()

                if day is None:
                    day = Day()
                    day.day = day_index
                    day.points = score
                    day.game_id = game.id
                    day.player_id = player.id
                    db.session.add(day)

    db.session.commit()

    return game
Beispiel #2
0
def update_score(game):
    """Update result to current day"""

    supremacy = Supremacy(game.game_id, game.game_host)
    current_day = game.day

    for day_index in range(game.last_day, current_day):
        day_index += 1

        result = supremacy.score(day_index)

        ranking = result["ranking"]["ranking"]
        ranking.pop(0)

        player_id = 0

        for score in ranking:
            player_id += 1
            if score >= 20:
                player = game.players.filter(
                    Player.player_id == player_id).first()
                day = player.days.filter(Day.day == day_index).first()

                if day is None:
                    day = Day()
                    day.day = day_index
                    day.points = score
                    day.game_id = game.id
                    day.player_id = player.id
                    db.session.add(day)

    db.session.commit()