2012-02-14 16:32:20 +00:00
|
|
|
class Tag
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
2012-07-30 03:59:20 +00:00
|
|
|
include Impressionist::Impressionable
|
2012-02-14 16:32:20 +00:00
|
|
|
|
2012-07-30 03:59:20 +00:00
|
|
|
is_impressionable :counter_cache => { :column_name => :view_count }
|
2012-07-30 09:57:55 +00:00
|
|
|
|
2012-05-08 09:27:42 +00:00
|
|
|
field :key
|
2012-07-30 09:57:55 +00:00
|
|
|
field :view_count, :type => Integer, :default => 0
|
2012-07-30 03:59:20 +00:00
|
|
|
#field :cloud_amper,:type: Integer,:default=> 0
|
2012-02-14 16:32:20 +00:00
|
|
|
belongs_to :module_app
|
|
|
|
|
2012-07-30 03:59:20 +00:00
|
|
|
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}
|
|
|
|
|
2012-07-31 03:57:32 +00:00
|
|
|
|
2012-07-30 03:59:20 +00:00
|
|
|
range = self.class.all.collect{ |tag|
|
|
|
|
get_impressionist_diff(tag)
|
|
|
|
}
|
2012-07-31 03:57:32 +00:00
|
|
|
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
|
|
|
|
|
2012-07-30 03:59:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
def get_impressionist_diff(item_tag = self)
|
2012-07-31 03:57:32 +00:00
|
|
|
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
|
2012-07-30 03:59:20 +00:00
|
|
|
for_now - for_yesterday
|
|
|
|
end
|
|
|
|
|
2012-02-14 16:32:20 +00:00
|
|
|
end
|