public
Description: Tracks is a GTD(TM) web application, built with Ruby on Rails
Homepage: http://www.rousette.org.uk/projects/
Clone URL: git://github.com/bsag/tracks.git
Click here to lend your support to: tracks and make a donation at www.pledgie.com !
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
lrbalt (author)
Fri Jul 04 08:56:59 -0700 2008
commit  44f8646881beae085dca02def679a975a1be9379
tree    cbb2b98e38795b78a152ce1bbcfaeff91890cc3e
parent  909519293b2bc7608b15cc4b93f062bc2d85ffa5
...
105
106
107
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
110
111
...
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
0
@@ -105,7 +105,107 @@ class StatsController < ApplicationController
0
     
0
     render :layout => false
0
   end
0
+  
0
+  def actions_done_last_years
0
+    @chart_width = 900
0
+    @chart_height = 400
0
+  end
0
+  
0
+  def actions_done_lastyears_data
0
+    @actions = @user.todos
0
+       
0
+    # get actions created and completed in the past 12+3 months. +3 for running
0
+    #   average
0
+    @actions_done_last_months = @actions.find(:all, {
0
+        :select => "completed_at",
0
+        :conditions => ["completed_at IS NOT NULL"]
0
+      })
0
+    @actions_created_last_months = @actions.find(:all, {
0
+        :select => "created_at",
0
+      })
0
+    
0
+    @month_count = 0
0
+    
0
+    # convert to hash to be able to fill in non-existing days in
0
+    #   @actions_done_last12months and count the total actions done in the past
0
+    #   12 months to be able to calculate percentage
0
+    
0
+    # use 0 to initialise action count to zero
0
+    @actions_done_last_months_hash = Hash.new(0) 
0
+    @actions_done_last_months.each do |r|      
0
+      months = (@today.year - r.completed_at.year)*12 + (@today.month - r.completed_at.month)
0
+      @month_count = months if months > @month_count
0
+      @actions_done_last_months_hash[months] += 1
0
+    end
0
+        
0
+    # convert to hash to be able to fill in non-existing days in
0
+    #   @actions_created_last12months and count the total actions done in the
0
+    #   past 12 months to be able to calculate percentage
0
+
0
+    # use 0 to initialise action count to zero
0
+    @actions_created_last_months_hash = Hash.new(0)
0
+    @actions_created_last_months.each do |r|
0
+      months = (@today.year - r.created_at.year)*12 + (@today.month - r.created_at.month)
0
+      @month_count = months if months > @month_count
0
+      @actions_created_last_months_hash[months] += 1
0
+    end
0
+
0
+    @sum_actions_done_last_months=0
0
+    @sum_actions_created_last_months=0
0
+
0
+    # find max for graph in both hashes
0
+    @max=0
0
+    0.upto @month_count do |i|
0
+      @sum_actions_done_last_months += @actions_done_last_months_hash[i] 
0
+      @max = @actions_done_last_months_hash[i] if @actions_done_last_months_hash[i] > @max
0
+    end
0
+    0.upto @month_count do |i| 
0
+      @sum_actions_created_last_months += @actions_created_last_months_hash[i]
0
+      @max = @actions_created_last_months_hash[i] if @actions_created_last_months_hash[i] > @max
0
+    end
0
+    
0
+    # find running avg for month i by calculating avg of month i and the two
0
+    #   after them. Ignore current month because you do not have full data for
0
+    #   it
0
+    @actions_done_avg_last_months_hash = Hash.new("null")
0
+    1.upto(@month_count) { |i| 
0
+      @actions_done_avg_last_months_hash[i] = (@actions_done_last_months_hash[i] +
0
+          @actions_done_last_months_hash[i+1] + 
0
+          @actions_done_last_months_hash[i+2])/3.0
0
+    }
0
+    # correct last two months
0
+    @actions_done_avg_last_months_hash[@month_count] = @actions_done_avg_last_months_hash[@month_count] * 3
0
+    @actions_done_avg_last_months_hash[@month_count-1] = @actions_done_avg_last_months_hash[@month_count-1] * 3 / 2 if @month_count > 1
0
 
0
+    # find running avg for month i by calculating avg of month i and the two
0
+    #   after them. Ignore current month because you do not have full data for
0
+    #   it
0
+    @actions_created_avg_last_months_hash = Hash.new("null")
0
+    1.upto(@month_count) { |i| 
0
+      @actions_created_avg_last_months_hash[i] = (@actions_created_last_months_hash[i] +
0
+          @actions_created_last_months_hash[i+1] + 
0
+          @actions_created_last_months_hash[i+2])/3.0
0
+    }    
0
+    # correct last two months
0
+    @actions_created_avg_last_months_hash[@month_count] = @actions_created_avg_last_months_hash[@month_count] * 3
0
+    @actions_created_avg_last_months_hash[@month_count-1] = @actions_created_avg_last_months_hash[@month_count-1] * 3 / 2 if @month_count > 1
0
+    
0
+    # interpolate avg for this month. Assume 31 days in this month
0
+    days_passed_this_month = Time.new.day/1.0
0
+    @interpolated_actions_created_this_month = (
0
+      @actions_created_last_months_hash[0]/days_passed_this_month*31.0+
0
+        @actions_created_last_months_hash[1]+
0
+        @actions_created_last_months_hash[2]) / 3.0
0
+  
0
+    @interpolated_actions_done_this_month = (
0
+      @actions_done_last_months_hash[0]/days_passed_this_month*31.0 +
0
+        @actions_done_last_months_hash[1]+
0
+        @actions_done_last_months_hash[2]) / 3.0
0
+    
0
+    render :layout => false
0
+  end
0
+
0
+  
0
   def actions_done_last30days_data
0
     # get actions created and completed in the past 30 days.
0
     @actions_done_last30days = @actions.find(:all, {
...
11
12
13
 
 
14
15
16
...
11
12
13
14
15
16
17
18
0
@@ -11,6 +11,8 @@
0
 &line_7=1,0xAA0000&
0
 &line_8=1,0x007700&
0
 &values=<% 0.upto 11 do |i| -%><%= @actions_created_last12months_hash[i]%>,<% end -%><%= @actions_created_last12months_hash[12]%>&
0
+&links=<% 0.upto 11 do |i| -%><%=  url_for :controller => 'stats', :action => 'actions_done_last_years' %>,<% end -%><%=  url_for :controller => 'stats', :action => 'actions_done_last_years' %>&
0
+&links_2=<% 0.upto 11 do |i| -%><%=  url_for :controller => 'stats', :action => 'actions_done_last_years' %>,<% end -%><%=  url_for :controller => 'stats', :action => 'actions_done_last_years' %>&
0
 &values_2=<% 0.upto 11 do |i| -%><%= @actions_done_last12months_hash[i]%>,<% end -%><%= @actions_done_last12months_hash[12]%>&
0
 &values_3=<%0.upto 11 do |i| -%><%=@sum_actions_created_last12months/12-%>,<%end-%><%=@sum_actions_created_last12months/12-%>&
0
 &values_4=<%0.upto 11 do |i| -%><%=@sum_actions_done_last12months/12-%>,<%end-%><%=@sum_actions_done_last12months/12-%>&
...
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
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
31
...
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
29
30
31
0
@@ -1,30 +1,30 @@
0
 <div class="stats_content">
0
-  <h2>Totals</h2>
0
-
0
-<%= render :partial => 'totals' -%>
0
-
0
-<% unless @actions.empty? -%>
0
-
0
-<h2>Actions</h2>
0
-
0
-<%= render :partial => 'actions' -%>
0
-
0
-<h2>Contexts</h2>
0
-
0
-<%= render :partial => 'contexts' -%>
0
-
0
-<h2>Projects</h2>
0
-
0
-<%= render :partial => 'projects' -%>
0
-
0
-<h2>Tags</h2>
0
-
0
-<%= render :partial => 'tags' -%>
0
-
0
-<% else -%>
0
-
0
-<p>More statistics will appear here once you have added some actions.</p>
0
-  
0
-<% end -%>
0
-
0
+  <h2>Totals</h2>
0
+  
0
+  <%= render :partial => 'totals' -%>
0
+  
0
+  <% unless @actions.empty? -%>
0
+  
0
+    <h2>Actions</h2>
0
+  
0
+    <%= render :partial => 'actions' -%>
0
+  
0
+    <h2>Contexts</h2>
0
+  
0
+    <%= render :partial => 'contexts' -%>
0
+  
0
+    <h2>Projects</h2>
0
+  
0
+    <%= render :partial => 'projects' -%>
0
+  
0
+    <h2>Tags</h2>
0
+  
0
+    <%= render :partial => 'tags' -%>
0
+  
0
+  <% else -%>
0
+  
0
+    <p>More statistics will appear here once you have added some actions.</p>
0
+  
0
+  <% end -%>
0
+  
0
 </div>
0
\ No newline at end of file

Comments