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('analytics@email.com', '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