mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-18 00:00:12 +01:00
enhanced stats for actions in the past 12 months. Added an avarage over the past 3 months to show some sort of 'trend'
git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@618 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
parent
4f5126b5e8
commit
8360f94bb8
2 changed files with 44 additions and 13 deletions
|
|
@ -26,20 +26,20 @@ class StatsController < ApplicationController
|
||||||
def actions_done_last12months_data
|
def actions_done_last12months_data
|
||||||
@actions = @user.todos
|
@actions = @user.todos
|
||||||
|
|
||||||
# get actions created and completed in the past 12 months.
|
# get actions created and completed in the past 12+3 months. +3 for running
|
||||||
|
# average
|
||||||
@actions_done_last12months = @actions.find(:all, {
|
@actions_done_last12months = @actions.find(:all, {
|
||||||
:select => "completed_at",
|
:select => "completed_at",
|
||||||
:conditions => ["completed_at > ? AND NOT completed_at is null", @cut_off_year]
|
:conditions => ["completed_at > ? AND NOT completed_at is null", @cut_off_year_plus3]
|
||||||
})
|
})
|
||||||
@actions_created_last12months = @actions.find(:all, {
|
@actions_created_last12months = @actions.find(:all, {
|
||||||
:select => "created_at",
|
:select => "created_at",
|
||||||
:conditions => ["created_at > ?", @cut_off_year]
|
:conditions => ["created_at > ?", @cut_off_year_plus3]
|
||||||
})
|
})
|
||||||
|
|
||||||
# convert to hash to be able to fill in non-existing days in
|
# 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
|
# @actions_done_last12months and count the total actions done in the past 12
|
||||||
# months to be able to calculate percentage
|
# months to be able to calculate percentage
|
||||||
@sum_actions_done_last12months=0
|
|
||||||
|
|
||||||
# use 0 to initialise action count to zero
|
# use 0 to initialise action count to zero
|
||||||
@actions_done_last12months_hash = Hash.new(0)
|
@actions_done_last12months_hash = Hash.new(0)
|
||||||
|
|
@ -47,13 +47,11 @@ class StatsController < ApplicationController
|
||||||
months = (@today.year - r.completed_at.year)*12 + (@today.month - r.completed_at.month)
|
months = (@today.year - r.completed_at.year)*12 + (@today.month - r.completed_at.month)
|
||||||
|
|
||||||
@actions_done_last12months_hash[months] += 1
|
@actions_done_last12months_hash[months] += 1
|
||||||
@sum_actions_done_last12months += 1
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# convert to hash to be able to fill in non-existing days in
|
# 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
|
# @actions_created_last12months and count the total actions done in the past
|
||||||
# 12 months to be able to calculate percentage
|
# 12 months to be able to calculate percentage
|
||||||
@sum_actions_created_last12months=0
|
|
||||||
|
|
||||||
# use 0 to initialise action count to zero
|
# use 0 to initialise action count to zero
|
||||||
@actions_created_last12months_hash = Hash.new(0)
|
@actions_created_last12months_hash = Hash.new(0)
|
||||||
|
|
@ -61,13 +59,39 @@ class StatsController < ApplicationController
|
||||||
months = (@today.year - r.created_at.year)*12 + (@today.month - r.created_at.month)
|
months = (@today.year - r.created_at.year)*12 + (@today.month - r.created_at.month)
|
||||||
|
|
||||||
@actions_created_last12months_hash[months] += 1
|
@actions_created_last12months_hash[months] += 1
|
||||||
@sum_actions_created_last12months += 1
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@sum_actions_done_last12months=0
|
||||||
|
@sum_actions_created_last12months=0
|
||||||
|
|
||||||
# find max for graph in both hashes
|
# find max for graph in both hashes
|
||||||
@max=0
|
@max=0
|
||||||
0.upto(30) { |i| @max = @actions_done_last12months_hash[i] if @actions_done_last12months_hash[i] > @max }
|
0.upto 13 do |i|
|
||||||
0.upto(30) { |i| @max = @actions_created_last12months_hash[i] if @actions_created_last12months_hash[i] > @max }
|
@sum_actions_done_last12months += @actions_done_last12months_hash[i]
|
||||||
|
@max = @actions_done_last12months_hash[i] if @actions_done_last12months_hash[i] > @max
|
||||||
|
end
|
||||||
|
0.upto 13 do |i|
|
||||||
|
@sum_actions_created_last12months += @actions_created_last12months_hash[i]
|
||||||
|
@max = @actions_created_last12months_hash[i] if @actions_created_last12months_hash[i] > @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_last12months_hash = Hash.new("null")
|
||||||
|
1.upto(12) { |i|
|
||||||
|
@actions_done_avg_last12months_hash[i] = (@actions_done_last12months_hash[i] +
|
||||||
|
@actions_done_last12months_hash[i+1] +
|
||||||
|
@actions_done_last12months_hash[i+2])/3.0
|
||||||
|
}
|
||||||
|
|
||||||
|
# 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_last12months_hash = Hash.new("null")
|
||||||
|
1.upto(12) { |i|
|
||||||
|
@actions_created_avg_last12months_hash[i] = (@actions_created_last12months_hash[i] +
|
||||||
|
@actions_created_last12months_hash[i+1] +
|
||||||
|
@actions_created_last12months_hash[i+2])/3.0
|
||||||
|
}
|
||||||
|
|
||||||
render :layout => false
|
render :layout => false
|
||||||
end
|
end
|
||||||
|
|
@ -386,7 +410,7 @@ class StatsController < ApplicationController
|
||||||
@contexts = @user.contexts
|
@contexts = @user.contexts
|
||||||
@tags = @user.tags
|
@tags = @user.tags
|
||||||
|
|
||||||
# get the current date wih time set to 0:0
|
# get the current date wih time set to 0:0
|
||||||
now = Time.new
|
now = Time.new
|
||||||
@today = Time.utc(now.year, now.month, now.day, 0,0)
|
@today = Time.utc(now.year, now.month, now.day, 0,0)
|
||||||
|
|
||||||
|
|
@ -397,6 +421,9 @@ class StatsController < ApplicationController
|
||||||
cut_off_time = 13.months.ago()
|
cut_off_time = 13.months.ago()
|
||||||
@cut_off_year = Time.utc(cut_off_time.year, cut_off_time.month, cut_off_time.day,0,0)
|
@cut_off_year = Time.utc(cut_off_time.year, cut_off_time.month, cut_off_time.day,0,0)
|
||||||
|
|
||||||
|
cut_off_time = 16.months.ago()
|
||||||
|
@cut_off_year_plus3 = Time.utc(cut_off_time.year, cut_off_time.month, cut_off_time.day,0,0)
|
||||||
|
|
||||||
cut_off_time = 31.days.ago
|
cut_off_time = 31.days.ago
|
||||||
@cut_off_month = Time.utc(cut_off_time.year, cut_off_time.month, cut_off_time.day,0,0)
|
@cut_off_month = Time.utc(cut_off_time.year, cut_off_time.month, cut_off_time.day,0,0)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,10 @@
|
||||||
&y_ticks=5,10,5&
|
&y_ticks=5,10,5&
|
||||||
&filled_bar=50,0x9933CC,0x8010A0,Completed,9&
|
&filled_bar=50,0x9933CC,0x8010A0,Completed,9&
|
||||||
&filled_bar_2=50,0x0066CC,0x0066CC,Created,9&
|
&filled_bar_2=50,0x0066CC,0x0066CC,Created,9&
|
||||||
&line_3=3,0xFF0000, Avg completed, 9&
|
&line_3=2,0xFF0000, Avg completed, 9&
|
||||||
&line_4=3,0x00FF00, Avg created, 9&
|
&line_4=2,0x00FF00, Avg created, 9&
|
||||||
|
&line_5=2,0xAA0000, 3 Month Avg Completed, 9&
|
||||||
|
&line_6=2,0x007700, 3 Month Avg Created, 9&
|
||||||
&values=
|
&values=
|
||||||
<% 0.upto 11 do |i| -%>
|
<% 0.upto 11 do |i| -%>
|
||||||
<%= @actions_done_last12months_hash[i]%>,
|
<%= @actions_done_last12months_hash[i]%>,
|
||||||
|
|
@ -16,6 +18,8 @@
|
||||||
<% end -%><%= @actions_created_last12months_hash[12]%>&
|
<% end -%><%= @actions_created_last12months_hash[12]%>&
|
||||||
&values_3=<%0.upto 11 do |i| -%><%=@sum_actions_done_last12months/12-%>,<%end-%><%=@sum_actions_done_last12months/12-%>&
|
&values_3=<%0.upto 11 do |i| -%><%=@sum_actions_done_last12months/12-%>,<%end-%><%=@sum_actions_done_last12months/12-%>&
|
||||||
&values_4=<%0.upto 11 do |i| -%><%=@sum_actions_created_last12months/12-%>,<%end-%><%=@sum_actions_created_last12months/12-%>&
|
&values_4=<%0.upto 11 do |i| -%><%=@sum_actions_created_last12months/12-%>,<%end-%><%=@sum_actions_created_last12months/12-%>&
|
||||||
|
&values_5=<%0.upto 11 do |i| -%><%=@actions_done_avg_last12months_hash[i]-%>,<%end-%><%=@actions_done_avg_last12months_hash[12]-%>&
|
||||||
|
&values_6=<%0.upto 11 do |i| -%><%=@actions_created_avg_last12months_hash[i]-%>,<%end-%><%=@actions_created_avg_last12months_hash[12]-%>&
|
||||||
&x_labels=<%0.upto 11 do |i| -%>
|
&x_labels=<%0.upto 11 do |i| -%>
|
||||||
<%= Date::MONTHNAMES[ (Time.now.mon - i -1 ) % 12 + 1 ] -%>,
|
<%= Date::MONTHNAMES[ (Time.now.mon - i -1 ) % 12 + 1 ] -%>,
|
||||||
<% end -%>
|
<% end -%>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue