Skip to content

Instantly share code, notes, and snippets.

@adamlwalker
Created February 10, 2015 19:29
Show Gist options
  • Select an option

  • Save adamlwalker/66daab19aff67104c183 to your computer and use it in GitHub Desktop.

Select an option

Save adamlwalker/66daab19aff67104c183 to your computer and use it in GitHub Desktop.
require 'csv'
unique_count = {}
total_count = {}
CSV.foreach('Lead_Source_Report.csv', :headers => true) do |total|
total_count[total[9]] ||= 0
total_count[total[9]] += 1
end
CSV.foreach('Lead_Source_Report.csv', :headers => true) do |row|
unique_count[row[9]] ||= 0
if row[7].include? 'Won'
unique_count[row[9]] += 1
elsif row[7].include? 'Promised'
unique_count[row[9]] += 1
elsif row[7].include? 'Qualified'
unique_count[row[9]] += 1
end
end
unique_count.each do |val,count|
if count > 0
total = total_count[val]
rate = count .to_f / total.to_f * 100
rate = rate.round
puts "#{val} appears #{total} time(s) and was successful #{count} times in this cycle. #{rate}% success rate"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment