<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>app/views/stats/actions_done_last_years.html.erb</filename>
    </added>
    <added>
      <filename>app/views/stats/actions_done_lastyears_data.html.erb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -105,7 +105,107 @@ class StatsController &lt; ApplicationController
     
     render :layout =&gt; false
   end
+  
+  def actions_done_last_years
+    @chart_width = 900
+    @chart_height = 400
+  end
+  
+  def actions_done_lastyears_data
+    @actions = @user.todos
+       
+    # get actions created and completed in the past 12+3 months. +3 for running
+    #   average
+    @actions_done_last_months = @actions.find(:all, {
+        :select =&gt; &quot;completed_at&quot;,
+        :conditions =&gt; [&quot;completed_at IS NOT NULL&quot;]
+      })
+    @actions_created_last_months = @actions.find(:all, {
+        :select =&gt; &quot;created_at&quot;,
+      })
+    
+    @month_count = 0
+    
+    # convert to hash to be able to fill in non-existing days in
+    #   @actions_done_last12months and count the total actions done in the past
+    #   12 months to be able to calculate percentage
+    
+    # use 0 to initialise action count to zero
+    @actions_done_last_months_hash = Hash.new(0) 
+    @actions_done_last_months.each do |r|      
+      months = (@today.year - r.completed_at.year)*12 + (@today.month - r.completed_at.month)
+      @month_count = months if months &gt; @month_count
+      @actions_done_last_months_hash[months] += 1
+    end
+        
+    # convert to hash to be able to fill in non-existing days in
+    #   @actions_created_last12months and count the total actions done in the
+    #   past 12 months to be able to calculate percentage
+
+    # use 0 to initialise action count to zero
+    @actions_created_last_months_hash = Hash.new(0)
+    @actions_created_last_months.each do |r|
+      months = (@today.year - r.created_at.year)*12 + (@today.month - r.created_at.month)
+      @month_count = months if months &gt; @month_count
+      @actions_created_last_months_hash[months] += 1
+    end
+
+    @sum_actions_done_last_months=0
+    @sum_actions_created_last_months=0
+
+    # find max for graph in both hashes
+    @max=0
+    0.upto @month_count do |i|
+      @sum_actions_done_last_months += @actions_done_last_months_hash[i] 
+      @max = @actions_done_last_months_hash[i] if @actions_done_last_months_hash[i] &gt; @max
+    end
+    0.upto @month_count do |i| 
+      @sum_actions_created_last_months += @actions_created_last_months_hash[i]
+      @max = @actions_created_last_months_hash[i] if @actions_created_last_months_hash[i] &gt; @max
+    end
+    
+    # find running avg for month i by calculating avg of month i and the two
+    #   after them. Ignore current month because you do not have full data for
+    #   it
+    @actions_done_avg_last_months_hash = Hash.new(&quot;null&quot;)
+    1.upto(@month_count) { |i| 
+      @actions_done_avg_last_months_hash[i] = (@actions_done_last_months_hash[i] +
+          @actions_done_last_months_hash[i+1] + 
+          @actions_done_last_months_hash[i+2])/3.0
+    }
+    # correct last two months
+    @actions_done_avg_last_months_hash[@month_count] = @actions_done_avg_last_months_hash[@month_count] * 3
+    @actions_done_avg_last_months_hash[@month_count-1] = @actions_done_avg_last_months_hash[@month_count-1] * 3 / 2 if @month_count &gt; 1
 
