From ee5ac0227e486f8c4b01fc5a16d52cb0197a5496 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Wed, 1 Aug 2012 18:15:10 +0800 Subject: [PATCH] change the algorithm of tag cloud. --- app/models/tag.rb | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/app/models/tag.rb b/app/models/tag.rb index c9c32496..fbf57615 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -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