Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
#!/usr/bin/env ruby require 'rubygems' require 'fastercsv' require 'gruff' require 'pp' def random_color colors = %w(green blue red orange yellow puple) colors[rand(colors.length)] end date_re = "[0-9]{2,}" data = FasterCSV.read('/Users/kastner/Documents/downloads/adsense_aj.csv', :headers => true, :col_sep => "\t") i = 0 months = data.inject(Hash.new(0)) do |hash, line| i += 1 if line["Date"].match(date_re) month = Date.parse(line["Date"]).strftime("%m/%y") hash[month] = i end hash end labels = Hash[*months.collect{|k,v| [v,k]}.flatten] ["Page impressions", "Clicks", "Page CTR", "Page eCPM", "Earnings"].each do |key| g = Gruff::Line.new("1100x700") g.title = key g.labels = labels g.baseline_color = random_color key_data = data.collect { |line| line[key].to_f if line["Date"].match(date_re) } key_data = key_data.find_all{ |y| y } g.data(key, key_data) g.write "adsense_#{key.downcase.gsub(/\s/,'_')}.png" puts "#{key} done." end
This paste will be private.
From the Design Piracy series on my blog: