This commit is contained in:
Reinier Balt 2012-01-21 20:20:24 +01:00
parent bc7bf459db
commit 1bce9a670d
4 changed files with 79 additions and 18 deletions

View file

@ -112,7 +112,7 @@ class StatsController < ApplicationController
@count = [10, @max_weeks].min
# convert to new array to hold max @cut_off elems + 1 for sum of actions after @cut_off
@actions_completion_time_array = cut_off_array(@actions_completed_per_week_array, @count)
@actions_completion_time_array = cut_off_array_with_sum(@actions_completed_per_week_array, @count)
@max_actions = @actions_completion_time_array.max
# get percentage done cummulative
@ -132,7 +132,7 @@ class StatsController < ApplicationController
@count = [52, @max_weeks].min
# convert to new array to hold max @cut_off elems + 1 for sum of actions after @cut_off
@actions_running_time_array = cut_off_array(@actions_running_per_week_array, @count)
@actions_running_time_array = cut_off_array_with_sum(@actions_running_per_week_array, @count)
@max_actions = @actions_running_time_array.max
# get percentage done cummulative
@ -160,7 +160,7 @@ class StatsController < ApplicationController
@count = [52, @max_weeks].min
# convert to new array to hold max @cut_off elems + 1 for sum of actions after @cut_off
@actions_running_time_array = cut_off_array(@actions_running_per_week_array, @count)
@actions_running_time_array = cut_off_array_with_sum(@actions_running_per_week_array, @count)
@max_actions = @actions_running_time_array.max
# get percentage done cummulative
@ -168,6 +168,22 @@ class StatsController < ApplicationController
render :layout => false
end
def actions_open_per_week_data
@actions_started = current_user.todos.created_after(@today-53.weeks).find(:all,
:select => "todos.created_at, todos.completed_at",:order => "todos.created_at DESC")
@max_weeks = difference_in_weeks(@today, @actions_started.last.created_at)
# cut off chart at 52 weeks = one year
@count = [52, @max_weeks].min
@actions_open_per_week_array = convert_to_weeks_running_from_today_array(@actions_started, @max_weeks)
@actions_open_per_week_array = cut_off_array(@actions_open_per_week_array, @count)
@max_actions = @actions_open_per_week_array.max
render :layout => false
end
def context_total_actions_data
# get total action count per context Went from GROUP BY c.id to c.name for
@ -619,39 +635,57 @@ class StatsController < ApplicationController
return Array.new(upper_bound){ |i| hash[i] }
end
# uses the supplied block to determine index in hash
# uses the supplied block to determine array of indexes in hash
# the block should return an array of indexes each is added to the hash and summed
def convert_to_hash(records)
# use 0 to initialise action count to zero
hash = Hash.new(0)
records.each { |r| hash[ yield r ] += 1 }
records.each { |r| (yield r).each { |i| hash[i] += 1} }
return hash
end
def convert_to_months_from_today_array(records, array_size, date_method_on_todo)
return convert_to_array(convert_to_hash(records){ |r| difference_in_months(@today, r.send(date_method_on_todo))}, array_size)
return convert_to_array(convert_to_hash(records){ |r| [difference_in_months(@today, r.send(date_method_on_todo))]}, array_size)
end
def convert_to_days_from_today_array(records, array_size, date_method_on_todo)
return convert_to_array(convert_to_hash(records){ |r| difference_in_days(@today, r.send(date_method_on_todo))}, array_size)
return convert_to_array(convert_to_hash(records){ |r| [difference_in_days(@today, r.send(date_method_on_todo))]}, array_size)
end
def convert_to_weeks_from_today_array(records, array_size, date_method_on_todo)
return convert_to_array(convert_to_hash(records) { |r| difference_in_weeks(@today, r.send(date_method_on_todo))}, array_size)
return convert_to_array(convert_to_hash(records) { |r| [difference_in_weeks(@today, r.send(date_method_on_todo))]}, array_size)
end
def convert_to_weeks_running_array(records, array_size)
return convert_to_array(convert_to_hash(records) { |r| difference_in_weeks(r.completed_at, r.created_at)}, array_size)
return convert_to_array(convert_to_hash(records) { |r| [difference_in_weeks(r.completed_at, r.created_at)]}, array_size)
end
def convert_to_weeks_running_from_today_array(records, array_size)
hash = convert_to_hash(records) { |r| week_indexes_of(r) }
return convert_to_array(hash, array_size)
end
def week_indexes_of(record)
a = []
start_week = difference_in_weeks(@today, record.created_at)
end_week = record.completed_at ? difference_in_weeks(@today, record.completed_at) : 0
end_week.upto(start_week) { |i| a << i };
return a
end
# returns a new array containing all elems of array up to cut_off and
# adds the sum of the rest of array to the last elem
def cut_off_array(array, cut_off)
def cut_off_array_with_sum(array, cut_off)
# +1 to hold sum of rest
a = Array.new(cut_off+1){|i| array[i]||0}
# add rest of array to last elem
a[cut_off] += array.inject(:+) - a.inject(:+)
return a
end
def cut_off_array(array, cut_off)
return Array.new(cut_off){|i| array[i]||0}
end
def convert_to_cummulative_array(array, max)
# calculate fractions

