Пример #1
0
    def new_game(self, **kwargs):
        default = {}
        default.update(kwargs)

        game = Game(**default)
        db.session.add(game)
        db.session.commit()
        return game
Пример #2
0
    def post(self):
        deserialized = request.get_json()

        if not game_validator.is_valid(deserialized):
            errors = handle_validation_errors(
                game_validator.iter_errors(deserialized))
            return dumps(errors), 400
        else:
            errors = {}
            for player in ['x_player_id', 'o_player_id']:
                if not User.exists_by_id(deserialized[player]):
                    errors[player] = 'Player does not exist'
            if errors != {}:
                return dumps(errors), 400

        game = Game.create(deserialized)

        return dumps(game.serialized)
Пример #3
0
    def post(self):
        deserialized = request.get_json()

        if not game_validator.is_valid(deserialized):
            errors = handle_validation_errors(
                        game_validator.iter_errors(deserialized))
            return dumps(errors), 400
        else:
            errors = {}
            for player in ['x_player_id', 'o_player_id']:
                if not User.exists_by_id(deserialized[player]):
                    errors[player] = 'Player does not exist'
            if errors != {}:
                return dumps(errors), 400

        game = Game.create(deserialized)

        return dumps(game.serialized)
Пример #4
0
                        debut_date=debut_date)
        player.save()

if import_type == 'gamelog':
    for row in rows:
        print("Processing %(date)s..." % {'date': row[0]})
        game_date = date_or_none(row[0], "%Y%m%d")
        attendance = int(row[17])
        day_of_week = row[2]
        duration_in_minutes = int(row[18])
        winning_pitcher = Player.objects.get(retrosheet_id=row[93])
        losing_pitcher = Player.objects.get(retrosheet_id=row[95])

        game = Game(attendance=attendance,
                    date=game_date,
                    day_of_week=day_of_week,
                    winning_pitcher=winning_pitcher,
                    losing_pitcher=losing_pitcher)

        game.save()

        away_team = Team.objects.get(team_abbreviation=row[3], league=row[4])
        away_team_game_number = int(row[5])
        away_team_runs_scored = int(row[9])
        away_team_starting_pitcher = Player.objects.get(retrosheet_id=row[101])
        away_participant = game.gameparticipant_set.create(
            team=away_team,
            game_number_for_season=away_team_game_number,
            team_location_status='away',
            runs_scored_count=away_team_runs_scored,
            starting_pitcher=away_team_starting_pitcher)
Пример #5
0
    debut_date = date_or_none(date_string)

    player = Player(last_name = last_name, first_name = first_name, retrosheet_id = key, debut_date = debut_date)
    player.save()

if import_type == 'gamelog':
  for row in rows:
    print ("Processing %(date)s..." % {'date': row[0]})
    game_date = date_or_none(row[0], "%Y%m%d")
    attendance = int(row[17])
    day_of_week = row[2]
    duration_in_minutes = int(row[18])
    winning_pitcher = Player.objects.get(retrosheet_id = row[93])
    losing_pitcher = Player.objects.get(retrosheet_id = row[95])

    game = Game(attendance = attendance, date = game_date, day_of_week = day_of_week, winning_pitcher = winning_pitcher, losing_pitcher = losing_pitcher)

    game.save()

    away_team = Team.objects.get(team_abbreviation=row[3], league=row[4])
    away_team_game_number = int(row[5])
    away_team_runs_scored = int(row[9])
    away_team_starting_pitcher = Player.objects.get(retrosheet_id = row[101])
    away_participant = game.gameparticipant_set.create(team = away_team, game_number_for_season = away_team_game_number, team_location_status = 'away', runs_scored_count = away_team_runs_scored, starting_pitcher = away_team_starting_pitcher)

    home_team = Team.objects.get(team_abbreviation=row[6], league=row[7])
    home_team_game_number = int(row[8])
    home_team_runs_scored = int(row[10])
    home_team_starting_pitcher = Player.objects.get(retrosheet_id = row[103])
    home_participant = game.gameparticipant_set.create(team = home_team, game_number_for_season = home_team_game_number, team_location_status = 'home', runs_scored_count = home_team_runs_scored, starting_pitcher = home_team_starting_pitcher)