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()
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()
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()
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()
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()
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()
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()
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()