change the algorithm of tag cloud.

This commit is contained in:
Matthew K. Fu JuYuan 2012-08-01 18:15:10 +08:00
parent acebec8904
commit ee5ac0227e
1 changed files with 13 additions and 15 deletions

View File

@ -11,38 +11,36 @@ class Tag
belongs_to :module_app
def cloud_amper
for_now = {:start_at=>20.days.ago,:end_at=>Time.now}
for_yesterday = {:start_at=>19.days.ago,:end_at=>1.days.ago}
for_now = {:start_at=>14.days.ago,:end_at=>Time.now}
for_yesterday = {:start_at=>15.days.ago,:end_at=>1.days.ago}
range = self.class.all.collect{ |tag|
get_impressionist_diff(tag)
get_impressionist(tag)
}
range.sort!.reverse!.uniq!
offset_size = range.size+4
section_3 = range.last..range[-(offset_size/4)]
section_2 = range[-(offset_size/4)-1]..range[-2*(offset_size/4)] rescue nil
section_1 = range[-2*(offset_size/4)-1]..range[1] rescue nil
section_3 = range.first..range[(offset_size/4)]
section_2 = range[(offset_size/4)+1]..range[2*(offset_size/4)] rescue nil
section_1 = range[2*(offset_size/4)+1]..last rescue nil
case get_impressionist_diff
case get_impressionist
when range.first
return :heading1
return :hot1
when section_1
return :heading2
return :hot2
when section_2
return :heading3
return :hot3
when section_3
return :heading4
return :hot4
end
end
protected
def get_impressionist_diff(item_tag = self)
for_now = item_tag.impressions.where(:created_at.gte=> 20.days.ago,:created_at.lte => Time.now).count
for_yesterday = item_tag.impressions.where(:created_at.gte=> 21.days.ago,:created_at.lte => 1.days.ago).count
for_now - for_yesterday
def get_impressionist(item_tag = self)
item_tag.impressions.where(:created_at.gte=> 14.days.ago,:created_at.lte => Time.now).count
end
end