Apply patch to improve graph and tag cloud rendering on stats page. Thanks to Reinier Balt for the patch! Fixes #566.

git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@597 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
lukemelia 2007-09-26 11:23:06 +00:00
parent 13732088be
commit 9f5862d842
6 changed files with 105 additions and 20 deletions

View file

@ -13,7 +13,7 @@ class StatsController < ApplicationController
@first_action = @actions.find(:first, :order => "created_at asc")
# default chart dimensions
@chart_width=450
@chart_width=460
@chart_height=250
@pie_width=@chart_width
@pie_height=325
@ -117,7 +117,7 @@ class StatsController < ApplicationController
# convert to hash to be able to fill in non-existing days in
# @actions_completion_time also convert days to weeks (/7)
@max_days, @max_actions=0,0
@max_days, @max_actions, @sum_actions=0,0,0
@actions_completion_time_hash = Hash.new(0)
@actions_completion_time.each do |days, total|
# RAILS_DEFAULT_LOGGER.error("\n" + total.to_s + " - " + days + "\n")
@ -125,6 +125,7 @@ class StatsController < ApplicationController
@max_days=days.to_i if days.to_i > @max_days
@max_actions = @actions_completion_time_hash[days.to_i/7] if @actions_completion_time_hash[days.to_i/7] > @max_actions
@sum_actions += total
end
# stop the chart after 10 weeks
@ -145,7 +146,7 @@ class StatsController < ApplicationController
# convert to hash to be able to fill in non-existing days in
# @actions_running_time also convert days to weeks (/7)
@max_days, @max_actions=0,0
@max_days, @max_actions, @sum_actions=0,0,0
@actions_running_time_hash = Hash.new(0)
@actions_running_time.each do |days, total|
# RAILS_DEFAULT_LOGGER.error("\n" + total.to_s + " - " + days + "\n")
@ -153,6 +154,7 @@ class StatsController < ApplicationController
@max_days=days.to_i if days.to_i > @max_days
@max_actions = @actions_running_time_hash[days.to_i/7] if @actions_running_time_hash[days.to_i/7] > @max_actions
@sum_actions += total
end
# cut off chart at 52 weeks = one year
@ -164,12 +166,6 @@ class StatsController < ApplicationController
def actions_visible_running_time_data
@actions = @user.todos
@actions_running_time = @actions.count(:all, {
:group => "datediff(now(), created_at)",
:conditions => "completed_at is null",
:order => "datediff(now(), created_at) ASC"
})
@actions_running_time = @actions.find_by_sql(
"SELECT datediff(now(), t.created_at) AS days, count(*) AS total "+
"FROM todos t LEFT OUTER JOIN projects p ON t.project_id = p.id LEFT OUTER JOIN contexts c ON t.context_id = c.id "+
@ -182,7 +178,7 @@ class StatsController < ApplicationController
# convert to hash to be able to fill in non-existing days in
# @actions_running_time also convert days to weeks (/7)
@max_days, @max_actions=0,0
@max_days, @max_actions, @sum_actions=0,0,0
@actions_running_time_hash = Hash.new(0)
@actions_running_time.each do |a|
# RAILS_DEFAULT_LOGGER.error("\n" + total.to_s + " - " + days + "\n")
@ -190,6 +186,7 @@ class StatsController < ApplicationController
@max_days=a.days.to_i if a.days.to_i > @max_days
@max_actions = @actions_running_time_hash[a.days.to_i/7] if @actions_running_time_hash[a.days.to_i/7] > @max_actions
@sum_actions += a.total.to_i
end
# cut off chart at 52 weeks = one year
@ -465,24 +462,49 @@ class StatsController < ApplicationController
# tag cloud code inspired by this article
# http://www.juixe.com/techknow/index.php/2006/07/15/acts-as-taggable-tag-cloud/
levels=10
# TODO: parameterize limit
# Get the tag cloud for all tags for actions
query = "SELECT tags.id, name, count(*) AS count"
query << " FROM taggings, tags"
query << " WHERE tags.id = tag_id"
query << " AND taggings.user_id="+@user.id.to_s+" "
query << " AND taggings.taggable_type='Todo' "
query << " GROUP BY tag_id"
query << " ORDER BY count DESC, name"
query << " LIMIT 100"
@tags_for_cloud = Tag.find_by_sql(query).sort_by { |tag| tag.name.downcase }
max, @tags_min = 0, 0
@tags_for_cloud.each { |t|
max = t.count.to_i if t.count.to_i > max
@tags_min = t.count.to_i if t.count.to_i < @tags_min
}
# 10 = number of levels
@tags_divisor = ((max - @tags_min) / 10) + 1
@tags_divisor = ((max - @tags_min) / levels) + 1
# Get the tag cloud for all tags for actions
query = "SELECT tags.id, tags.name AS name, count(*) AS count"
query << " FROM taggings, tags, todos"
query << " WHERE tags.id = tag_id"
query << " AND taggings.user_id="+@user.id.to_s+" "
query << " AND taggings.taggable_type='Todo' "
query << " AND taggings.taggable_id=todos.id "
query << " AND (datediff(now(), todos.created_at) < 90 OR "
query << " datediff(now(), todos.completed_at) < 90) "
query << " GROUP BY tag_id"
query << " ORDER BY count DESC, name"
query << " LIMIT 100"
@tags_for_cloud_90days = Tag.find_by_sql(query).sort_by { |tag| tag.name.downcase }
max_90days, @tags_min_90days = 0, 0
@tags_for_cloud_90days.each { |t|
max_90days = t.count.to_i if t.count.to_i > max_90days
@tags_min_90days = t.count.to_i if t.count.to_i < @tags_min_90days
}
@tags_divisor_90days = ((max_90days - @tags_min_90days) / levels) + 1
end
end

View file

@ -1,6 +1,8 @@
<div class="stats_module">
<h3>Tag Cloud</h3>
<p>
<h3>Tag Cloud for all actions</h3>
<p>This tag cloud includes tags of all actions (completed, not completed, visible and/or hidden)</p>
<p>
<% if @tags_for_cloud.size < 1
%> no tags available <%
else
@ -13,4 +15,23 @@
end
end-%>
</p>
</div>
<div class="stats_module">
<h3>Tag Cloud actions in past 90 days</h3>
<p>This tag cloud includes tags of actions that were created or completed in
the past 90 days.</p>
<p>
<% if @tags_for_cloud_90days.size < 1
%> no tags available <%
else
@tags_for_cloud_90days.each do |t| %>
<%= link_to t.name,
{:controller => "todos", :action => "tag", :id => t.name},
{:style => "font-size: " + (9 + 2*(t.count.to_i-@tags_min_90days)/@tags_divisor_90days).to_s + "pt",
:title => t.count+" actions"}
-%> <%
end
end-%>
</p>
</div>

View file

@ -1,5 +1,6 @@
&title=Completion time (all completed actions),{font-size:16},&
&y_legend=Actions,12,0x736AFF&
&y_legend=Actions,10,0x8010A0&
&y2_legend=Percentage,10,0xFF0000&
&x_legend=Running time of an action (weeks),12,0x736AFF&
&y_ticks=5,10,5&
&filled_bar=50,0x9933CC,0x8010A0&
@ -14,6 +15,15 @@
@sum += @actions_completion_time_hash[i]
end -%>
<%=@sum%>&
&line_2=2,0xFF0000&
&values_2=
<% total=0
@count = @max_days > @cut_off*7 ? @cut_off : @max_days/7
0.upto @count-1 do |i|
total += @actions_completion_time_hash[i]*100.0/@sum_actions -%>
<%= total -%>,
<% end -%>
<%= total+@sum*100.0/@sum_actions%>&
&x_labels=within 1,
<% 1.upto @count-1 do |i| -%>
<%= i %>-<%= i+1 %>,
@ -23,4 +33,8 @@
<% # 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-%>&
&show_y2=true&
&y2_lines=2&
&y2_min=0&
&y2_max=100&
&x_label_style=9,,2,1&

View file

@ -1,5 +1,6 @@
&title=Current running time of all uncompleted actions,{font-size:16},&
&y_legend=Actions,12,0x736AFF&
&y_legend=Actions,10,0x736AFF&
&y2_legend=Percentage,10,0xFF0000&
&x_legend=Running time of an action (weeks),12,0x736AFF&
&y_ticks=5,10,5&
&filled_bar=50,0x9933CC,0x8010A0&
@ -14,6 +15,15 @@
@sum += @actions_running_time_hash[i]
end -%>
<%=@sum%>&
&line_2=2,0xFF0000&
&values_2=
<% total=0
@count = @max_days > @cut_off*7 ? @cut_off : @max_days/7
0.upto @count-1 do |i|
total += @actions_running_time_hash[i] -%>
<%= total*100.0/@sum_actions -%>,
<% end -%>
<%= (total+@sum)*100.0/@sum_actions%>&
&x_labels=< 1,
<% 1.upto @count-1 do |i| -%>
<%= i %>-<%= i+1 %>,
@ -25,3 +35,7 @@
# OpenFlashChart cannot handle y_max=0 -%>
&y_max=<%=1+@max_actions+@max_actions/10-%>&
&x_label_style=9,,2,2&
&show_y2=true&
&y2_lines=2&
&y2_min=0&
&y2_max=100&

View file

@ -1,5 +1,6 @@
&title=Current running time of uncompleted visible actions,{font-size:16},&
&y_legend=Actions,12,0x736AFF&
&y_legend=Actions,10,0x736AFF&
&y2_legend=Percentage,10,0xFF0000&
&x_legend=Running time of an action (weeks),12,0x736AFF&
&y_ticks=5,10,5&
&filled_bar=50,0x9933CC,0x8010A0&
@ -14,6 +15,15 @@
@sum += @actions_running_time_hash[i]
end -%>
<%=@sum%>&
&line_2=2,0xFF0000&
&values_2=
<% total=0
@count = @max_days > @cut_off*7 ? @cut_off : @max_days/7
0.upto @count-1 do |i|
total += @actions_running_time_hash[i] -%>
<%= total*100.0/@sum_actions -%>,
<% end -%>
<%= (total+@sum)*100.0/@sum_actions%>&
&x_labels=< 1,
<% 1.upto @count-1 do |i| -%>
<%= i %>-<%= i+1 %>,
@ -25,3 +35,7 @@
# OpenFlashChart cannot handle y_max=0 -%>
&y_max=<%=1+@max_actions+@max_actions/10-%>&
&x_label_style=9,,2,2&
&show_y2=true&
&y2_lines=2&
&y2_min=0&
&y2_max=100&

View file

@ -5,9 +5,9 @@
<li>Trac (for bug reports): http://dev.rousette.org.uk/report/6</li>
<li>Wiki (more info on installation): http://dev.rousette.org.uk/wiki</li>
<li>Author: bsag (http://www.rousette.org.uk/)</li>
<li>Contributors: Nicholas Lee, Lolindrath, Jim Ray, Arnaud Limbourg, Timothy Martens, Luke Melia, John Leonard (for great installation tutorials on Windows XP)</li>
<li>Contributors: Nicholas Lee, Lolindrath, Jim Ray, Arnaud Limbourg, Timothy Martens, Luke Melia, John Leonard (for great installation tutorials on Windows XP), Reinier Balt, Jacqui Maher, James Kebinger</li>
<li>Version: 1.04</li>
<li>Copyright: (cc) 2004-2006 rousette.org.uk</li>
<li>Copyright: (cc) 2004-2007 rousette.org.uk</li>
<li>License: GNU GPL</li>
</ul>