Retrieving a single game and the teams associated with it
This commit is contained in:
132
data/get_data.py
132
data/get_data.py
@@ -1,4 +1,7 @@
|
||||
def pull_training_data():
|
||||
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
|
||||
|
||||
"""
|
||||
@@ -211,4 +214,129 @@ def pull_training_data():
|
||||
- 0 home team wins, 1 visiting team wins
|
||||
"""
|
||||
|
||||
pass
|
||||
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
|
||||
"""
|
||||
|
||||
14
main.py
14
main.py
@@ -1,8 +1,10 @@
|
||||
import numpy as np # helps with the math
|
||||
import matplotlib.pyplot as plt # to plot error during training
|
||||
|
||||
from data.get_data import pull_training_data
|
||||
from data.db_connect import Database
|
||||
from data.stats_importer import Importer
|
||||
from data.build_weather import get_weather, get_sun_and_moon_phase
|
||||
from data.stats_importer import Importer
|
||||
|
||||
# input data
|
||||
inputs = np.array([[0, 0, 1, 0],
|
||||
@@ -15,19 +17,23 @@ inputs = np.array([[0, 0, 1, 0],
|
||||
outputs = np.array([[0], [0], [0], [1], [1], [1]])
|
||||
|
||||
if __name__ == '__main__':
|
||||
db_file = "./database/baseball.db"
|
||||
db_conn = Database(db_file)
|
||||
|
||||
pull_training_data(db_conn, "20240602", 0, "BAL12")
|
||||
|
||||
"""
|
||||
build_db_path = "./data/sql/build_db.sql"
|
||||
fill_parks_path = "./data/sql/prefill_parks.sql"
|
||||
fill_teams_path = "./data/sql/prefill_teams.sql"
|
||||
|
||||
db_file = "./database/baseball.db"
|
||||
db_conn = Database(db_file)
|
||||
|
||||
db_conn.run_sql_file(build_db_path)
|
||||
db_conn.run_sql_file(fill_parks_path)
|
||||
db_conn.run_sql_file(fill_teams_path)
|
||||
|
||||
imp = Importer(db_conn)
|
||||
imp.parse_all_data("./data/stats/to_import", "./data/stats/imported/")
|
||||
"""
|
||||
|
||||
"""
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user