mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-27 04:18:49 +01:00
Rename variables
The current user isn't necessarily current when it is in the model layer. The exposed attributes on the tag cloud no longer need to contain type information.
This commit is contained in:
parent
8f6d57014a
commit
edc793e703
2 changed files with 24 additions and 24 deletions
|
|
@ -555,12 +555,12 @@ class StatsController < ApplicationController
|
|||
cloud = Stats::TagCloud.new(current_user, @cut_off_3months)
|
||||
cloud.compute
|
||||
|
||||
@tags_for_cloud = cloud.tags_for_cloud
|
||||
@tags_min = cloud.tags_min
|
||||
@tags_divisor = cloud.tags_divisor
|
||||
@tags_for_cloud_90days = cloud.tags_for_cloud_90days
|
||||
@tags_min_90days = cloud.tags_min_90days
|
||||
@tags_divisor_90days = cloud.tags_divisor_90days
|
||||
@tags_for_cloud = cloud.tags
|
||||
@tags_min = cloud.min
|
||||
@tags_divisor = cloud.divisor
|
||||
@tags_for_cloud_90days = cloud.tags_90days
|
||||
@tags_min_90days = cloud.min_90days
|
||||
@tags_divisor_90days = cloud.divisor_90days
|
||||
end
|
||||
|
||||
def get_ids_from (actions, week_from, week_to, at_end)
|
||||
|
|
|
|||
|
|
@ -3,12 +3,12 @@
|
|||
module Stats
|
||||
class TagCloud
|
||||
|
||||
attr_reader :current_user,
|
||||
:tags_for_cloud, :tags_min, :tags_divisor,
|
||||
:tags_for_cloud_90days, :tags_min_90days, :tags_divisor_90days
|
||||
def initialize(current_user, cut_off_3months)
|
||||
@current_user = current_user
|
||||
@cut_off_3months = cut_off_3months
|
||||
attr_reader :user, :cutoff,
|
||||
:tags, :min, :divisor,
|
||||
:tags_90days, :min_90days, :divisor_90days
|
||||
def initialize(user, cutoff)
|
||||
@user = user
|
||||
@cutoff = cutoff
|
||||
end
|
||||
|
||||
def compute
|
||||
|
|
@ -20,20 +20,20 @@ module Stats
|
|||
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 todos.user_id="+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 }
|
||||
@tags = Tag.find_by_sql(query).sort_by { |tag| tag.name.downcase }
|
||||
|
||||
max, @tags_min = 0, 0
|
||||
@tags_for_cloud.each { |t|
|
||||
max, @min = 0, 0
|
||||
@tags.each { |t|
|
||||
max = [t.count.to_i, max].max
|
||||
@tags_min = [t.count.to_i, @tags_min].min
|
||||
@min = [t.count.to_i, @min].min
|
||||
}
|
||||
|
||||
@tags_divisor = ((max - @tags_min) / levels) + 1
|
||||
@divisor = ((max - @min) / levels) + 1
|
||||
|
||||
# Get the tag cloud for all tags for actions
|
||||
query = "SELECT tags.id, tags.name AS name, count(*) AS count"
|
||||
|
|
@ -47,17 +47,17 @@ module Stats
|
|||
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]
|
||||
@tags_90days = Tag.find_by_sql(
|
||||
[query, user.id, cutoff, cutoff]
|
||||
).sort_by { |tag| tag.name.downcase }
|
||||
|
||||
max_90days, @tags_min_90days = 0, 0
|
||||
@tags_for_cloud_90days.each { |t|
|
||||
max_90days, @min_90days = 0, 0
|
||||
@tags_90days.each { |t|
|
||||
max_90days = [t.count.to_i, max_90days].max
|
||||
@tags_min_90days = [t.count.to_i, @tags_min_90days].min
|
||||
@min_90days = [t.count.to_i, @min_90days].min
|
||||
}
|
||||
|
||||
@tags_divisor_90days = ((max_90days - @tags_min_90days) / levels) + 1
|
||||
@divisor_90days = ((max_90days - @min_90days) / levels) + 1
|
||||
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue