Started adding weather code
This commit is contained in:
@@ -2,6 +2,7 @@ import os
|
||||
import csv
|
||||
import shutil
|
||||
from data.db_connect import Database
|
||||
from data.build_weather import get_weather
|
||||
|
||||
class Importer:
|
||||
def __init__(self, database: Database):
|
||||
@@ -71,6 +72,19 @@ class Importer:
|
||||
)
|
||||
"""
|
||||
|
||||
game_data = [
|
||||
game_stats["date"], game_stats["num-of-game"], game_stats["day-of-week"],
|
||||
game_stats["length-in-outs"], game_stats["day-night"], game_stats["completion-info"],
|
||||
game_stats["forfeit"], game_stats["protest"], game_stats["park-id"],
|
||||
game_stats["attendance"], game_stats["length-in-min"], game_stats["home-plate-ump-id"],
|
||||
game_stats["home-plate-ump-name"], game_stats["1b-plate-ump-id"], game_stats["1b-plate-ump-name"],
|
||||
game_stats["2b-plate-ump-id"], game_stats["2b-plate-ump-name"], game_stats["3b-plate-ump-id"],
|
||||
game_stats["3b-plate-ump-name"], game_stats["lf-plate-ump-id"], game_stats["lf-plate-ump-name"],
|
||||
game_stats["rf-plate-ump-id"], game_stats["rf-plate-ump-name"],
|
||||
]
|
||||
|
||||
game_id = self.database.insert(insert_game, game_data)
|
||||
|
||||
insert_team_game = """
|
||||
INSERT INTO team_game
|
||||
(
|
||||
@@ -124,19 +138,6 @@ class Importer:
|
||||
)
|
||||
"""
|
||||
|
||||
game_data = [
|
||||
game_stats["date"], game_stats["num-of-game"], game_stats["day-of-week"],
|
||||
game_stats["length-in-outs"], game_stats["day-night"], game_stats["completion-info"],
|
||||
game_stats["forfeit"], game_stats["protest"], game_stats["park-id"],
|
||||
game_stats["attendance"], game_stats["length-in-min"], game_stats["home-plate-ump-id"],
|
||||
game_stats["home-plate-ump-name"], game_stats["1b-plate-ump-id"], game_stats["1b-plate-ump-name"],
|
||||
game_stats["2b-plate-ump-id"], game_stats["2b-plate-ump-name"], game_stats["3b-plate-ump-id"],
|
||||
game_stats["3b-plate-ump-name"], game_stats["lf-plate-ump-id"], game_stats["lf-plate-ump-name"],
|
||||
game_stats["rf-plate-ump-id"], game_stats["rf-plate-ump-name"],
|
||||
]
|
||||
|
||||
game_id = self.database.insert(insert_game, game_data)
|
||||
|
||||
visiting_team_data = [
|
||||
game_id, game_stats["visiting-team"], game_stats["visiting-game-num"],
|
||||
game_stats["visiting-score"], game_stats["visiting-line-scores"], game_stats["visiting-at-bats"],
|
||||
@@ -189,3 +190,35 @@ class Importer:
|
||||
|
||||
self.database.insert(insert_team_game, visiting_team_data)
|
||||
self.database.insert(insert_team_game, home_team_data)
|
||||
|
||||
park_data = self.database.select("SELECT latitude, longitude FROM parks WHERE park_id = ?", (game_stats["park-id"],))
|
||||
|
||||
hour = 15 if game_stats["day-night"] == "D" else 19
|
||||
historic_weather = get_weather(park_data[0], park_data[1], game_stats["date"], hour)
|
||||
historic_weather = historic_weather["hourly"]
|
||||
|
||||
insert_into_weather = """
|
||||
INSERT INTO weather
|
||||
(
|
||||
game_id, temperature, humidity,
|
||||
dew_point, apparent_temperature, air_pressure,
|
||||
wind_speed, precipitation, rain,
|
||||
snowfall, cloud_cover, wind_speed,
|
||||
wind_direction, wind_gusts, sun_rise,
|
||||
sin_set, moon_phase
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
?, ?, ?,
|
||||
?, ?, ?,
|
||||
?, ?, ?,
|
||||
?, ?, ?,
|
||||
?, ?, ?,
|
||||
?, ?
|
||||
)
|
||||
"""
|
||||
|
||||
weather_data = [
|
||||
game_id, historic_weather["temperature_2m"][hour], historic_weather["relative_humidity_2m"][hour],
|
||||
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user