Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update weather API to Tomorrowio #689

Merged
merged 10 commits into from
Jan 4, 2024
Merged

Update weather API to Tomorrowio #689

merged 10 commits into from
Jan 4, 2024

Conversation

cwille97
Copy link
Collaborator

Resolves #535

Context

The Dark Sky API has been completely shut down for some time now so we are migrating to Tomorrow.io to bring back weather data for users.

Approach

I first wrote a small wrapper for the API in Ruby and created a gem for that. This PR removes the old Dark Sky gem and adds my new gem and refactors the weather retriever service to use the new API. By and large the data is mostly backwards compatible with a few exceptions noted below. Notably, it was not necessary to change the Geolocation API since that is still in use. There were some previous reports of getting the wrong weather data for a given location, so it's possible we may still want to replace the Geolocation API (possibly with the browser geolocation API if that continues to be a problem.

Exceptions to backwards compatibility

  • This API uses a totally different icon system. I attempted to translate their icon codes into our current icons, however in some cases the best approximation is not very good (i.e. for "thunderstorms" the only option I could pick from is "cloudy"). It would likely improve the user experience to pull in their icon system (assets found here), while keeping the old icons around for backwards compatibility with existing data.
  • Precipitation intensity is calculated slightly differently here. In DarkSky, they just gave one precipitation intensity value whereas Tomorrow gives one for rain, one for sleet, and one for snow. My best guess was to sum these up to make a total precipitation value.
  • Tomorrow does not provide a text based summary like Dark Sky did. I made a best approximation of recreating that by combining information from the weather code, as well as the temperature to touch on the core weather attributes for that day in a concise summary. Though I'm open to other suggestions here.

Tests

Tests to follow, I need to familiarize myself with the VCR package being used here as well as generate the requisite API data for that. Just want to put up an initial draft PR to get some feedback on this so far.

Other resources

Expand for API translations that I came up with

Dark Sky (Forecast API wrapper) Tomorrow.io Notes
Humidity humidityAvg
Icon weatherCode Translating Tomorrow weather codes into the most applicable existing icon
precipIntensity rainIntensityAvg, sleetIntensityAvg, snowIntensityAvg DarkSky had 1 value for this and my best guess was to sum these 3
pressure pressureSurfaceLevelAvg DarkSky uses sea level, Tomorrow uses surface level pressure
summary N/A I attempted to recreate this value by including information from the weatherCode and the temperature
temperatureMin temperatureMin DarkSky defaulted to Kelvin
temperatureMax temperatureMax DarkSky defaulted to Kelvin

@cwille97 cwille97 marked this pull request as draft October 21, 2023 20:00
backend/Gemfile Outdated
# wrapper for forecast.io API, Dark Sky
gem "forecast_io"
# wrapper for tomorrow.io API
gem "tomorrowio_rb"
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice parallelism

@@ -1,6 +1,6 @@
class WeatherRetriever
class << self
def get(date, postal_code)
def get(date, latitude, longitude)
Copy link
Collaborator

Choose a reason for hiding this comment

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

ncie to not have to go thru postal code for this api

Choose a reason for hiding this comment

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

doesn't this break the code below? the method expects postal_code in a few places

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Whoops, yeah I meant to remove postal_code in those places and replace it with coordinates.


if the_day.blank?
Rails.logger.warn "No forecast found for position #{position.inspect}: #{forecast.inspect}"
if forecast.status != 200
Copy link
Collaborator

Choose a reason for hiding this comment

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

makes sense 200

forecast
end

def create_weather(the_day, position_id)
def create_weather(forecast, position_id)
today = forecast.body["timelines"]["daily"][0]
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: maybe use "dig" for json safety?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, I'm pretty unfamiliar with Ruby and did not know about dig, I will look into that further and make some changes.

)
end

def get_icon_legacy(today)
# Our icons do not coverage their full range of weather codes. We could pull in their icons (linked below) on the frontend to expand options
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice

@compwron
Copy link
Collaborator

I am excited for this to go thru!

@cwille97 cwille97 marked this pull request as ready for review December 11, 2023 19:04
@compwron compwron merged commit 0d25d2d into master Jan 4, 2024
9 checks passed
@compwron compwron deleted the fix-weather-api branch January 4, 2024 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Weather API is end-of-life
3 participants