Skip to content

Instantly share code, notes, and snippets.

@jolexa
Last active December 28, 2015 02:00
Show Gist options
  • Save jolexa/e18decc20df37cb79115 to your computer and use it in GitHub Desktop.
Save jolexa/e18decc20df37cb79115 to your computer and use it in GitHub Desktop.
Simple, hacky ruby script to parse csv and provide a number for 2015
#!/usr/bin/ruby
# Tested with ruby-2.0
# 1) Download CSV file with workout data
# 2) run this script as './2015-lifting-totals.rb <path to csv file>
require 'csv'
# Ugly HACK!
`grep ^2015 "#{ARGV[0]}" > /tmp/data.csv`
lbs = 0
CSV.foreach("/tmp/data.csv", converters: :numeric) do |row|
volume = row[2] * row[4]
#puts "Volume for #{row[1]} on #{row[0]} was: #{volume}"
lbs += volume
end
# http://codereview.stackexchange.com/a/28100
whole, decimal = lbs.to_s.split(".")
whole_with_commas = whole.chars.to_a.reverse.each_slice(3).map(&:join).join(",").reverse
newlbs = [whole_with_commas, decimal].compact.join(".")
puts "2015 Volume is: #{newlbs}"
`rm -f /tmp/data.csv`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment