finished tag clouds

This commit is contained in:
Matthew K. Fu JuYuan 2012-07-31 11:57:32 +08:00
parent af4865ceb7
commit 7e3b59c09a
5 changed files with 61 additions and 7 deletions

View File

@ -14,16 +14,34 @@ class Tag
for_now = {:start_at=>20.days.ago,:end_at=>Time.now}
for_yesterday = {:start_at=>19.days.ago,:end_at=>1.days.ago}
range = self.class.all.collect{ |tag|
get_impressionist_diff(tag)
}
(get_impressionist_diff - range.min).abs
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
case get_impressionist_diff
when range.first
return :heading1
when section_1
return :heading2
when section_2
return :heading3
when section_3
return :heading4
end
end
protected
def get_impressionist_diff(item_tag = self)
for_now = item_tag.impressionist_count(:start_date=>20.days.ago,:end_date=>Time.now)
for_yesterday = item_tag.impressionist_count(:start_date=>21.days.ago,:end_date=>1.days.ago)
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
end

View File

@ -14,5 +14,5 @@ Redis::Search.configure do |config|
# use rmmseg, true to disable it, it can save memroy
config.disable_rmmseg = false
end
Bulletin.new
NewsBulletin.new
# Bulletin.new
# NewsBulletin.new

View File

@ -8,4 +8,40 @@ namespace :matt_dev do
p a
# p Pinyin.t('台灣不是中國的一部分')
end
task :testing_new_tag_cal do
ranges = [[1],[1,2],[1,2,3],[1,2,3,4],[1,2,3,4,5],[1,2,3,4,5,6],[1,2,3,4,5,6,7],[1,2,3,4,5,6,7,8],[1,2,3,4,5,6,7,8,9],[1,2,3,4,5,6,7,8,9,10],[1,2,3,4,5,6,7,8,9,10,11],[1,2,3,4,5,6,7,8,9,10,11,12],[-1,-2,-3,-4,5,6,7,8,9,10,11,12]]
ranges.each{ |range|
cal(range)
}
end
def cal(range_t)
range = range_t.sort.reverse
puts '='*20
puts range.to_s
puts '='*20
offset_size = range.size+4
section_3 = range.last..range[-(offset_size/4)]
puts(section_3)
section_2 = range[-(offset_size/4)-1]..range[-2*(offset_size/4)] rescue nil
puts(section_2)
section_1 = range[-2*(offset_size/4)-1]..range[1] rescue nil
puts(section_1)
range.each{|num|
result= case num
when range.first
:heading1
when section_1
:heading2
when section_2
:heading3
when section_3
:heading4
end
puts "Num:#{num} Result: #{result}"
}
puts("END")
end
end

View File

@ -13,7 +13,7 @@
<h3 class="h3"><%= t('announcement.tag_cloud') %></h3>
<div class="cloud">
<% @tags.each do |tag| %>
<%= link_to tag[I18n.locale], panel_announcement_front_end_bulletins_path(:tag_id => tag.id), :class => "hot#{rand(4) + 1} #{(tag.id.to_s.eql?(params[:tag_id]) || tag.key.eql?(params[:tag_id])) ? 'active' : nil}" %>
<%= link_to tag[I18n.locale], panel_announcement_front_end_bulletins_path(:tag_id => tag.id), :class => "#{tag.cloud_amper} hot#{rand(4) + 1} #{(tag.id.to_s.eql?(params[:tag_id]) || tag.key.eql?(params[:tag_id])) ? 'active' : nil} " %>
<% end %>
</div>
</div>

View File

@ -13,7 +13,7 @@
<h3 class="h3"><%= t('announcement.tag_cloud') %></h3>
<div class="cloud">
<% @tags.each do |tag| %>
<%= link_to tag[I18n.locale], panel_news_front_end_news_bulletins_path(:tag_id => tag.id),:class => "hot#{rand(4) + 1} #{(tag.id.to_s.eql?(params[:tag_id]) || tag.key.eql?(params[:tag_id])) ? 'active' : nil}" %>
<%= link_to tag[I18n.locale], panel_news_front_end_news_bulletins_path(:tag_id => tag.id),:class => "#{tag.cloud_amper} hot#{rand(4) + 1} #{(tag.id.to_s.eql?(params[:tag_id]) || tag.key.eql?(params[:tag_id])) ? 'active' : nil} " %>
<% end %>
</div>
</div>