Example #1
0
    def create_weather_report(temperature, wind, precipitation, location,
                              date):
        weather_report_models = WeatherReportModel.get_all_weather_reports(
            temperature=temperature,
            wind=wind,
            precipitation=precipitation,
            location=location,
            date=date)

        if weather_report_models:
            return [
                weather_report_model.as_dict()
                for weather_report_model in weather_report_models
            ]

        weather_report_id = str(uuid4())
        weather_report_model = WeatherReportModel(
            weather_report_id=weather_report_id,
            temperature=temperature,
            wind=wind,
            precipitation=precipitation,
            location=location,
            date=date)

        mlbdb.add(weather_report_model)
        mlbdb.commit()

        return weather_report_model.as_dict()
Example #2
0
    def delete_schedule(schedule_id):
        schedule_model = ScheduleModel.get_schedule_by_id(schedule_id=schedule_id, return_as_model=True)

        if schedule_model:
            mlbdb.delete(schedule_model)
            mlbdb.commit()

            return schedule_model.as_dict()

        return None
Example #3
0
    def delete_game(game_id):
        game_model = GameModel.get_game_by_id(game_id=game_id,
                                              return_as_model=True)

        if game_model:
            mlbdb.delete(game_model)
            mlbdb.commit()

            return game_model.as_dict()

        return None
Example #4
0
    def delete_expectation(expectation_id):
        expectation_model = ExpectationModel.get_expectation_by_id(
            expectation_id=expectation_id, return_as_model=True)

        if expectation_model:
            mlbdb.delete(expectation_model)
            mlbdb.commit()

            return expectation_model.as_dict()

        return None
Example #5
0
    def delete_weather_report(weather_report_id):
        weather_report_model = WeatherReportModel.get_weather_report_by_id(
            weather_report_id=weather_report_id, return_as_model=True)

        if weather_report_model:
            mlbdb.delete(weather_report_model)
            mlbdb.commit()

            return weather_report_model.as_dict()

        return None
Example #6
0
    def delete_team(team_id):
        team_model = TeamModel.get_team_by_id(team_id=team_id,
                                              return_as_model=True)

        if team_model:
            mlbdb.delete(team_model)
            mlbdb.commit()

            return team_model.as_dict()

        return None
Example #7
0
    def delete_injury_report(injury_report_id):
        injury_report_model = InjuryReportModel.get_injury_report_by_id(
            injury_report_id=injury_report_id, return_as_model=True)

        if injury_report_model:
            mlbdb.delete(injury_report_model)
            mlbdb.commit()

            return injury_report_model.as_dict()

        return None
Example #8
0
    def delete_player(player_id):
        player_model = PlayerModel.get_player_by_id(player_id=player_id,
                                                    return_as_model=True)

        if player_model:
            mlbdb.delete(player_model)
            mlbdb.commit()

            return player_model.as_dict()

        return None
Example #9
0
    def delete_season(season_id):
        season_model = SeasonModel.get_season_by_id(season_id=season_id,
                                                    return_as_model=True)

        if season_model:
            mlbdb.delete(season_model)
            mlbdb.commit()

            return season_model.as_dict()

        return None
Example #10
0
    def create_injury_report(players, date):
        injury_report_models = InjuryReportModel.get_all_injury_reports(
            players=players, date=date)

        if injury_report_models:
            return [
                injury_report_model.as_dict()
                for injury_report_model in injury_report_models
            ]

        injury_report_id = str(uuid4())
        injury_report_model = InjuryReportModel(
            injury_report_id=injury_report_id, players=players, date=date)

        mlbdb.add(injury_report_model)
        mlbdb.commit()

        return injury_report_model.as_dict()
Example #11
0
    def create_schedule(away_team_id, home_team_id, game_start_time, date):
        schedule_models = ScheduleModel.get_all_schedules(away_team_id=away_team_id,
                                                          home_team_id=home_team_id,
                                                          game_start_time=game_start_time,
                                                          date=date)

        if schedule_models:
            return [schedule_model.as_dict() for schedule_model in schedule_models]

        schedule_id = str(uuid4())
        schedule_model = ScheduleModel(schedule_id=schedule_id,
                                       away_team_id=away_team_id,
                                       home_team_id=home_team_id,
                                       game_start_time=game_start_time,
                                       date=date)

        mlbdb.add(schedule_model)
        mlbdb.commit()

        return schedule_model.as_dict()
