Modified:
trunk/seb/app/controllers/stats_controller.rb
trunk/seb/app/models/item.rb
trunk/seb/app/views/stats/summary.rhtml
trunk/seb/public/images/seb_header.png
Log:
adding a "per month" graph
Modified: trunk/seb/app/controllers/stats_controller.rb
==============================================================================
--- trunk/seb/app/controllers/stats_controller.rb (original)
+++ trunk/seb/app/controllers/stats_controller.rb Tue Apr 15 11:26:27 2008
@@ -7,7 +7,8 @@
end
def summary
- @graph = open_flash_chart_object(600,300, '/stats/per_day.html', false)
+ @graph = open_flash_chart_object(600,300, '/stats/per_day.html', false)
+ @months =
open_flash_chart_object(600,300, '/stats/per_month,html', false)
end
def per_day
@@ -32,19 +33,24 @@
def per_month
@item_counts=[]
@date_labels=[]
- 1.upto(30) do |i|
- t=Time.now.at_midnight-60*60*24*i
- @item_counts[30-i]=Item.date_count(t)
- @date_labels[30-i]=(Date.today-i+1).to_s
+ now=DateTime.now
+ 2007.upto(now.year) do |i|
+ 1.upto(12) do |j|
+ if i<now.year || j<now.month
+ @item_counts<<Item.month_count(i,j)
+ @date_labels <<DateTime.new(i,j,1).strftime("%b %Y")
+ end
+ end
end
g = Graph.new
- g.title("Posts per Day", '{font-size: 26px;}')
+ g.title("Posts per Month", '{font-size: 26px;}')
g.set_data(@item_counts)
g.line(2,'0x80a033','Posts', 10)
g.set_x_labels(@date_labels)
- g.set_x_label_style( 10, '#CC3399', 2 );
- g.set_y_max(200)
- g.set_y_label_steps(8)
+ g.set_x_label_style( 10, '#CC3399', 2 )
+ @top=@item_counts.max/250+1
+ g.set_y_max(@top*250)
+ g.set_y_label_steps(@top)
render :text => g.render
end
Modified: trunk/seb/app/models/item.rb
==============================================================================
--- trunk/seb/app/models/item.rb (original)
+++ trunk/seb/app/models/item.rb Tue Apr 15 11:26:27 2008
@@ -18,6 +18,10 @@
Item.find(:all, :conditions=>"pubDate<='#{date.tomorrow.to_s(:db)}'
and pubDate>='#{date.to_s(:db)}'").length rescue 0
end
+ def Item.month_count(year,month)
+ Item.find(:all, :conditions=>["month(pubDate)=? and
year(pubDate)=?",month,year]).length rescue 0
+ end
+
def Item.time_of_day_count(hour)
Item.find(:all, :conditions=>"HOUR(TIME(pubDate))='#{hour}'").length
rescue 0
end
Modified: trunk/seb/app/views/stats/summary.rhtml
==============================================================================
--- trunk/seb/app/views/stats/summary.rhtml (original)
+++ trunk/seb/app/views/stats/summary.rhtml Tue Apr 15 11:26:27 2008
@@ -1,2 +1,3 @@
<h1> Scotedublogs Statistics</h1>
<div class="stat_image"><%= @graph %></div>
+<div class="stat_image"><%= @months %></div>
Modified: trunk/seb/public/images/seb_header.png
==============================================================================
Binary files. No diff available.