Skip to content

Commit

Permalink
Fix for sparkline statistic
Browse files Browse the repository at this point in the history
  • Loading branch information
dominiek committed Nov 9, 2008
1 parent 489cb73 commit 8e3f84f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/models/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,16 @@ def common_activity_hours_graph_url
end

def activity_summary_sparkline_url
data = []
data = {}
self.posts.find(:all,
:select => 'COUNT(posts.id) AS num_posts, published_at',
:conditions => ['posts.published_at > ?', 2.weeks.ago],
:group => "DATE_FORMAT(posts.published_at, '%Y-%m-%d')").each do |post|
data << post.num_posts.to_i
data[post.published_at.beginning_of_day] = post.num_posts.to_i
end
data = data.to_a
data.sort! { |a,b| a.first <=> b.first }
data = data.collect { |d| d.last }
peak = data.max
data = data.collect { |p| ((p/peak.to_f)*100).ceil }
"http://chart.apis.google.com/chart?chs=200x80&chd=t:#{data.join(',')}&cht=ls"
Expand Down

0 comments on commit 8e3f84f

Please sign in to comment.