Example #12
0
    def create_season(season_start_date, season_end_date, champion_id,
                      runnerup_id):
        season_models = SeasonModel.get_all_seasons(
            season_start_date=season_start_date,
            season_end_date=season_end_date)

        if season_models:
            return [season_model.as_dict() for season_model in season_models]

        season_id = str(uuid4())
        season_model = SeasonModel(season_id=season_id,
                                   season_start_date=season_start_date,
                                   season_end_date=season_end_date,
                                   champion_id=champion_id,
                                   runnerup_id=runnerup_id)

        mlbdb.add(season_model)
        mlbdb.commit()

        return season_model.as_dict()
Example #13
0
    def create_team(team_name, team_city, conference_id, division_id,
                    season_id):
        team_models = TeamModel.get_all_teams(team_name=team_name,
                                              team_city=team_city,
                                              season_id=season_id)

        if team_models:
            return [team_model.as_dict() for team_model in team_models]

        team_id = str(uuid4())
        team_model = TeamModel(team_id=team_id,
                               team_name=team_name,
                               team_city=team_city,
                               conference_id=conference_id,
                               division_id=division_id,
                               season_id=season_id)

        mlbdb.add(team_model)
        mlbdb.commit()

        return team_model.as_dict()
Example #14
0
    def create_game(date, dome, away_team_id, home_team_id, winner_id,
                    loser_id, winner_score, loser_score, winning_pitcher_id,
                    losing_pitcher_id, weather_report_id, expectation_id,
                    injury_reports_away_team, injury_reports_home_team):
        game_models = GameModel.get_all_games(
            date=date,
            away_team_id=away_team_id,
            home_team_id=home_team_id,
            winner_score=winner_score,
            loser_score=loser_score,
            winner_id=winner_id,
            loser_id=loser_id,
            winning_pitcher_id=winning_pitcher_id,
            losing_pitcher_id=losing_pitcher_id)

        if game_models:
            return [game_model.as_dict() for game_model in game_models]

        game_id = str(uuid4())
        game_model = GameModel(
            game_id=game_id,
            date=date,
            dome=dome,
            away_team_id=away_team_id,
            home_team_id=home_team_id,
            winner_id=winner_id,
            loser_id=loser_id,
            winner_score=winner_score,
            loser_score=loser_score,
            winning_pitcher_id=winning_pitcher_id,
            losing_pitcher_id=losing_pitcher_id,
            weather_report_id=weather_report_id,
            expectation_id=expectation_id,
            injury_reports_away_team=injury_reports_away_team,
            injury_reports_home_team=injury_reports_home_team)

        mlbdb.add(game_model)
        mlbdb.commit()

        return game_model.as_dict()
Example #15
0
    def create_player(player_name, bats, throws, player_position, starter,
                      team_id):
        player_models = PlayerModel.get_all_players(
            player_name=player_name,
            player_positon=player_position,
            team_id=team_id)

        if player_models:
            return [player_model.as_dict() for player_model in player_models]

        player_id = str(uuid4())
        player_model = PlayerModel(player_id=player_id,
                                   player_name=player_name,
                                   bats=bats,
                                   throws=throws,
                                   starter=starter,
                                   team_id=team_id)

        mlbdb.add(player_model)
        mlbdb.commit()

        return player_model.as_dict()
Example #16
0
    def create_expectation(away_team_id, home_team_id, winner_id, loser_id,
                           winner_score, loser_score, winning_pitcher_id,
                           losing_pitcher_id, date):
        expectation_models = ExpectationModel.get_all_expectations(
            away_team_id=away_team_id,
            home_team_id=home_team_id,
            winner_id=winner_id,
            loser_id=loser_id,
            winner_score=winner_score,
            loser_score=loser_score,
            winning_pitcher_id=winning_pitcher_id,
            losing_pitcher_id=losing_pitcher_id,
            date=date)

        if expectation_models:
            return [
                expectation_model.as_dict()
                for expectation_model in expectation_models
            ]

        expectation_id = str(uuid4())
        expectation_model = ExpectationModel(
            expectation_id=expectation_id,
            away_team_id=away_team_id,
            home_team_id=home_team_id,
            winner_id=winner_id,
            loser_id=loser_id,
            winner_score=winner_score,
            loser_score=loser_score,
            winning_pitcher_id=winning_pitcher_id,
            losing_pitcher_id=losing_pitcher_id,
            date=date)

        mlbdb.add(expectation_model)
        mlbdb.commit()

        return expectation_model.as_dict()