Skip to content

Commit

Permalink
cleaned up code in helper.py forecast_to_json()
Browse files Browse the repository at this point in the history
  • Loading branch information
n-strong committed Dec 7, 2024
1 parent 1a97636 commit 6869637
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,10 @@ def set_location(location):


def forecast_to_json(forecast_data, decimal):
"""
Takes forecast_data from forecast() as input
and returns it in JSON format
"""
# Formatting into JSON
forecasts = []
for i in range(len(forecast_data["date"])):
forecast = {
"date": str(forecast_data["date"][i].date()),
for i, d in enumerate(forecast_data["date"]):
forecasts.append({
"date": str(d.date()),
"surf height": round(
float(forecast_data["wave_height_max"][i]), decimal
),
Expand All @@ -370,23 +365,29 @@ def forecast_to_json(forecast_data, decimal):
"temperature_2m_min": round(
float(forecast_data["temperature_2m_min"][i]), decimal
),
"rain_sum": round(float(forecast_data["rain_sum"][i]), decimal),
"rain_sum": round(
float(forecast_data["rain_sum"][i]), decimal
),
"daily_precipitation_probability": round(
float(forecast_data["precipitation_probability_max"][i]),
decimal,
float(
forecast_data["precipitation_probability_max"][i]
),
decimal
),
"wind_speed_max": round(
float(forecast_data["wind_speed_10m_max"][i]), decimal
),
"wind_direction_10m_dominant": round(
float(forecast_data["wind_direction_10m_dominant"][i]), decimal
float(
forecast_data["wind_direction_10m_dominant"][i]
),
decimal
),
}
forecasts.append(forecast)

})
return forecasts



def surf_summary(surf_data):
"""
Outputs a simple summary of the surf data.
Expand Down

0 comments on commit 6869637

Please sign in to comment.