Orbit/app/models/tag.rb

29 lines
835 B
Ruby

class Tag
include Mongoid::Document
include Mongoid::Timestamps
include Impressionist::Impressionable
is_impressionable :counter_cache => { :column_name => :view_count }
field :key
#field :cloud_amper,:type: Integer,:default=> 0
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}
range = self.class.all.collect{ |tag|
get_impressionist_diff(tag)
}
(get_impressionist_diff - range.min).abs
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 - for_yesterday
end
end