Class: Octo::UserPersona
Constant Summary
collapse
- HIGH_ENGAGED =
0
- MEDIUM_ENGAGED =
1
- LOW_ENGAGED =
2
- DEAD =
3
MongoMapper::Document::DUMP_ATTRS
Class Method Summary
collapse
Instance Method Summary
collapse
#marshal_dump, #marshal_load, redis, update_cache_config
Class Method Details
.aggregate(res) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# 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) ⇒ Object
26
27
28
|
# File 'lib/octocore-mongo/models/user/user_persona.rb', line 26
def self.engaged_text(val)
_engaged_text val
end
|
.fakedata(user, ts) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# 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
|
Instance Method Details
#engaged_text ⇒ Object
22
23
24
|
# File 'lib/octocore-mongo/models/user/user_persona.rb', line 22
def engaged_text
_engaged_text self.engagement
end
|