Class: Octo::NewsfeedHit

Inherits:
Object
  • Object
show all
Extended by:
Counter, Scheduleable
Includes:
Cequel::Record
Defined in:
lib/octocore/models/enterprise/newsfeed_hit.rb

Constant Summary collapse

COUNTERS =
20

Constants included from Counter

Counter::COUNTER_KEY_PREFIX, Counter::INDEX_KEY_PREFIX, Counter::SEPARATOR, Counter::TYPE_DAY, Counter::TYPE_DAY_3, Counter::TYPE_DAY_6, Counter::TYPE_HOUR, Counter::TYPE_HOUR_12, Counter::TYPE_HOUR_3, Counter::TYPE_HOUR_6, Counter::TYPE_MINUTE, Counter::TYPE_MINUTE_30, Counter::TYPE_WEEK

Constants included from Counter::Helper

Counter::Helper::METHOD_PREFIX

Constants included from Cequel::Record

Cequel::Record::DUMP_ATTRS

Class Method Summary collapse

Methods included from Counter

aggregate, aggregate!, aggregate_and_create, call_completion_hook, countables, increment_for, local_count, local_counter_sum, update_counters

Methods included from Counter::Helper

counter_text, #generate_aggregators, #get_duration_for_counter_type, #get_fromtype_for_totype, #get_typecounters, #max_type, #method_names_type_counter, #string_to_const_val, #type_counters_method_names

Methods included from Scheduleable

perform

Methods included from Cequel::Record

#marshal_dump, #marshal_load, redis, update_cache_config

Class Method Details

.fakedata(args) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/octocore/models/enterprise/newsfeed_hit.rb', line 24

def self.fakedata(args)
  res = self.where(args)

  enterprise = Octo::Enterprise.find_by_id(args[:enterprise_id])
  if res.count == 0 and enterprise.fakedata?
    unless args.has_key?(:uid)
      args[:uid] = 'newsfeed'
    end
    res = []
    ts = args.fetch(:ts, 7.days.ago..Time.now)
    if ts.class == Range
      start_ts = ts.begin.beginning_of_day
      end_ts = ts.end.end_of_day
      start_ts.to(end_ts, 1.day).each do |_ts|
        _args = args.merge({ ts: _ts, count: rand(400..700) })
        res << self.new(_args).save!
      end
    elsif ts.class == Time
      _args = args.merge({ count: rand(400..800) })
      res << self.new(_args).save!
    end
  end
  res
end