Automatic Trip Weather
You can see it in action at: https://automatic-weather.herokuapp.com
Once you have access to these, you will want to add your credentials to the
cp .env.sample .env
And fill in your credentials for each of those services.
Developing with this locally will require you to be able to Sign in with Automatic. In order to achieve this, you can use ngrok to specify your Automatic Client URLs.
Next you will want to:
# Install application dependencies bundle install # Install ui dependencies bundle exec rake bower:install
Now your application should be ready to boot up:
# Start it with Unicorn bundle exec foreman start # Start it with Rails bundle exec rails server
If you are using
ngrok, you can start that up with:
Specify the port your application runs on
Now you should be able to view your application in the browser, sign in with Automatic, and see your trips.
I also keep my Forecast.io developer page up to ensure I am not exceeding my daily limits. You can see this in their Developer console or by viewing your HTTP requests in the log to see their
In order to view this application you need to register for a Dark Sky Forecast API account and get your API Key.
Next you need to ensure you have an Automatic API
Client setup and have a
How does it work
The application currently only shows your last week's worth of trip data. We leave it as an exercise to the reader to allow pagination back through more data. We achieve this by using Automatic's filtering on Trips, and specifying a
Once we have the trips, we focus in on the data we want to render to the interface.
Often times shorter trips have both a start and end in the same city, and within the same hour. In this case we didn't want to make duplicate calls to the Forecast.io API. We create a simple
CacheStore that only needs to geocode and request if we don't already have a stored key for the city, state, and datetime. We compute a checksum from those values to reference as our cache key.
CacheStoreis single request based only. It does not keep a memory cache. This is an exercise left to the reader.
We wanted to show trips grouped by their day. Our
Trip records have a
end_location, and we wanted the weather for both of those points. A trip could span over the time of 2 days or multiple timezones. Our first iteration groups all of the trips by their timestamp of
Once we have iterated through our trips, we push them into a new data structure and Presenter that is then passed on to the Interface.
The beautiful weather icons are provided by Erik Flowers
Here are some other things that could be done to enhance the application.
- Extract the coordinates from the
polylineand plot out the weather for the entire trip.
- Show other pieces of weather information
- Allow you to paginate by days of trips, to keep going back in time.
- Integrate the weather with the Automatic webhooks data to show weather for a given event.
- Cache the weather data in a database or memory store to prevent API calls to the Forecast.io service.
This project is licensed under the terms of the Apache 2.0 license.