Adding moon and sun phases
This commit is contained in:
@@ -2,7 +2,7 @@ import os
|
||||
import csv
|
||||
import shutil
|
||||
from data.db_connect import Database
|
||||
from data.build_weather import get_weather
|
||||
from data.build_weather import get_weather, get_sun_and_moon_phase
|
||||
|
||||
class Importer:
|
||||
def __init__(self, database: Database):
|
||||
@@ -191,8 +191,11 @@ class Importer:
|
||||
self.database.insert(insert_team_game, visiting_team_data)
|
||||
self.database.insert(insert_team_game, home_team_data)
|
||||
|
||||
parkid = game_stats["park-id"]
|
||||
print(f"SELECT latitude, longitude FROM parks WHERE park_id = {parkid}")
|
||||
park_data = self.database.select("SELECT latitude, longitude FROM parks WHERE park_id = ?", (game_stats["park-id"],))
|
||||
|
||||
print(f"latlon {park_data}")
|
||||
|
||||
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"]
|
||||
@@ -202,10 +205,10 @@ class Importer:
|
||||
(
|
||||
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
|
||||
precipitation, rain, snowfall,
|
||||
cloud_cover, wind_speed, wind_direction,
|
||||
wind_gusts, sun_rise, sun_set,
|
||||
moon_phase
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
@@ -214,11 +217,17 @@ class Importer:
|
||||
?, ?, ?,
|
||||
?, ?, ?,
|
||||
?, ?, ?,
|
||||
?, ?
|
||||
?,
|
||||
)
|
||||
"""
|
||||
|
||||
(sunrise_time, sunset_time, moonphase) = get_sun_and_moon_phase(park_data[0], park_data[1], game_stats["date"])
|
||||
|
||||
weather_data = [
|
||||
game_id, historic_weather["temperature_2m"][hour], historic_weather["relative_humidity_2m"][hour],
|
||||
|
||||
historic_weather["dew_point_2m"][hour], historic_weather["apparent_temperature"][hour], historic_weather["pressure_msl"][hour],
|
||||
historic_weather["precipitation"][hour], historic_weather["rain"][hour], historic_weather["snowfall"][hour],
|
||||
historic_weather["cloud_cover"][hour], historic_weather["wind_speed_10m"][hour], historic_weather["wind_direction_10m"][hour],
|
||||
historic_weather["wind_gusts_10m"][hour], sunrise_time, sunset_time,
|
||||
moonphase,
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user