+    # find running avg for month i by calculating avg of month i and the two
+    #   after them. Ignore current month because you do not have full data for
+    #   it
+    @actions_created_avg_last_months_hash = Hash.new(&quot;null&quot;)
+    1.upto(@month_count) { |i| 
+      @actions_created_avg_last_months_hash[i] = (@actions_created_last_months_hash[i] +
+          @actions_created_last_months_hash[i+1] + 
+          @actions_created_last_months_hash[i+2])/3.0
+    }    
+    # correct last two months
+    @actions_created_avg_last_months_hash[@month_count] = @actions_created_avg_last_months_hash[@month_count] * 3
+    @actions_created_avg_last_months_hash[@month_count-1] = @actions_created_avg_last_months_hash[@month_count-1] * 3 / 2 if @month_count &gt; 1
+    
+    # interpolate avg for this month. Assume 31 days in this month
+    days_passed_this_month = Time.new.day/1.0
+    @interpolated_actions_created_this_month = (
+      @actions_created_last_months_hash[0]/days_passed_this_month*31.0+
+        @actions_created_last_months_hash[1]+
+        @actions_created_last_months_hash[2]) / 3.0
+  
+    @interpolated_actions_done_this_month = (
+      @actions_done_last_months_hash[0]/days_passed_this_month*31.0 +
+        @actions_done_last_months_hash[1]+
+        @actions_done_last_months_hash[2]) / 3.0
+    
+    render :layout =&gt; false
+  end
+
+  
   def actions_done_last30days_data
     # get actions created and completed in the past 30 days.
     @actions_done_last30days = @actions.find(:all, {</diff>
      <filename>app/controllers/stats_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -11,6 +11,8 @@
 &amp;line_7=1,0xAA0000&amp;
 &amp;line_8=1,0x007700&amp;
 &amp;values=&lt;% 0.upto 11 do |i| -%&gt;&lt;%= @actions_created_last12months_hash[i]%&gt;,&lt;% end -%&gt;&lt;%= @actions_created_last12months_hash[12]%&gt;&amp;
+&amp;links=&lt;% 0.upto 11 do |i| -%&gt;&lt;%=  url_for :controller =&gt; 'stats', :action =&gt; 'actions_done_last_years' %&gt;,&lt;% end -%&gt;&lt;%=  url_for :controller =&gt; 'stats', :action =&gt; 'actions_done_last_years' %&gt;&amp;
+&amp;links_2=&lt;% 0.upto 11 do |i| -%&gt;&lt;%=  url_for :controller =&gt; 'stats', :action =&gt; 'actions_done_last_years' %&gt;,&lt;% end -%&gt;&lt;%=  url_for :controller =&gt; 'stats', :action =&gt; 'actions_done_last_years' %&gt;&amp;
 &amp;values_2=&lt;% 0.upto 11 do |i| -%&gt;&lt;%= @actions_done_last12months_hash[i]%&gt;,&lt;% end -%&gt;&lt;%= @actions_done_last12months_hash[12]%&gt;&amp;
 &amp;values_3=&lt;%0.upto 11 do |i| -%&gt;&lt;%=@sum_actions_created_last12months/12-%&gt;,&lt;%end-%&gt;&lt;%=@sum_actions_created_last12months/12-%&gt;&amp;
 &amp;values_4=&lt;%0.upto 11 do |i| -%&gt;&lt;%=@sum_actions_done_last12months/12-%&gt;,&lt;%end-%&gt;&lt;%=@sum_actions_done_last12months/12-%&gt;&amp;</diff>
      <filename>app/views/stats/actions_done_last12months_data.html.erb</filename>
    </modified>
    <modified>
      <diff>@@ -1,30 +1,30 @@
 &lt;div class=&quot;stats_content&quot;&gt;
-	&lt;h2&gt;Totals&lt;/h2&gt;
-
-&lt;%= render :partial =&gt; 'totals' -%&gt;
-
-&lt;% unless @actions.empty? -%&gt;
-
-&lt;h2&gt;Actions&lt;/h2&gt;
-
-&lt;%= render :partial =&gt; 'actions' -%&gt;
-
-&lt;h2&gt;Contexts&lt;/h2&gt;
-
-&lt;%= render :partial =&gt; 'contexts' -%&gt;
-
-&lt;h2&gt;Projects&lt;/h2&gt;
-
-&lt;%= render :partial =&gt; 'projects' -%&gt;
-
-&lt;h2&gt;Tags&lt;/h2&gt;
-
-&lt;%= render :partial =&gt; 'tags' -%&gt;
-
-&lt;% else -%&gt;
-
-&lt;p&gt;More statistics will appear here once you have added some actions.&lt;/p&gt;
-	
-&lt;% end -%&gt;
-
+  &lt;h2&gt;Totals&lt;/h2&gt;
+  
+  &lt;%= render :partial =&gt; 'totals' -%&gt;
+  
+  &lt;% unless @actions.empty? -%&gt;
+  
+    &lt;h2&gt;Actions&lt;/h2&gt;
+  
+    &lt;%= render :partial =&gt; 'actions' -%&gt;
+  
+    &lt;h2&gt;Contexts&lt;/h2&gt;
+  
+    &lt;%= render :partial =&gt; 'contexts' -%&gt;
+  
+    &lt;h2&gt;Projects&lt;/h2&gt;
+  
+    &lt;%= render :partial =&gt; 'projects' -%&gt;
+  
+    &lt;h2&gt;Tags&lt;/h2&gt;
+  
+    &lt;%= render :partial =&gt; 'tags' -%&gt;
+  
+  &lt;% else -%&gt;
+  
+    &lt;p&gt;More statistics will appear here once you have added some actions.&lt;/p&gt;
+  
+  &lt;% end -%&gt;
+  
 &lt;/div&gt;
\ No newline at end of file</diff>
      <filename>app/views/stats/index.html.erb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>909519293b2bc7608b15cc4b93f062bc2d85ffa5</id>
    </parent>
  </parents>
  <author>
    <name>Reinier Balt</name>
    <email>lrbalt@gmail.com</email>
  </author>
  <url>http://github.com/bsag/tracks/commit/44f8646881beae085dca02def679a975a1be9379</url>
  <id>44f8646881beae085dca02def679a975a1be9379</id>
  <committed-date>2008-07-04T08:56:59-07:00</committed-date>
  <authored-date>2008-07-04T08:56:59-07:00</authored-date>
  <message>adds chart to see all actions in all past months

This one is a bit hidden. You need to click on a bar in the chart
with the actions from the last 12 months. Need to change this so
people can find it easier</message>
  <tree>cbb2b98e38795b78a152ce1bbcfaeff91890cc3e</tree>
  <committer>
    <name>Reinier Balt</name>
    <email>lrbalt@gmail.com</email>
  </committer>
</commit>