View file

@ -7,7 +7,9 @@
<%= t('stats.actions_avg_created', :count => (@sum_actions_created_last12months*10.0/12.0).round/10.0 )%>
<%= t('stats.actions_avg_completed', :count => (@sum_actions_done_last12months*10.0/12.0).round/10.0 )%></p>
<% %w{ actions_done_last30days_data
<%
%w{
actions_done_last30days_data
actions_done_last12months_data
actions_completion_time_data
}.each do |action|
@ -17,12 +19,15 @@
<br style="clear:both">
<% %w{ actions_visible_running_time_data
actions_running_time_data
actions_day_of_week_all_data
actions_day_of_week_30days_data
actions_time_of_day_all_data
actions_time_of_day_30days_data
<%
%w{
actions_visible_running_time_data
actions_running_time_data
actions_open_per_week_data
actions_day_of_week_all_data
actions_day_of_week_30days_data
actions_time_of_day_all_data
actions_time_of_day_30days_data
}.each do |action|
%><%= render :partial => 'chart', :locals => {:width => @chart_width, :height => @chart_height, :data => url_for(:action => action)} -%><%
end

View file

@ -0,0 +1,18 @@
<%-
time_labels = Array.new(@count+1){ |i| "#{i}-#{i+1}" }
time_labels[0] = "< 1"
-%>
&title=<%= t('stats.open_per_week') %>,{font-size:16},&
&y_legend=<%= t('stats.open_per_week_legend.actions') %>,10,0x736AFF&
&x_legend=<%= t('stats.open_per_week_legend.weeks') %>,11,0x736AFF&
&y_ticks=5,10,5&
&filled_bar=50,0x9933CC,0x8010A0&
&values=<%= @actions_open_per_week_array.join(",") -%>&
&x_labels=<%= time_labels.join(",")%>&
&y_min=0&
<%
# add one to @max for people who have no actions completed yet.
# OpenFlashChart cannot handle y_max=0
-%>
&y_max=<%=1+@max_actions+@max_actions/10-%>&
&x_label_style=9,,2,2&

View file

@ -255,7 +255,11 @@ en:
running_time: Running time of an action (weeks)
months_ago: Months ago
current_running_time_of_incomplete_visible_actions: Current running time of incomplete visible actions
totals_deferred_actions: of which %{count} are deferred actions in the tickler
open_per_week: Active (visible and hidden) next actions per week
open_per_week_legend:
actions: Actions
weeks: Weeks ago
totals_deferred_actions: "of which %{count} are deferred actions in the tickler"
running_time_legend:
actions: Actions
percentage: Percentage