Skip to content

Commit

Permalink
Fixed format issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansurf committed Jul 24, 2024
1 parent 72e5204 commit ce99a4f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
5 changes: 4 additions & 1 deletion docs/structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ More in-depth structure:
.
├── compose.yaml
├── CONTRIBUTING.md
├── dist
│   ├── cli_surf-0.1.0-py3-none-any.whl
│   └── cli_surf-0.1.0.tar.gz
├── Dockerfile
├── docs
│   ├── cheat_sheet.md
Expand Down Expand Up @@ -73,6 +76,6 @@ More in-depth structure:
├── test_helper.py
└── test_server.py
9 directories, 38 files
10 directories, 40 files
```
<!-- STRUCTURE END -->
19 changes: 16 additions & 3 deletions src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ def forecast(lat, long, decimal, days=0):
retry_session = retry(cache_session, retries=5, backoff_factor=0.2)
openmeteo = openmeteo_requests.Client(session=retry_session)

url = "https://marine-api.open-meteo.com/v1/marine"
# First URL is the marine API. Second is for general weather/UV index
urls = (
"https://marine-api.open-meteo.com/v1/marine",
"https://api.open-meteo.com/v1/forecast",
)
params = {
"latitude": lat,
"longitude": long,
Expand All @@ -172,9 +176,14 @@ def forecast(lat, long, decimal, days=0):
"timezone": "auto",
"forecast_days": days,
}
responses = openmeteo.weather_api(url, params=params)

params_uv = {"latitude": lat, "longitude": long, "daily": "uv_index_max"}

responses = openmeteo.weather_api(urls[0], params=params)
responses_uv = openmeteo.weather_api(urls[1], params=params_uv)

response = responses[0]
response_uv = responses_uv[0]

daily_height_max = helper.round_decimal(
response.Daily().Variables(0).ValuesAsNumpy(), decimal
Expand All @@ -186,6 +195,10 @@ def forecast(lat, long, decimal, days=0):
response.Daily().Variables(2).ValuesAsNumpy(), decimal
)

daily_uv_index_max = helper.round_decimal(
response_uv.Daily().Variables(0).ValuesAsNumpy(), decimal
)

daily_data = {
"date": pd.date_range(
start=pd.to_datetime(response.Daily().Time(), unit="s", utc=True),
Expand All @@ -194,12 +207,12 @@ def forecast(lat, long, decimal, days=0):
inclusive="left",
)
}

return [
daily_height_max,
daily_direction_dominant,
daily_period_max,
daily_data["date"],
daily_uv_index_max,
]


Expand Down
5 changes: 4 additions & 1 deletion src/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ def print_forecast(ocean, forecast):
print("Wave Direction: ", day[1])
if int(ocean["show_period"]) == 1:
print("Wave Period: ", day[2])
if int(ocean["show_uv"]) == 1:
print("UV Index: ", day[4])
print("\n")


Expand Down Expand Up @@ -248,7 +250,7 @@ def forecast_to_json(data, decimal):
"""
Takes forecast() as input and returns it in JSON format
"""
surf_height, swell_direction, swell_period, dates = data
surf_height, swell_direction, swell_period, dates, uv_index = data

# Formatting into JSON
forecasts = []
Expand All @@ -258,6 +260,7 @@ def forecast_to_json(data, decimal):
"surf height": round(float(surf_height[i]), decimal),
"swell direction": round(float(swell_direction[i]), decimal),
"swell period": round(float(swell_period[i]), decimal),
"uv index": round(float(uv_index[i]), decimal),
}
forecasts.append(forecast)

Expand Down

1 comment on commit ce99a4f

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
src
   __init__.py00100% 
   api.py105694%30, 48, 70–71, 103–104
   art.py9367%24–25, 37
   cli.py23483%34, 50–51, 55
   gpt.py10640%16–21, 32–45
   helper.py1576062%53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 91, 102–106, 132, 134, 136, 145–155, 167, 180–181, 199–201, 211, 213–214, 236–237, 275–285, 292–300
   send_email.py24240%5–48
   server.py41410%5–82
   settings.py220100% 
TOTAL39114463% 

Tests Skipped Failures Errors Time
9 0 💤 0 ❌ 0 🔥 14.900s ⏱️

Please sign in to comment.