343 lines
10 KiB
Python
343 lines
10 KiB
Python
from data.db_connect import Database
|
|
|
|
# Game date in YYYYmmDD
|
|
def pull_training_data(database: Database, game_date: str, game_number: int, park_id: str):
|
|
# Training data
|
|
|
|
"""
|
|
- park_id
|
|
- lf_fence_distance
|
|
- lf_fence_height
|
|
- ct_fence_distance
|
|
- ct_fence_height
|
|
- rf_fence_distance
|
|
- rf_fence_height
|
|
- has_roof
|
|
- elevation
|
|
- game_date
|
|
- game_number
|
|
- day_of_week
|
|
- day_night
|
|
- home_plate_ump_id
|
|
- b1_ump_id
|
|
- b2_ump_id
|
|
- b3_ump_id
|
|
- lf_ump_id
|
|
- rf_ump_id
|
|
- temperature
|
|
- humidity
|
|
- dew_point
|
|
- apparent_temperature
|
|
- air_pressure
|
|
- precipitation
|
|
- rain
|
|
- snowfall
|
|
- cloud_cover
|
|
- wind_speed
|
|
- wind_direction
|
|
- wind_gusts
|
|
- sun_rise
|
|
- sun_set
|
|
- moon_phase
|
|
|
|
- Team being trained
|
|
- game_num
|
|
- manager_id
|
|
- starting_pitcher_id
|
|
- starting_1_id
|
|
- starting_1_position
|
|
- starting_2_id
|
|
- starting_2_position
|
|
- starting_3_id
|
|
- starting_3_position
|
|
- starting_4_id
|
|
- starting_4_position
|
|
- starting_5_id
|
|
- starting_5_position
|
|
- starting_6_id
|
|
- starting_6_position
|
|
- starting_7_id
|
|
- starting_7_position
|
|
- starting_8_id
|
|
- starting_8_position
|
|
- starting_9_id
|
|
- starting_9_position
|
|
|
|
- Calculated values from previous games
|
|
- win_streak
|
|
- loss_streak
|
|
- game_date
|
|
- day_of_weeki
|
|
- length_in_outs
|
|
- day_night
|
|
- completion_info
|
|
- forfeit
|
|
- protest
|
|
- park_id
|
|
- attendence
|
|
- length_in_minutes
|
|
- hits
|
|
- doubles
|
|
- triples
|
|
- homeruns
|
|
- rbis
|
|
- sacrifice_hits
|
|
- sacrifice_flies
|
|
- hit_by_pitch
|
|
- walks
|
|
- intentional_walks
|
|
- strikeouts
|
|
- stolen_bases
|
|
- caught_stealing
|
|
- grounded_double
|
|
- interference
|
|
- left_on_base
|
|
- pitchers_used
|
|
- individual_earned_runs
|
|
- earned_runs
|
|
- wild_pitches
|
|
- balks
|
|
- putouts
|
|
- assists
|
|
- errors
|
|
- passed
|
|
- double_play
|
|
- triple_play
|
|
- game_num
|
|
- manager_id
|
|
- starting_pitcher_id
|
|
- starting_1_id
|
|
- starting_1_position
|
|
- starting_2_id
|
|
- starting_2_position
|
|
- starting_3_id
|
|
- starting_3_position
|
|
- starting_4_id
|
|
- starting_4_position
|
|
- starting_5_id
|
|
- starting_5_position
|
|
- starting_6_id
|
|
- starting_6_position
|
|
- starting_7_id
|
|
- starting_7_position
|
|
- starting_8_id
|
|
- starting_8_position
|
|
- starting_9_id
|
|
- starting_9_position
|
|
|
|
- Opposing team
|
|
- game_num
|
|
- manager_id
|
|
- starting_pitcher_id
|
|
- starting_1_id
|
|
- starting_1_position
|
|
- starting_2_id
|
|
- starting_2_position
|
|
- starting_3_id
|
|
- starting_3_position
|
|
- starting_4_id
|
|
- starting_4_position
|
|
- starting_5_id
|
|
- starting_5_position
|
|
- starting_6_id
|
|
- starting_6_position
|
|
- starting_7_id
|
|
- starting_7_position
|
|
- starting_8_id
|
|
- starting_8_position
|
|
- starting_9_id
|
|
- starting_9_position
|
|
|
|
- Calculated values from previous games
|
|
- win_streak
|
|
- loss_streak
|
|
- game_date
|
|
- day_of_weeki
|
|
- length_in_outs
|
|
- day_night
|
|
- completion_info
|
|
- forfeit
|
|
- protest
|
|
- park_id
|
|
- attendence
|
|
- length_in_minutes
|
|
- hits
|
|
- doubles
|
|
- triples
|
|
- homeruns
|
|
- rbis
|
|
- sacrifice_hits
|
|
- sacrifice_flies
|
|
- hit_by_pitch
|
|
- walks
|
|
- intentional_walks
|
|
- strikeouts
|
|
- stolen_bases
|
|
- caught_stealing
|
|
- grounded_double
|
|
- interference
|
|
- left_on_base
|
|
- pitchers_used
|
|
- individual_earned_runs
|
|
- earned_runs
|
|
- wild_pitches
|
|
- balks
|
|
- putouts
|
|
- assists
|
|
- errors
|
|
- passed
|
|
- double_play
|
|
- triple_play
|
|
- game_num
|
|
- manager_id
|
|
- starting_pitcher_id
|
|
- starting_1_id
|
|
- starting_1_position
|
|
- starting_2_id
|
|
- starting_2_position
|
|
- starting_3_id
|
|
- starting_3_position
|
|
- starting_4_id
|
|
- starting_4_position
|
|
- starting_5_id
|
|
- starting_5_position
|
|
- starting_6_id
|
|
- starting_6_position
|
|
- starting_7_id
|
|
- starting_7_position
|
|
- starting_8_id
|
|
- starting_8_position
|
|
- starting_9_id
|
|
- starting_9_position
|
|
|
|
- Output
|
|
- 0 home team wins, 1 visiting team wins
|
|
"""
|
|
|
|
select_upcoming_game = """
|
|
SELECT
|
|
games.id,
|
|
|
|
games.game_date, games.game_number,
|
|
games.day_of_week, games.day_night,
|
|
games.home_plate_ump_id,
|
|
games.b1_ump_id, games.b2_ump_id, games.b3_ump_id,
|
|
games.lf_ump_id, games.rf_ump_id,
|
|
|
|
parks.park_id,
|
|
parks.lf_fence_distance, parks.lf_fence_height,
|
|
parks.ct_fence_distance, parks.ct_fence_height,
|
|
parks.rf_fence_distance, parks.rf_fence_height,
|
|
parks.has_roof, parks.elevation,
|
|
parks.latitude, parks.longitude,
|
|
|
|
weather.temperature, weather.humidity, weather.dew_point,
|
|
weather.apparent_temperature, weather.air_pressure,
|
|
weather.precipitation, weather.rain, weather.snowfall,
|
|
weather.cloud_cover,
|
|
weather.wind_speed, weather.wind_direction, weather.wind_gusts,
|
|
weather.sun_rise, weather.sun_set, weather.moon_phase
|
|
|
|
FROM
|
|
games
|
|
|
|
LEFT JOIN parks ON parks.park_id = games.park_id
|
|
LEFT JOIN weather ON weather.game_id = games.id
|
|
|
|
WHERE
|
|
games.game_date = ? AND games.game_number = ? AND games.park_id = ?
|
|
"""
|
|
|
|
curr_game = database.select(select_upcoming_game, [game_date, game_number, park_id])
|
|
if curr_game is None:
|
|
print(f"Failed to get game data for date: {game_date}, number: {game_number}, park: {park_id}")
|
|
return None
|
|
|
|
print(curr_game)
|
|
|
|
select_teams = """
|
|
SELECT
|
|
game_num, manager_id, starting_pitcher_id,
|
|
starting_1_id, starting_1_position,
|
|
starting_2_id, starting_2_position,
|
|
starting_3_id, starting_3_position,
|
|
starting_4_id, starting_4_position,
|
|
starting_5_id, starting_5_position,
|
|
starting_6_id, starting_6_position,
|
|
starting_7_id, starting_7_position,
|
|
starting_8_id, starting_8_position,
|
|
starting_9_id, starting_9_position
|
|
WHERE
|
|
game = ?
|
|
"""
|
|
|
|
curr_team_game = database.selectall(select_teams, [curr_game[0]])
|
|
|
|
if curr_game.len() != 2:
|
|
print(f"Got the wrong number of games {curr_game.len()}")
|
|
return None
|
|
|
|
select_previous_games = """
|
|
SELECT
|
|
- win_streak
|
|
- loss_streak
|
|
- game_date
|
|
- day_of_weeki
|
|
- length_in_outs
|
|
- day_night
|
|
- completion_info
|
|
- forfeit
|
|
- protest
|
|
- park_id
|
|
- attendence
|
|
- length_in_minutes
|
|
- hits
|
|
- doubles
|
|
- triples
|
|
- homeruns
|
|
- rbis
|
|
- sacrifice_hits
|
|
- sacrifice_flies
|
|
- hit_by_pitch
|
|
- walks
|
|
- intentional_walks
|
|
- strikeouts
|
|
- stolen_bases
|
|
- caught_stealing
|
|
- grounded_double
|
|
- interference
|
|
- left_on_base
|
|
- pitchers_used
|
|
- individual_earned_runs
|
|
- earned_runs
|
|
- wild_pitches
|
|
- balks
|
|
- putouts
|
|
- assists
|
|
- errors
|
|
- passed
|
|
- double_play
|
|
- triple_play
|
|
- game_num
|
|
- manager_id
|
|
- starting_pitcher_id
|
|
- starting_1_id
|
|
- starting_1_position
|
|
- starting_2_id
|
|
- starting_2_position
|
|
- starting_3_id
|
|
- starting_3_position
|
|
- starting_4_id
|
|
- starting_4_position
|
|
- starting_5_id
|
|
- starting_5_position
|
|
- starting_6_id
|
|
- starting_6_position
|
|
- starting_7_id
|
|
- starting_7_position
|
|
- starting_8_id
|
|
- starting_8_position
|
|
- starting_9_id
|
|
- starting_9_position
|
|
"""
|