Statistics for longest running projects now includes completed and hidden projects. fixes #1725

This commit is contained in:
Reinier Balt 2014-11-05 17:07:21 +01:00
parent ff9edcc309
commit 2883d1b7f4
6 changed files with 57 additions and 27 deletions

View file

@ -138,6 +138,14 @@ class Project < ActiveRecord::Base
@age_in_days ||= (Time.current.to_date - created_at.to_date).to_i + 1
end
def running_time
if completed_at.nil?
return age_in_days
else
return (completed_at.to_date - created_at.to_date).to_i + 1
end
end
def self.import(filename, params, user)
count = 0
CSV.foreach(filename, headers: true) do |row|

View file

@ -7,7 +7,7 @@ module Stats
end
def runtime
@runtime ||= user.projects.active.order('created_at ASC').limit(10)
@runtime ||= find_top10_longest_running_projects
end
def actions
@ -18,5 +18,12 @@ module Stats
@actions_last30days ||= Stats::TopProjectsQuery.new(user, 1.month.ago.beginning_of_day).result
end
private
def find_top10_longest_running_projects
projects = user.projects.order('created_at ASC')
projects.sort{|a,b| b.running_time <=> a.running_time}.take(10)
end
end
end

View file

@ -1,5 +1,5 @@
<% @swf_count ||= 0 -%>
<div class="open-flash-chart"><%= swf_tag asset_path("open-flash-chart.swf"),
<div class="open-flash-chart"><%= swf_tag "open-flash-chart.swf",
:flashvars => { 'width' => chart.width, 'height' => chart.height, 'data' => url_for(:action => chart.action)},
:parameters => { 'allowScriptAccess' => 'sameDomain', 'wmode' => 'transparent'},
:div_id => "chart_#{@swf_count+=1}",

View file

@ -2,5 +2,4 @@
<%= render :partial => 'projects_list', :locals => {:projects => projects.actions_last30days, :key => 'projects_30days', :n => :count} -%>
<%= render :partial => 'projects_list', :locals => {:projects => projects.runtime, :key => 'longrunning', :n => :age_in_days} -%>
<%= render :partial => 'projects_list', :locals => {:projects => projects.runtime, :key => 'longrunning', :n => :running_time, :i18n_key => "days_midsentence"} -%>

View file

@ -1,7 +1,8 @@
<%- i18n_key ||= "actions_midsentence" -%>
<div class="stats_module">
<h3><%= t("stats.top10_#{key}") %></h3>
<% projects.each_with_index do |p, i| -%>
<%= i + 1 -%> - <%= link_to p.name, project_path(p) %> (<%=p.send(n)%> <%= t('common.actions_midsentence', :count => p.send(n)) %>) <br/>
<%= i + 1 -%> - <%= link_to p.name, project_path(p) %> (<%=p.send(n)%> <%= t("common.#{i18n_key}", :count => p.send(n)) %>) <br/>
<% end -%>
<%= render :partial => 'null_list_item', :locals => {:from => projects.size + 1, :to => 10} -%>
</div>

View file

@ -238,4 +238,19 @@ class ProjectTest < ActiveSupport::TestCase
assert_equal 8, p2.age_in_days
end
def test_running_time
p = users(:admin_user).projects.create!(:name => "test8")
p.created_at = 1.week.ago
p.save!
p.reload
assert_equal 8, p.running_time
p.completed_at = 4.days.ago
p.save!
p.reload
assert_equal 4, p.running_time
end
end