This commit is contained in:
Matt Rogers 2013-03-01 16:49:53 -06:00
commit 8b0f3e986a
9 changed files with 159 additions and 77 deletions

View file

@ -552,49 +552,11 @@ class StatsController < ApplicationController
end
def get_stats_tags
# tag cloud code inspired by this article
# http://www.juixe.com/techknow/index.php/2006/07/15/acts-as-taggable-tag-cloud/
tags = Stats::TagCloudQuery.new(current_user).result
@tag_cloud = Stats::TagCloud.new(tags)
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, todos"
query << " WHERE tags.id = tag_id"
query << " AND taggings.taggable_id = todos.id"
query << " AND todos.user_id="+current_user.id.to_s+" "
query << " AND taggings.taggable_type='Todo' "
query << " GROUP BY tags.id, tags.name"
query << " ORDER BY count DESC, name"
query << " LIMIT 100"
@tags_for_cloud = Tag.find_by_sql(query).sort_by { |tag| tag.name.downcase }
tag_counts = @tags_for_cloud.map(&:count)
max = tag_counts.max || 0
@tags_min = tag_counts.min || 0
@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 todos.user_id=? "
query << " AND taggings.taggable_type='Todo' "
query << " AND taggings.taggable_id=todos.id "
query << " AND (todos.created_at > ? OR "
query << " todos.completed_at > ?) "
query << " GROUP BY tags.id, tags.name"
query << " ORDER BY count DESC, name"
query << " LIMIT 100"
@tags_for_cloud_90days = Tag.find_by_sql(
[query, current_user.id, @cut_off_3months, @cut_off_3months]
).sort_by { |tag| tag.name.downcase }
tag_counts_90days = @tags_for_cloud_90days.map(&:count)
max_90days = tag_counts_90days.max || 0
@tags_min_90days = tag_counts_90days.min || 0
@tags_divisor_90days = ((max_90days - @tags_min_90days) / levels) + 1
tags = Stats::TagCloudQuery.new(current_user, @cut_off_3months).result
@tag_cloud_90days = Stats::TagCloud.new(tags)
end
def get_ids_from (actions, week_from, week_to, at_end)