GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: A simple application written in merb to help you manage ad serving across multiple sites
Clone URL: git://github.com/kneath/greed.git
kneath (author)
Sun May 11 22:18:10 -0700 2008
commit  5f97998a36ef6d4af5a6b18ed73e976b29a17a99
tree    43b24e6fb938e876d6c3a4c7128fce8398df6f44
parent  45bab61ace1174c37cbfeea8c44c83cb0f45fcde
greed / app / helpers / dashboard_helper.rb
100644 28 lines (25 sloc) 1.134 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module Merb
    module DashboardHelper
      def google_bar_graph(collection, x_method, y_method, options = {})
        options[:size] ||= "580x200"
        options[:color] ||= "c6d9fd"
        
        max = collection.max{ |a,b| a.send(y_method) <=> b.send(y_method) }.send(y_method)
        labels = []
        collection.each do |item|
          labels << item.send(x_method)
        end
        
        query = "http://chart.apis.google.com/chart?cht=bvs&chs=#{options[:size]}&chco=#{options[:color]}"
        query << "&chd=t:" + collection.collect{|d| d.send(y_method) }.join(",")
        query << "&chds=0,#{max}"
        query << "&chxt=x,y"
        query << "&chxl=0:|#{labels.join('|')}|1:|0|#{number_with_delimiter max/4}|#{number_with_delimiter max*2/4}|#{number_with_delimiter max*3/4}|#{number_with_delimiter max}"
        query << "&chg=" + [5000, 25, 1, 3].join(',')
        '<img src="' + query + '" alt="Graph" />'
      end
      
      def ctr(clicks, impressions)
        num = clicks.to_f/impressions.to_f*100
        num = 0 if num.nan?
        number_to_percentage(num, :precision => 2)
      end
    end
end