From 9f5862d84200dc333d81e16ac23e611a9d218848 Mon Sep 17 00:00:00 2001 From: lukemelia Date: Wed, 26 Sep 2007 11:23:06 +0000 Subject: [PATCH] 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 --- tracks/app/controllers/stats_controller.rb | 48 ++++++++++++++----- tracks/app/views/stats/_tags.rhtml | 25 +++++++++- .../stats/actions_completion_time_data.rhtml | 16 ++++++- .../stats/actions_running_time_data.rhtml | 16 ++++++- .../actions_visible_running_time_data.rhtml | 16 ++++++- tracks/installation.html | 4 +- 6 files changed, 105 insertions(+), 20 deletions(-) diff --git a/tracks/app/controllers/stats_controller.rb b/tracks/app/controllers/stats_controller.rb index da5c6970..a30e8c85 100755 --- a/tracks/app/controllers/stats_controller.rb +++ b/tracks/app/controllers/stats_controller.rb @@ -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 diff --git a/tracks/app/views/stats/_tags.rhtml b/tracks/app/views/stats/_tags.rhtml index c424c6b1..16f8b8a0 100755 --- a/tracks/app/views/stats/_tags.rhtml +++ b/tracks/app/views/stats/_tags.rhtml @@ -1,6 +1,8 @@
-

Tag Cloud

-

+

Tag Cloud for all actions

+

This tag cloud includes tags of all actions (completed, not completed, visible and/or hidden)

+ +

<% if @tags_for_cloud.size < 1 %> no tags available <% else @@ -13,4 +15,23 @@ end end-%>

+
+ +
+

Tag Cloud actions in past 90 days

+

This tag cloud includes tags of actions that were created or completed in + the past 90 days.

+

+ <% 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-%> +

\ No newline at end of file diff --git a/tracks/app/views/stats/actions_completion_time_data.rhtml b/tracks/app/views/stats/actions_completion_time_data.rhtml index 2065c6f0..68e440f3 100755 --- a/tracks/app/views/stats/actions_completion_time_data.rhtml +++ b/tracks/app/views/stats/actions_completion_time_data.rhtml @@ -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& \ No newline at end of file diff --git a/tracks/app/views/stats/actions_running_time_data.rhtml b/tracks/app/views/stats/actions_running_time_data.rhtml index 30f3c651..700d3661 100755 --- a/tracks/app/views/stats/actions_running_time_data.rhtml +++ b/tracks/app/views/stats/actions_running_time_data.rhtml @@ -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& diff --git a/tracks/app/views/stats/actions_visible_running_time_data.rhtml b/tracks/app/views/stats/actions_visible_running_time_data.rhtml index 8aceae13..c858ea6a 100755 --- a/tracks/app/views/stats/actions_visible_running_time_data.rhtml +++ b/tracks/app/views/stats/actions_visible_running_time_data.rhtml @@ -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& \ No newline at end of file diff --git a/tracks/installation.html b/tracks/installation.html index af84e6fa..154cc918 100644 --- a/tracks/installation.html +++ b/tracks/installation.html @@ -5,9 +5,9 @@
  • Trac (for bug reports): http://dev.rousette.org.uk/report/6
  • Wiki (more info on installation): http://dev.rousette.org.uk/wiki
  • Author: bsag (http://www.rousette.org.uk/)
  • -
  • Contributors: Nicholas Lee, Lolindrath, Jim Ray, Arnaud Limbourg, Timothy Martens, Luke Melia, John Leonard (for great installation tutorials on Windows XP)
  • +
  • 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
  • Version: 1.04
  • -
  • Copyright: (cc) 2004-2006 rousette.org.uk
  • +
  • Copyright: (cc) 2004-2007 rousette.org.uk
  • License: GNU GPL