Adding win and if the team is home to the database, calculations for win and lose streak, and returning the training data. Fixing sunrise sunset times
This commit is contained in:
189
data/get_data.py
189
data/get_data.py
@@ -211,7 +211,7 @@ def pull_training_data(database: Database, game_date: str, game_number: int, par
|
||||
- starting_9_position
|
||||
|
||||
- Output
|
||||
- 0 home team wins, 1 visiting team wins
|
||||
- 1 home team wins, 0 visiting team wins
|
||||
"""
|
||||
|
||||
select_upcoming_game = """
|
||||
@@ -257,6 +257,7 @@ def pull_training_data(database: Database, game_date: str, game_number: int, par
|
||||
|
||||
select_teams = """
|
||||
SELECT
|
||||
win, team, home,
|
||||
game_num, manager_id, starting_pitcher_id,
|
||||
starting_1_id, starting_1_position,
|
||||
starting_2_id, starting_2_position,
|
||||
@@ -267,76 +268,138 @@ def pull_training_data(database: Database, game_date: str, game_number: int, par
|
||||
starting_7_id, starting_7_position,
|
||||
starting_8_id, starting_8_position,
|
||||
starting_9_id, starting_9_position
|
||||
FROM
|
||||
team_game
|
||||
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()}")
|
||||
if len(curr_team_game) != 2:
|
||||
print(f"Got the wrong number of games {len(curr_team_game)}")
|
||||
return None
|
||||
|
||||
training_result = (curr_team_game[0][0] == 1 and curr_team_game[0][2] == 1)
|
||||
|
||||
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
|
||||
games.id,
|
||||
|
||||
games.game_date, games.game_number,
|
||||
games.day_of_week, games.day_night,
|
||||
games.length_in_outs, games.completion_info,
|
||||
games.forfeit, games.protest,
|
||||
games.attendence, games.length_in_minutes,
|
||||
|
||||
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,
|
||||
|
||||
team_game.game_num, team_game.score,
|
||||
team_game.line_score, team_game.win,
|
||||
team_game.hits, team_game.doubles, team_game.triples,
|
||||
team_game.homeruns, team_game.rbis,
|
||||
team_game.sacrifice_hits, team_game.sacrifice_flies,
|
||||
team_game.hit_by_pitch, team_game.walks, team_game.intentional_walks,
|
||||
team_game.strikeouts, team_game.stolen_bases,
|
||||
team_game.caught_stealing, team_game.grounded_double,
|
||||
team_game.interference, team_game.left_on_base,
|
||||
team_game.pitchers_used,
|
||||
team_game.individual_earned_runs, team_game.earned_runs,
|
||||
team_game.wild_pitches, team_game.balks,
|
||||
team_game.putouts, team_game.assists,
|
||||
team_game.errors, team_game.passed,
|
||||
team_game.double_play, team_game.triple_play,
|
||||
team_game.manager_id, team_game.starting_pitcher_id,
|
||||
team_game.starting_1_id, team_game.starting_1_position,
|
||||
team_game.starting_2_id, team_game.starting_2_position,
|
||||
team_game.starting_3_id, team_game.starting_3_position,
|
||||
team_game.starting_4_id, team_game.starting_4_position,
|
||||
team_game.starting_5_id, team_game.starting_5_position,
|
||||
team_game.starting_6_id, team_game.starting_6_position,
|
||||
team_game.starting_7_id, team_game.starting_7_position,
|
||||
team_game.starting_8_id, team_game.starting_8_position,
|
||||
team_game.starting_9_id, team_game.starting_9_position,
|
||||
|
||||
parks.park_id,
|
||||
|
||||
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 team_game ON team_game.game = games.id
|
||||
LEFT JOIN weather ON weather.game_id = games.id
|
||||
|
||||
WHERE
|
||||
games.game_date > ? AND
|
||||
games.game_date < ? AND
|
||||
team_game.team = ?
|
||||
|
||||
ORDER BY team_game.game_num ASC
|
||||
"""
|
||||
|
||||
first_of_the_year = f"{game_date[:4]}0101"
|
||||
select_previous_games_data_0 = [first_of_the_year, game_date, curr_team_game[0][1]]
|
||||
select_previous_games_data_1 = [first_of_the_year, game_date, curr_team_game[1][1]]
|
||||
|
||||
training_data = [*curr_game[1:]]
|
||||
|
||||
training_data = [*training_data, *curr_team_game[0][1:]]
|
||||
prev_games = database.selectall(select_previous_games, select_previous_games_data_0)
|
||||
prev_game_data = [0] * 61
|
||||
if prev_games is not None:
|
||||
prev_win_streak = 0
|
||||
index = len(prev_games) - 1
|
||||
while index > 0 and prev_games[index][20] == 1:
|
||||
prev_win_streak += 1
|
||||
index -= 1
|
||||
|
||||
prev_loss_streak = 0
|
||||
index = len(prev_games) - 1
|
||||
while index > 0 and prev_games[index][20] == 0:
|
||||
prev_loss_streak += 1
|
||||
index -= 1
|
||||
|
||||
index = len(prev_games) - 1
|
||||
prev_game_data = [
|
||||
prev_win_streak,
|
||||
prev_loss_streak,
|
||||
*prev_games[index][1:]
|
||||
]
|
||||
training_data = [*training_data, *prev_game_data]
|
||||
|
||||
training_data = [*training_data, *curr_team_game[1][1:]]
|
||||
prev_games = database.selectall(select_previous_games, select_previous_games_data_1)
|
||||
prev_game_data = [0] * 61
|
||||
if prev_games is not None:
|
||||
prev_win_streak = 0
|
||||
index = len(prev_games) - 1
|
||||
while index > 0 and prev_games[index][20] == 1:
|
||||
prev_win_streak += 1
|
||||
index -= 1
|
||||
|
||||
prev_loss_streak = 0
|
||||
index = len(prev_games) - 1
|
||||
while index > 0 and prev_games[index][20] == 0:
|
||||
prev_loss_streak += 1
|
||||
index -= 1
|
||||
|
||||
index = len(prev_games) - 1
|
||||
prev_game_data = [
|
||||
prev_win_streak,
|
||||
prev_loss_streak,
|
||||
*prev_games[index][1:]
|
||||
]
|
||||
training_data = [*training_data, *prev_game_data]
|
||||
|
||||
print(f"{training_result}\n{training_data}")
|
||||
|
||||
return (training_result, training_data)
|
||||
|
||||
Reference in New Issue
Block a user