47 lines
1.1 KiB
Ruby
47 lines
1.1 KiB
Ruby
class Tag
|
|
include Mongoid::Document
|
|
include Mongoid::Timestamps
|
|
include Impressionist::Impressionable
|
|
|
|
is_impressionable :counter_cache => { :column_name => :view_count }
|
|
|
|
field :key
|
|
field :view_count, :type => Integer, :default => 0
|
|
#field :cloud_amper,:type: Integer,:default=> 0
|
|
belongs_to :module_app
|
|
|
|
def cloud_amper
|
|
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(tag)
|
|
}
|
|
range.sort!.reverse!.uniq!
|
|
offset_size = range.size+4
|
|
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
|
|
when range.first
|
|
return :hot1
|
|
when section_1
|
|
return :hot2
|
|
when section_2
|
|
return :hot3
|
|
when section_3
|
|
return :hot4
|
|
end
|
|
|
|
end
|
|
|
|
protected
|
|
def get_impressionist(item_tag = self)
|
|
item_tag.impressions.where(:created_at.gte=> 14.days.ago,:created_at.lte => Time.now).count
|
|
end
|
|
|
|
end
|