<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>app/controllers/statistics_controller.rb</filename>
    </added>
    <added>
      <filename>app/helpers/statistics_helper.rb</filename>
    </added>
    <added>
      <filename>app/views/statistics/index.html.erb</filename>
    </added>
    <added>
      <filename>test/functional/statistics_controller_test.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,3 +1,11 @@
 class Media &lt; ActiveRecord::Base
   belongs_to :post
+  
+  def big_thumbnail_url
+    if self.thumbnail_url =~ /flickr\.com/
+      self.thumbnail_url.gsub(/_s\.jpg/, '.jpg')
+    else
+      self.embed_url
+    end
+  end
 end
\ No newline at end of file</diff>
      <filename>app/models/media.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,4 @@
+
 class Stream &lt; ActiveRecord::Base
   has_many :posts, :conditions =&gt; 'is_deleted IS FALSE', :order =&gt; 'published_at DESC'
   has_many :articles, 
@@ -38,4 +39,105 @@ class Stream &lt; ActiveRecord::Base
   def self.current
     self.find_or_create_by_id(1)
   end
+  
+  def activity_overview_graph
+    require 'google_chart'
+    # Main Activity Chart
+    GoogleChart::BarChart.new('900x300', &quot;Daily Activity&quot;, :vertical, false) do |bc|
+      data = {}
+      services = []
+      self.posts.find(:all, 
+                         :select =&gt; 'COUNT(posts.id) AS num_posts, service_id, published_at', 
+                         :conditions =&gt; ['posts.published_at &gt; ?', 2.weeks.ago],
+                         :group =&gt; &quot;service_id,DATE_FORMAT(posts.published_at, '%Y-%m-%d')&quot;).each do |post|
+        xlabel = post.published_at.strftime(&quot;%b-%d&quot;)
+        data[xlabel] = {} unless data[xlabel]
+        data[xlabel][post.service_id.to_i] = post.num_posts.to_i
+        services &lt;&lt; post.service_id.to_i unless services.include?(post.service_id.to_i)
+      end
+      xlabels = []
+      data_by_service = {}
+      all_values = []
+      data.each do |day,posts_by_service|
+        xlabels &lt;&lt; day
+        total_today = 0
+        services.each do |service_id|
+          data_by_service[service_id] ||= []
+          data_by_service[service_id] &lt;&lt; (posts_by_service[service_id] || 0)
+          total_today += posts_by_service[service_id].to_i
+        end
+        all_values &lt;&lt; total_today
+      end
+      color_i = 0
+      services.each do |service_id|
+        bc.data(Service.find(service_id).identifier, data_by_service[service_id], graph_colors[(color_i % 4)])
+        color_i += 1 
+      end
+      ylabels = []
+      0.upto(all_values.max) { |i| ylabels &lt;&lt; i }
+      #1.upto(10) { |i| ylabels &lt;&lt; i }
+      bc.axis(:y, :labels =&gt; ylabels)
+      bc.axis(:x, :labels =&gt; xlabels)
+      bc.width_spacing_options(:bar_width =&gt; 50)
+      bc.stacked = true
+      return bc    
+    end    
+  end
+  
+  def used_services_graph
+    require 'google_chart'
+    # Services Diagram
+    services = {}
+    self.posts.find(:all, 
+                       :select =&gt; 'COUNT(posts.id) AS num_posts,service_id',
+                       :conditions =&gt; ['posts.published_at &gt; ?', 2.weeks.ago],
+                       :group =&gt; 'service_id').each do |post|
+      services[post.service_id.to_i] = post.num_posts.to_i
+    end
+    GoogleChart::PieChart.new('320x200', &quot;Services used&quot;, false) do |pc|
+      color_i = 0
+      services.each do |service_id,num_posts|
+        pc.data(Service.find(service_id).identifier, num_posts, graph_colors[(color_i % 4)])
+        color_i += 1
+      end
+      return pc
+    end
+  end
+  
+  def common_activity_hours_graph_url
+    require 'google_chart'
+    hourly_activity = {}
+    time_zone = nil
+    self.posts.find(:all, 
+                       :select =&gt; 'COUNT(posts.id) AS num_posts,published_at',
+                       :conditions =&gt; ['posts.published_at &gt; ?', 2.weeks.ago],
+                       :group =&gt; &quot;DATE_FORMAT(posts.published_at, '%H')&quot;).each do |post|
+      hourly_activity[post.published_at.strftime(&quot;%H&quot;).to_i] = post.num_posts.to_i
+    end
+    puts hourly_activity.inspect
+    xlabels = (0..23).collect { |h| &quot;#{h+1}:00&quot; }
+    hourly_activity = (0..23).collect { |h| hourly_activity[h] || 0 }
+    hourly_activity = hourly_activity.collect { |p| ((p/hourly_activity.max.to_f)*100).ceil }
+    &quot;http://chart.apis.google.com/chart?cht=r&amp;chs=200x200&amp;chd=t:#{hourly_activity.join(',')}0&amp;chco=#{graph_colors.first}&amp;chls=2.0,4.0,0.0&amp;chxt=x&amp;chxl=0:|#{(0..23).collect { |i| i.to_s }.join('|')}&amp;chxr=0,0.0,23.0&amp;chm=B,#{graph_colors.last},0,1.0,4.0&amp;chtt=Hourly+Activity+#{time_zone}&quot;
+  end
+  
+  def activity_summary_sparkline_url
+    data = []
+    self.posts.find(:all, 
+                    :select =&gt; 'COUNT(posts.id) AS num_posts, published_at', 
+                    :conditions =&gt; ['posts.published_at &gt; ?', 2.weeks.ago],
+                    :group =&gt; &quot;DATE_FORMAT(posts.published_at, '%Y-%m-%d')&quot;).each do |post|
+      data &lt;&lt; post.num_posts.to_i
+    end
+    peak = data.max
+    data = data.collect { |p| ((p/peak.to_f)*100).ceil }
+    &quot;http://chart.apis.google.com/chart?chs=200x80&amp;chd=t:#{data.join(',')}&amp;cht=ls&quot;
+  end
+  
+  protected
+  
+  def graph_colors
+    ['2a2a2a', '666666', '999999', 'cccccc']
+  end
+
 end</diff>
      <filename>app/models/stream.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,6 +3,6 @@
   &lt;% if @post %&gt;
     &lt;%= image_tag(media.embed_url.gsub(/_m\.jpg$/, '.jpg')) %&gt;
   &lt;% elsif local_assigns[:context] == 'media' %&gt;
-    &lt;%= link_to(image_tag(media.embed_url), read_url(:id =&gt; post)) %&gt;
+    &lt;%= link_to(image_tag(media.big_thumbnail_url), read_url(:id =&gt; post)) %&gt;
   &lt;% end %&gt;
 &lt;% end %&gt;
\ No newline at end of file</diff>
      <filename>app/views/posts/_photo.html.erb</filename>
    </modified>
    <modified>
      <diff>@@ -72,6 +72,12 @@
     &lt;/div&gt;
   &lt;% end %&gt;
   
+  &lt;div class=&quot;stats&quot;&gt;
+    &lt;h3&gt;Activity Stats&lt;/h3&gt;
+    &lt;%= link_to(image_tag(@stream.activity_summary_sparkline_url), statistics_url) %&gt;
+    &lt;%= link_to('more', statistics_url, :class =&gt; 'more') %&gt;
+  &lt;/div&gt;
+  
   &lt;%= will_paginate(@posts) if @posts.respond_to?(:total_pages) %&gt;
 &lt;/div&gt;
 </diff>
      <filename>app/views/posts/index.html.erb</filename>
    </modified>
    <modified>
      <diff>@@ -4,15 +4,17 @@
     &lt;%= distance_of_time_in_words_to_now(@post.published_at) %&gt; ago
   &lt;/abbr&gt;
   &lt;div class=&quot;share&quot;&gt;
-    &lt;%= link_to('Tweet this', &quot;http://twitter.com/home/?status=&quot; + CGI.escape(&quot;Check out: #{File.join(@stream.blog_url.to_s, File.join(request.request_uri.to_s))}&quot;), :class =&gt; 'tweet_this') %&gt;
-    &lt;script type=&quot;text/javascript&quot;&gt;
-    digg_url = '&lt;%= File.join(@stream.blog_url.to_s, File.join(request.request_uri.to_s)) %&gt;';
-    digg_skin = 'compact';
-    digg_window = 'new';
-    &lt;/script&gt;
-    &lt;script src=&quot;http://digg.com/tools/diggthis.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
-    &lt;% unless @stream.addthis_username.blank? %&gt;
-      &lt;a href=&quot;http://www.addthis.com/bookmark.php&quot; onclick=&quot;window.open('http://www.addthis.com/bookmark.php?wt=nw&amp;pub=&lt;%= @stream.addthis_username %&gt;&amp;url='+encodeURIComponent(location.href)+'&amp;title='+encodeURIComponent(document.title), 'addthis', 'scrollbars=yes,menubar=no,width=620,height=520,resizable=yes,toolbar=no,location=no,status=no,screenX=200,screenY=100,left=200,top=100'); return false;&quot; title=&quot;Bookmark and Share&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://s9.addthis.com/button1-addthis.gif&quot; width=&quot;125&quot; height=&quot;16&quot; border=&quot;0&quot; alt=&quot;Bookmark and Share&quot; /&gt;&lt;/a&gt;
+    &lt;% if @post.type == 'article' %&gt;
+      &lt;%= link_to('Tweet this', &quot;http://twitter.com/home/?status=&quot; + CGI.escape(&quot;Check out: #{File.join(@stream.blog_url.to_s, File.join(request.request_uri.to_s))}&quot;), :class =&gt; 'tweet_this') %&gt;
+      &lt;script type=&quot;text/javascript&quot;&gt;
+      digg_url = '&lt;%= File.join(@stream.blog_url.to_s, File.join(request.request_uri.to_s)) %&gt;';
+      digg_skin = 'compact';
+      digg_window = 'new';
+      &lt;/script&gt;
+      &lt;script src=&quot;http://digg.com/tools/diggthis.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
+      &lt;% unless @stream.addthis_username.blank? %&gt;
+        &lt;a href=&quot;http://www.addthis.com/bookmark.php&quot; onclick=&quot;window.open('http://www.addthis.com/bookmark.php?wt=nw&amp;pub=&lt;%= @stream.addthis_username %&gt;&amp;url='+encodeURIComponent(location.href)+'&amp;title='+encodeURIComponent(document.title), 'addthis', 'scrollbars=yes,menubar=no,width=620,height=520,resizable=yes,toolbar=no,location=no,status=no,screenX=200,screenY=100,left=200,top=100'); return false;&quot; title=&quot;Bookmark and Share&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://s9.addthis.com/button1-addthis.gif&quot; width=&quot;125&quot; height=&quot;16&quot; border=&quot;0&quot; alt=&quot;Bookmark and Share&quot; /&gt;&lt;/a&gt;
+      &lt;% end %&gt;
     &lt;% end %&gt;
   &lt;/div&gt;
 </diff>
      <filename>app/views/posts/show.html.erb</filename>
    </modified>
    <modified>
      <diff>@@ -39,6 +39,7 @@ ActionController::Routing::Routes.draw do |map|
   #map.connect '/', :controller =&gt; 'posts', :method =&gt; :index
   #map.connect '/archive', :controller =&gt; 'posts', :method =&gt; :archive
   
+  map.resources :statistics
   map.resources :services
   map.resources :assets
   </diff>
      <filename>config/routes.rb</filename>
    </modified>
    <modified>
      <diff>@@ -245,7 +245,8 @@ div.articles a.feedburner {
 
 .trips h3,
 .tagcloud h3,
-.profiles h3 {
+.profiles h3,
+.stats h3 {
 	margin-bottom: 0.8em;
 }
 
@@ -257,7 +258,8 @@ div.articles a.feedburner {
 }
 
 .trips,
-.profiles {
+.profiles,
+.stats {
 	float: left;
 	width: 300px;
 	padding: 1em;
@@ -288,6 +290,11 @@ div.articles a.feedburner {
 
 /* Stream */
 
+.stream_and_context a.more {
+	display: block;
+	font-size: 12px;
+}
+
 .stream_and_context {
 	width: 920px;
 	margin: 2em auto;
@@ -485,3 +492,19 @@ a.more {
 	height: 20px;
 }
 
+/* Statistics */
+
+div.statistics {
+	width: 920px;
+	margin: 2em auto;
+}
+
+.statistics div.services.summary {
+	margin: 2em 2em 0 0;
+	float: left;
+}
+
+.statistics div.hourly.activity {
+	margin-top: 2em;
+}
+</diff>
      <filename>public/stylesheets/application.css</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>bb097ce69f05c3a6645aee19f86f49ed46bc6e91</id>
    </parent>
  </parents>
  <author>
    <name>Dominiek ter Heide</name>
    <email>info@dominiek.com</email>
  </author>
  <url>http://github.com/dominiek/kakuteru/commit/bb54a366708da358a69dd988d70432736af655fc</url>
  <id>bb54a366708da358a69dd988d70432736af655fc</id>
  <committed-date>2008-10-25T08:28:01-07:00</committed-date>
  <authored-date>2008-10-25T08:28:01-07:00</authored-date>
  <message>Added (public) activity statistics to Kakuteru</message>
  <tree>f2cfa8d274de94ab6ce358529f2a908b8741da4c</tree>
  <committer>
    <name>Dominiek ter Heide</name>
    <email>info@dominiek.com</email>
  </committer>
</commit>
