class Octo::UserPersona

Constants

DEAD
HIGH_ENGAGED
LOW_ENGAGED
MEDIUM_ENGAGED

Public Class Methods

aggregate(res) click to toggle source
# File lib/octocore-mongo/models/user/user_persona.rb, line 70
def self.aggregate(res)
  personas = [:categories, :tags, :trending]
  personas.inject({}) do |result, p|
    result[p] = res.collect do |r|
      r.send(p)
    end.inject({}) do |sum, values|
      values.each do |k,v|
        sum[k] = sum.fetch(k, 0) + v
        sum
      end
    end
    result
  end
end
engaged_text(val) click to toggle source
# File lib/octocore-mongo/models/user/user_persona.rb, line 26
def self.engaged_text(val)
  _engaged_text val
end
fakedata(user, ts) click to toggle source
# File lib/octocore-mongo/models/user/user_persona.rb, line 30
def self.fakedata(user, ts)
  args = {
    user_enterprise_id: user.enterprise._id,
    user_id: user._id,
    ts: ts
  }
  res = self.where(args)
  if res.count < 1
    categories = Hash[Octo::Category.first(rand(1..Octo::Category.count)).collect do |x|
      [x.cat_text, rand(20..200)]
    end]
    tags = Hash[Octo::Tag.first(rand(1..Octo::Tag.count)).collect do |x|
      [x.tag_text, rand(20.200)]
    end]
    trending = ['trending', 'non trending'].collect do |x|
      [x, rand(10..50)]
    end
    args = {
      user: user,
      categories: categories,
      tags: tags,
      trending: trending,
      engagement: rand(0..3)
    }
    res = []
    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})
        res << self.new(_args).save!
      end
    elsif ts.class == Time
      _args = args.merge({ts: ts})
      res << self.new(_args).save!
    end
  end
  self.aggregate res
end

Public Instance Methods

engaged_text() click to toggle source
# File lib/octocore-mongo/models/user/user_persona.rb, line 22
def engaged_text
  _engaged_text self.engagement
end

Private Instance Methods

_engaged_text(val) click to toggle source
# File lib/octocore-mongo/models/user/user_persona.rb, line 87
def _engaged_text(val)
  case val
  when HIGH_ENGAGED
    'Highly Engaged'
  when MEDIUM_ENGAGED
    'Moderately Engaged'
  when LOW_ENGAGED
    'Low Engagement'
  when DEAD
    'Slipping Out'
  end
end