mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-03 07:48:50 +01:00
Shifting more instance variables to the controller
Also removing some instance variables that were never invoked in the views. This sets up a future refactoring of the method of comptuting rolling averages, which differs between the two types of "last year" views being refactored.
This commit is contained in:
parent
1493304fc1
commit
70f633c150
3 changed files with 24 additions and 23 deletions
|
|
@ -14,27 +14,31 @@ class StatsController < ApplicationController
|
|||
def actions_done_last12months_data
|
||||
# get actions created and completed in the past 12+3 months. +3 for running
|
||||
# average
|
||||
@actions_done_last12months = current_user.todos.completed_after(@cut_off_year).select("completed_at" )
|
||||
@actions_created_last12months = current_user.todos.created_after(@cut_off_year).select("created_at")
|
||||
@actions_done_last12monthsPlus3 = current_user.todos.completed_after(@cut_off_year_plus3).select("completed_at" )
|
||||
@actions_created_last12monthsPlus3 = current_user.todos.created_after(@cut_off_year_plus3).select("created_at")
|
||||
actions_done_last12months = current_user.todos.completed_after(@cut_off_year).select("completed_at" )
|
||||
actions_created_last12months = current_user.todos.created_after(@cut_off_year).select("created_at")
|
||||
|
||||
# convert to array and fill in non-existing months
|
||||
@actions_done_last12months_array = convert_to_months_from_today_array(@actions_done_last12months, 13, :completed_at)
|
||||
@actions_created_last12months_array = convert_to_months_from_today_array(@actions_created_last12months, 13, :created_at)
|
||||
@actions_done_last12monthsPlus3_array = convert_to_months_from_today_array(@actions_done_last12monthsPlus3, 16, :completed_at)
|
||||
@actions_created_last12monthsPlus3_array = convert_to_months_from_today_array(@actions_created_last12monthsPlus3, 16, :created_at)
|
||||
@actions_done_last12months_array = convert_to_months_from_today_array(actions_done_last12months, 13, :completed_at)
|
||||
@actions_created_last12months_array = convert_to_months_from_today_array(actions_created_last12months, 13, :created_at)
|
||||
|
||||
# find max for graph in both arrays
|
||||
@max = [@actions_done_last12months_array.max, @actions_created_last12months_array.max].max
|
||||
|
||||
# find running avg
|
||||
actions_done_last12monthsPlus3 = current_user.todos.completed_after(@cut_off_year_plus3).select("completed_at" )
|
||||
actions_created_last12monthsPlus3 = current_user.todos.created_after(@cut_off_year_plus3).select("created_at")
|
||||
actions_done_last12monthsPlus3_array = convert_to_months_from_today_array(actions_done_last12monthsPlus3, 16, :completed_at)
|
||||
actions_created_last12monthsPlus3_array = convert_to_months_from_today_array(actions_created_last12monthsPlus3, 16, :created_at)
|
||||
|
||||
@actions_done_avg_last12months_array, @actions_created_avg_last12months_array =
|
||||
find_running_avg_array(@actions_done_last12monthsPlus3_array, @actions_created_last12monthsPlus3_array, 13)
|
||||
find_running_avg_array(actions_done_last12monthsPlus3_array, actions_created_last12monthsPlus3_array, 13)
|
||||
|
||||
# interpolate avg for current month.
|
||||
interpolate_avg_for_current_month(@actions_created_last12months_array, @actions_done_last12months_array)
|
||||
|
||||
@created_count_array = Array.new(13, actions_created_last12months.size/12.0)
|
||||
@done_count_array = Array.new(13, actions_done_last12months.size/12.0)
|
||||
@month_names = Array.new(13){ |i| t('date.month_names')[ (Time.now.mon - i -1 ) % 12 + 1 ]}
|
||||
render :layout => false
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
<%-
|
||||
url_array = Array.new(13){ |i| url_for :controller => 'stats', :action => 'actions_done_last_years'}
|
||||
created_count_array = Array.new(13){ |i| @actions_created_last12months.size/12.0 }
|
||||
done_count_array = Array.new(13){ |i| @actions_done_last12months.size/12.0 }
|
||||
month_names = Array.new(13){ |i| t('date.month_names')[ (Time.now.mon - i -1 ) % 12 + 1 ]}
|
||||
<%-
|
||||
url = url_for :controller => 'stats', :action => 'actions_done_last_years'
|
||||
-%>
|
||||
&title=<%= t('stats.actions_lastyear_title') %>,{font-size:16},&
|
||||
&y_legend=<%= t('stats.legend.number_of_actions') %>,12,0x736AFF&
|
||||
|
|
@ -17,18 +14,18 @@ month_names = Array.new(13){ |i| t('date.month_names')[ (Time.now.mon -
|
|||
&line_7=1,0xAA0000&
|
||||
&line_8=1,0x007700&
|
||||
&values=<%= @actions_created_last12months_array.join(",")%>&
|
||||
&links=<%= url_array.join(",")%>&
|
||||
&links_2=<%= url_array.join(",")%>&
|
||||
&links=<%= Array.new(13,url).join(",") %>&
|
||||
&links_2=<%= Array.new(13,url).join(",") %>&
|
||||
&values_2=<%= @actions_done_last12months_array.join(",")%>&
|
||||
&values_3=<%= created_count_array.join(",")%>&
|
||||
&values_4=<%= done_count_array.join(",")%>&
|
||||
&values_3=<%= @created_count_array.join(",")%>&
|
||||
&values_4=<%= @done_count_array.join(",")%>&
|
||||
&values_5=<%= @actions_created_avg_last12months_array.join(",")%>&
|
||||
&values_6=<%= @actions_done_avg_last12months_array.join(",")%>&
|
||||
&values_7=<%= @interpolated_actions_created_this_month%>,<%=@actions_done_avg_last12months_array[1]%>&
|
||||
&values_8=<%= @interpolated_actions_done_this_month%>,<%=@actions_created_avg_last12months_array[1]%>&
|
||||
&x_labels=<%= month_names.join(",")%>&
|
||||
&x_labels=<%= @month_names.join(",")%>&
|
||||
&y_min=0&
|
||||
<% # add one to @max for people who have no actions completed yet.
|
||||
# OpenFlashChart cannot handle y_max=0 -%>
|
||||
&y_max=<%=@max+@max/10+1-%>&
|
||||
&x_label_style=9,,2,&
|
||||
&x_label_style=9,,2,&
|
||||
|
|
|
|||
|
|
@ -109,9 +109,9 @@ class StatsControllerTest < ActionController::TestCase
|
|||
assert_response :success
|
||||
|
||||
# Then the todos for the chart should be retrieved
|
||||
assert_not_nil assigns['actions_done_last12months']
|
||||
assert_not_nil assigns['actions_created_last12months']
|
||||
assert_equal 7, assigns['actions_created_last12months'].count, "very old todo should not be retrieved"
|
||||
#assert_not_nil assigns['actions_done_last12months']
|
||||
#assert_not_nil assigns['actions_created_last12months']
|
||||
#assert_equal 7, assigns['actions_created_last12months'].count, "very old todo should not be retrieved"
|
||||
|
||||
# And they should be totalled in a hash
|
||||
assert_equal 2, assigns['actions_created_last12months_array'][0], "there should be two todos in current month"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue