Keeping those Sweet Equines Fed During the Long Winter


Sweet e splash


Feeding a proper amount of quality hay during the cold winter months is one of the best ways to help horses keep warm. With a proper winter coat, sufficient water, shelter, and an increased amount of hay based on body weight, a horse can stay healthy in temperatures as low as -40° F.

Sweet Equine provides a feed table based on geographical weather data and horse weight that calculates the amount of hay your animal requires based on current weather conditions.


A Cold Start

After moving from Colorado to Minnesota, where the temperatures frequently hit -40° F in the winters, horse care took on a new meaning. Every morning when it was bitingly cold, my wife and I had to calculate by hand the amount of daily feed based on current temperatures, which varies from horse to horse based on size, and wet/dry coat conditions. The basic formula we are using is based on the University of Minnesota's winter care recommendations, and requires 3 basic inputs: weight, temperature, and wet/dry status. We would have to check the weather, do the basic calculations, and potentially update them once we're outside if one of our horses was sweaty or covered in snow-melt. This usually meant an extra few minutes in the cold and aching fingers as we pulled off our gloves to tap the numbers out on our phones.

In order to save time I built Sweet Equine to solve our pre-coffee math woes. I was also looking for a simple project to create a Ruby on Rails web application from the ground up by myself as a learning tool. I wanted to learn the process of creating a simple login, admin interface, database creation and management, and basic API integration, all of which I encounter frequently with other projects I work on as a front-end engineer, UI/UX designer, or product designer.

In app


A Simple Tool for Health

One of our horses is older and has cushing's(a common pituitary issue with aging equines), so it's very important for his health to receive the proper amount of calories year round, especially when it's cold enough to put stress on his system. We use a hay-net and a hanging fish scale to quickly assess his hay quantities.

We also use the same system for our younger, more active mare. The application was designed to support any size barn, or number of horses regardless of knowledge level.



Keep it Simple, Keep it Free

From the start I wanted to keep this low cast, if not free. I also wanted to use technology that is in heavy use on other projects I work on to learn more about the underlying tools that I rarely touch. I chose to host on Heroku by way of their CLI, create a simple authentication system and scope user permissions and rules, and write helper methods to work with an API. I also used my simple open source front-end framework ThimbleCSS

For geographical weather data, I originally worked with Weather Underground, but moved to OpenWeather later in the project.

I chose to keep login as simple as possible and integrate a one click Google login / sign up solution using a custom omniauth set up.



On the Rail (a good horse pun, I promise!)

I started with the most basic command:

$ rails new

I then initialized my postgres gem and first migration. I've worked some on custom WordPress MySQL builds and PHP apps, but after years with ActiveRecord as a base feature, it feels like a natural way to deal with a database.

With the base app running with initial Rails welcome screen, I turned to my first problem and user interaction: account creation / login. I initially started working with the device gem, and used a plug and play solution for login with Facebook, and Google. Finding the gem a bit unruly to work with, I backed it out and decided to do a simple omniauth / google login. I wanted to control the process, user/login helpers, and write the code based on documentation myself to understand how the Google API and callbacks worked.

Screenshot 2

The next step was creating a form to gather a zip code, which is required to find a user's weather data, and a place for users to add their horses with each animal's weight. A few 'rails generate' scaffolding commands later, I was set up and saving user data to my database.

Once I had basic horse and user information, I built the basic weather table and input dummy hard coded test tables to see how it would look and work.

Under the Weather

The hardest part of the process was finding and integrating with a free weather service. Using OpenWeather, which has a free future forecast 5 days out, hour by hour, I had to create a forecast model with each entry being an hour forecast, then write helper functions to condense the data into a daily forecast that notes rain and wind patterns as well as temperature highs and lows. To ensure the data is the most up to date, I also had to write a rails job to check and update entries every hour.

def weather_forecast
   return @weather_forecast if defined? @weather_forecast

   date = Date.today
   date_end = Date.today + 4.days
   start_date = date.beginning_of_day
   end_date = date_end.end_of_day
   current_forecast = current_user.zip_code.forecasts.where(:dt => start_date..end_date)

   weather_forecast_by_day = current_forecast.group_by{ |t| t.dt.to_date }.sort_by{|e| e[0]}

   wf = Array.new
   weather_forecast_by_day.each do |fp|

       temps = []
       desc = []
       fp[1].each do |day|
           temps << day.temp
           desc << day.weather
       end

       wf << OpenStruct.new(
           'date' => fp[0].strftime("%a, %b %d"),
           'condition_array' => desc,
           'condition' => desc.max_by {|i| desc.count(i)},
           'min_temp' => temps.min,
           'max_temp' => temps.max,
       )
   end

   @weather_forecast = wf
end
helper_method :weather_forecast

Once I had the weather data and helper in hand, I had to output to the front-end table and check my calculations:

if cast.min_temp <= 18
   cold_feed = ((horse.daily_feed.to_f * 0.01) * ( (cast.min_temp - 18) * -1 )).round(1) + horse.daily_feed
else cold_feed = horse.daily_feed
if ( cast.condition_array.include?('Rain') || cast.condition_array.include?('Snow') ) rain_feed = ((horse.daily_feed.to_f * 0.01) * ( (cast.min_temp - 60) * -1 )).round(1) + horse.daily_feed


Screenshot

I'd say this was an easy process, but each stage was wrapped in hours of googling examples, reading documentation, and asking my more experienced developer friends for a nudge in the right direction. I do feel more comfortable running and creating rails database migrations, models, and working with APIs within views, so consider it a great time investment, as well as a great tool I use every day in the winter.




Barn & App Maintenance

Much like our barn, I learned that basic maintenance is a requirement of any app, especially one leaning on outside services. Between winters, I let the application languish, and during that time, the Google login API had changed (deprecated my old method), and Weather Underground eliminated their free tier API. It left me scrambling to run updates and find a replacement before I could use the app after our first bout of cold weather.

I also learned the basic formula I use for cold weather can be modified and used for hot / humid conditions as well. To help with the maintenance and the app in mind, I hope to update the app for hot weather conditions to keep it useful through the summer months. I'd also like to integrate android push notifications as well, so I could just have the newest feed amount pop up every morning.