Skip to content

Instantly share code, notes, and snippets.

@andrew
Created April 25, 2009 12:32
Show Gist options
  • Save andrew/101606 to your computer and use it in GitHub Desktop.
Save andrew/101606 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'garb' # http://github.com/vigetlabs/garb/
require 'sparklines' # http://github.com/topfunky/sparklines
Garb::Session.login('[email protected]', 'password')
site = Garb::Profile.all.first
days = []
length = 86400
puts "Generating graph of hits on #{site.title} homepage over last month"
30.times do |day|
r = Garb::Report.new(site)
r.metrics << :pageviews
r.dimensions << :request_uri
r.filters << {:request_uri.eql => '/'}
r.start_date = Time.now - (length*day)
r.end_date = Time.now - (length*(day-1))
days << r.all.first.pageviews.to_i
end
graph = Sparklines.plot(days, :type => 'smooth', :height => 20, :step => 1, :line_color => '#0080FF')
graph_file = File.new("graph.jpg", "w")
graph_file.write(graph)
graph_file.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment