octocore-mongo 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGES.md +12 -0
- data/CONTRIBUTING +0 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +150 -0
- data/LICENSE +202 -0
- data/MAINTAINERS +0 -0
- data/NOTICE +8 -0
- data/README.md +69 -0
- data/Rakefile +51 -0
- data/bin/fakestream-mongo +258 -0
- data/bin/octocore-admin-mongo +54 -0
- data/lib/octocore-mongo.rb +157 -0
- data/lib/octocore-mongo/baseline.rb +131 -0
- data/lib/octocore-mongo/callbacks.rb +117 -0
- data/lib/octocore-mongo/config.rb +39 -0
- data/lib/octocore-mongo/config/config.yml +1 -0
- data/lib/octocore-mongo/config/search/index/user.yml +42 -0
- data/lib/octocore-mongo/counter.rb +265 -0
- data/lib/octocore-mongo/counter/helpers.rb +168 -0
- data/lib/octocore-mongo/email.rb +63 -0
- data/lib/octocore-mongo/featureflag.rb +79 -0
- data/lib/octocore-mongo/helpers.rb +6 -0
- data/lib/octocore-mongo/helpers/api_consumer_helper.rb +51 -0
- data/lib/octocore-mongo/helpers/api_helper.rb +65 -0
- data/lib/octocore-mongo/helpers/api_logger.rb +14 -0
- data/lib/octocore-mongo/helpers/client_helper.rb +104 -0
- data/lib/octocore-mongo/helpers/kong_helper.rb +164 -0
- data/lib/octocore-mongo/helpers/sinatra_helper.rb +22 -0
- data/lib/octocore-mongo/kafka_bridge.rb +60 -0
- data/lib/octocore-mongo/kldivergence.rb +14 -0
- data/lib/octocore-mongo/mailer.rb +1 -0
- data/lib/octocore-mongo/mailer/subscriber_mailer.rb +32 -0
- data/lib/octocore-mongo/message_parser.rb +114 -0
- data/lib/octocore-mongo/models.rb +275 -0
- data/lib/octocore-mongo/models/contactus.rb +42 -0
- data/lib/octocore-mongo/models/enterprise.rb +75 -0
- data/lib/octocore-mongo/models/enterprise/adapter_details.rb +18 -0
- data/lib/octocore-mongo/models/enterprise/api_event.rb +14 -0
- data/lib/octocore-mongo/models/enterprise/api_hit.rb +20 -0
- data/lib/octocore-mongo/models/enterprise/api_key.rb +11 -0
- data/lib/octocore-mongo/models/enterprise/api_track.rb +13 -0
- data/lib/octocore-mongo/models/enterprise/app_init.rb +13 -0
- data/lib/octocore-mongo/models/enterprise/app_login.rb +12 -0
- data/lib/octocore-mongo/models/enterprise/app_logout.rb +12 -0
- data/lib/octocore-mongo/models/enterprise/authorization.rb +67 -0
- data/lib/octocore-mongo/models/enterprise/category.rb +14 -0
- data/lib/octocore-mongo/models/enterprise/category_baseline.rb +19 -0
- data/lib/octocore-mongo/models/enterprise/category_hit.rb +26 -0
- data/lib/octocore-mongo/models/enterprise/category_trend.rb +19 -0
- data/lib/octocore-mongo/models/enterprise/conversions.rb +69 -0
- data/lib/octocore-mongo/models/enterprise/ctr.rb +54 -0
- data/lib/octocore-mongo/models/enterprise/dimension_choice.rb +21 -0
- data/lib/octocore-mongo/models/enterprise/engagement_time.rb +43 -0
- data/lib/octocore-mongo/models/enterprise/funnel_data.rb +20 -0
- data/lib/octocore-mongo/models/enterprise/funnel_tracker.rb +19 -0
- data/lib/octocore-mongo/models/enterprise/funnels.rb +129 -0
- data/lib/octocore-mongo/models/enterprise/gcm.rb +21 -0
- data/lib/octocore-mongo/models/enterprise/newsfeed_hit.rb +52 -0
- data/lib/octocore-mongo/models/enterprise/notification_hit.rb +42 -0
- data/lib/octocore-mongo/models/enterprise/page.rb +15 -0
- data/lib/octocore-mongo/models/enterprise/page_view.rb +14 -0
- data/lib/octocore-mongo/models/enterprise/pageload_time.rb +43 -0
- data/lib/octocore-mongo/models/enterprise/product.rb +22 -0
- data/lib/octocore-mongo/models/enterprise/product_baseline.rb +20 -0
- data/lib/octocore-mongo/models/enterprise/product_hit.rb +26 -0
- data/lib/octocore-mongo/models/enterprise/product_page_view.rb +13 -0
- data/lib/octocore-mongo/models/enterprise/product_trend.rb +18 -0
- data/lib/octocore-mongo/models/enterprise/push_key.rb +15 -0
- data/lib/octocore-mongo/models/enterprise/rules.rb +45 -0
- data/lib/octocore-mongo/models/enterprise/segment.rb +65 -0
- data/lib/octocore-mongo/models/enterprise/segment_data.rb +22 -0
- data/lib/octocore-mongo/models/enterprise/tag.rb +14 -0
- data/lib/octocore-mongo/models/enterprise/tag_baseline.rb +19 -0
- data/lib/octocore-mongo/models/enterprise/tag_hit.rb +26 -0
- data/lib/octocore-mongo/models/enterprise/tag_trend.rb +19 -0
- data/lib/octocore-mongo/models/enterprise/template.rb +18 -0
- data/lib/octocore-mongo/models/plans.rb +17 -0
- data/lib/octocore-mongo/models/subscribe.rb +13 -0
- data/lib/octocore-mongo/models/user.rb +13 -0
- data/lib/octocore-mongo/models/user/push_token.rb +15 -0
- data/lib/octocore-mongo/models/user/user_browser_details.rb +16 -0
- data/lib/octocore-mongo/models/user/user_location_history.rb +15 -0
- data/lib/octocore-mongo/models/user/user_persona.rb +101 -0
- data/lib/octocore-mongo/models/user/user_phone_details.rb +17 -0
- data/lib/octocore-mongo/models/user/user_profile.rb +20 -0
- data/lib/octocore-mongo/models/user/user_timeline.rb +111 -0
- data/lib/octocore-mongo/record.rb +20 -0
- data/lib/octocore-mongo/schedeuleable.rb +20 -0
- data/lib/octocore-mongo/scheduler.rb +72 -0
- data/lib/octocore-mongo/search.rb +5 -0
- data/lib/octocore-mongo/search/client.rb +33 -0
- data/lib/octocore-mongo/search/indexer.rb +0 -0
- data/lib/octocore-mongo/search/searchable.rb +18 -0
- data/lib/octocore-mongo/search/setup.rb +71 -0
- data/lib/octocore-mongo/segment.rb +287 -0
- data/lib/octocore-mongo/stats.rb +33 -0
- data/lib/octocore-mongo/trendable.rb +88 -0
- data/lib/octocore-mongo/trends.rb +158 -0
- data/lib/octocore-mongo/utils.rb +90 -0
- data/lib/octocore-mongo/version.rb +4 -0
- data/octocore-mongo.gemspec +50 -0
- data/spec/lib/stats_spec.rb +20 -0
- data/spec/spec_helper.rb +103 -0
- metadata +545 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'mongo_mapper'
|
2
|
+
require 'octocore-mongo/record'
|
3
|
+
|
4
|
+
module Octo
|
5
|
+
class Rules
|
6
|
+
include MongoMapper::Document
|
7
|
+
include Octo::Record
|
8
|
+
|
9
|
+
# Types of conversions
|
10
|
+
DAILY = 0
|
11
|
+
WEEKLY = 1
|
12
|
+
WEEKENDS = 2
|
13
|
+
ALTERNATE = 3
|
14
|
+
|
15
|
+
belongs_to :enterprise, class_name: 'Octo::Enterprise'
|
16
|
+
|
17
|
+
key :name_slug, String # Name slug as rule
|
18
|
+
key :active, Boolean # Active or Not
|
19
|
+
|
20
|
+
key :name, String # Name of the rule
|
21
|
+
key :segment, String # slug name of segment
|
22
|
+
key :template_cat, String
|
23
|
+
key :duration, Integer # Daily, weekly, weekends ,alternate days
|
24
|
+
key :start_time, Time
|
25
|
+
key :end_time, Time
|
26
|
+
|
27
|
+
timestamps!
|
28
|
+
|
29
|
+
class << self
|
30
|
+
|
31
|
+
# Fetches the types of durations
|
32
|
+
# @return [Hash] The name and its duration value
|
33
|
+
def duration_types
|
34
|
+
{
|
35
|
+
Octo::Rules::DAILY => 'Daily',
|
36
|
+
Octo::Rules::WEEKLY => 'Weekly',
|
37
|
+
Octo::Rules::WEEKENDS => 'Weekends',
|
38
|
+
Octo::Rules::ALTERNATE => 'Alternate Days'
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'mongo_mapper'
|
2
|
+
require 'octocore-mongo/record'
|
3
|
+
require 'set'
|
4
|
+
|
5
|
+
module Octo
|
6
|
+
|
7
|
+
# The segment class. Responsible for segments
|
8
|
+
class Segment
|
9
|
+
include MongoMapper::Document
|
10
|
+
include Octo::Record
|
11
|
+
|
12
|
+
belongs_to :enterprise, class_name: 'Octo::Enterprise'
|
13
|
+
|
14
|
+
key :name_slug, String # Name slug as key
|
15
|
+
key :active, Boolean # Active or Not
|
16
|
+
|
17
|
+
key :intelligence, Boolean # If it is Octo's intelligent segment or manual
|
18
|
+
|
19
|
+
key :name, String # Name of the segment
|
20
|
+
key :type, Integer # Type of segment
|
21
|
+
key :event_type, String # Event Type used for events segmentation
|
22
|
+
|
23
|
+
key :dimensions, Array # list storing dimensions used
|
24
|
+
key :operators, Array # list storing operators on dimensions
|
25
|
+
key :dim_operators, Array # list storing operators between dimensions
|
26
|
+
key :values, Array # list of values for operations on dimensions
|
27
|
+
|
28
|
+
timestamps! # The usual housekeeping thing
|
29
|
+
|
30
|
+
before_create :create_name_slug, :activate
|
31
|
+
|
32
|
+
# Creates name slug
|
33
|
+
def create_name_slug
|
34
|
+
self.name_slug = self.name.to_slug
|
35
|
+
end
|
36
|
+
|
37
|
+
def activate
|
38
|
+
self.active = true
|
39
|
+
end
|
40
|
+
|
41
|
+
def data(ts = Time.now.floor)
|
42
|
+
args = {
|
43
|
+
enterprise_id: self.enterprise._id,
|
44
|
+
segment_slug: self.name_slug,
|
45
|
+
ts: ts
|
46
|
+
}
|
47
|
+
res = Octo::SegmentData.where(args)
|
48
|
+
if res.count > 0
|
49
|
+
res.first
|
50
|
+
elsif self.enterprise.fakedata?
|
51
|
+
# populate a poser data
|
52
|
+
val = [rand(1000..10000), rand(0.0..70.0)]
|
53
|
+
args.merge!({ value: val })
|
54
|
+
Octo::SegmentData.new(args).save!
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.find_by_enterprise_and_name(enterprise, name)
|
59
|
+
where({enterprise_id: enterprise._id, name_slug: name.to_slug})
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'mongo_mapper'
|
2
|
+
require 'octocore-mongo/record'
|
3
|
+
require 'set'
|
4
|
+
|
5
|
+
module Octo
|
6
|
+
|
7
|
+
# The SegmentData class. This class holds data for the segments
|
8
|
+
class SegmentData
|
9
|
+
|
10
|
+
include MongoMapper::Document
|
11
|
+
include Octo::Record
|
12
|
+
|
13
|
+
belongs_to :enterprise, class_name: 'Octo::Enterprise'
|
14
|
+
|
15
|
+
key :segment_slug, String # Using key as segment name's slug
|
16
|
+
|
17
|
+
key :ts, Time # The timestamp at which data is collected
|
18
|
+
key :value, Array # List of values containing data collected
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'mongo_mapper'
|
2
|
+
require 'octocore-mongo/record'
|
3
|
+
|
4
|
+
module Octo
|
5
|
+
class Tag
|
6
|
+
include MongoMapper::Document
|
7
|
+
include Octo::Record
|
8
|
+
|
9
|
+
belongs_to :enterprise, class_name: 'Octo::Enterprise'
|
10
|
+
|
11
|
+
key :tag_text, String
|
12
|
+
timestamps!
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'mongo_mapper'
|
2
|
+
|
3
|
+
require 'octocore-mongo/baseline'
|
4
|
+
require 'octocore-mongo/schedeuleable'
|
5
|
+
|
6
|
+
module Octo
|
7
|
+
class TagBaseline
|
8
|
+
include MongoMapper::Document
|
9
|
+
extend Octo::Baseline
|
10
|
+
extend Octo::Scheduleable
|
11
|
+
|
12
|
+
belongs_to :enterprise, class_name: 'Octo::Enterprise'
|
13
|
+
|
14
|
+
baselineable
|
15
|
+
|
16
|
+
# Specify the type of counter
|
17
|
+
baseline_for 'Octo::TagHit'
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'mongo_mapper'
|
2
|
+
|
3
|
+
require 'octocore-mongo/counter'
|
4
|
+
require 'octocore-mongo/trendable'
|
5
|
+
require 'octocore-mongo/schedeuleable'
|
6
|
+
|
7
|
+
module Octo
|
8
|
+
|
9
|
+
class TagHit
|
10
|
+
include MongoMapper::Document
|
11
|
+
extend Octo::Counter
|
12
|
+
extend Octo::Trendable
|
13
|
+
extend Octo::Scheduleable
|
14
|
+
|
15
|
+
COUNTERS = 20
|
16
|
+
|
17
|
+
belongs_to :enterprise, class_name: 'Octo::Enterprise'
|
18
|
+
|
19
|
+
countables
|
20
|
+
trendables
|
21
|
+
|
22
|
+
baseline 'Octo::TagBaseline'
|
23
|
+
trends_class 'Octo::TagTrend'
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'mongo_mapper'
|
2
|
+
require 'octocore-mongo/trends'
|
3
|
+
|
4
|
+
module Octo
|
5
|
+
|
6
|
+
# Class for storing trending tag
|
7
|
+
class TagTrend
|
8
|
+
include MongoMapper::Document
|
9
|
+
extend Octo::Trends
|
10
|
+
|
11
|
+
belongs_to :enterprise, class_name: 'Octo::Enterprise'
|
12
|
+
|
13
|
+
trendable
|
14
|
+
|
15
|
+
trend_for 'Octo::TagHit'
|
16
|
+
trend_class 'Octo::Tag'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'mongo_mapper'
|
2
|
+
|
3
|
+
module Octo
|
4
|
+
class Template
|
5
|
+
include MongoMapper::Document
|
6
|
+
|
7
|
+
belongs_to :enterprise, class_name: 'Octo::Enterprise'
|
8
|
+
|
9
|
+
key :category_type, String
|
10
|
+
|
11
|
+
key :template_text, String
|
12
|
+
key :active, Boolean
|
13
|
+
|
14
|
+
timestamps!
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'mongo_mapper'
|
2
|
+
|
3
|
+
module Octo
|
4
|
+
class UserBrowserDetails
|
5
|
+
include MongoMapper::Document
|
6
|
+
|
7
|
+
belongs_to :user, class_name: 'Octo::User'
|
8
|
+
|
9
|
+
key :cookieid, String
|
10
|
+
key :name, String
|
11
|
+
key :platform, String
|
12
|
+
key :manufacturer, String
|
13
|
+
|
14
|
+
timestamps!
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'mongo_mapper'
|
2
|
+
|
3
|
+
module Octo
|
4
|
+
|
5
|
+
class UserPersona
|
6
|
+
|
7
|
+
include MongoMapper::Document
|
8
|
+
|
9
|
+
HIGH_ENGAGED = 0
|
10
|
+
MEDIUM_ENGAGED = 1
|
11
|
+
LOW_ENGAGED = 2
|
12
|
+
DEAD = 3
|
13
|
+
|
14
|
+
belongs_to :user, class_name: 'Octo::User'
|
15
|
+
key :ts, Time
|
16
|
+
|
17
|
+
key :categories, Hash
|
18
|
+
key :tags, Hash
|
19
|
+
key :trending, Hash
|
20
|
+
key :engagement, Float
|
21
|
+
|
22
|
+
def engaged_text
|
23
|
+
_engaged_text self.engagement
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.engaged_text(val)
|
27
|
+
_engaged_text val
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.fakedata(user, ts)
|
31
|
+
args = {
|
32
|
+
user_enterprise_id: user.enterprise._id,
|
33
|
+
user_id: user._id,
|
34
|
+
ts: ts
|
35
|
+
}
|
36
|
+
res = self.where(args)
|
37
|
+
if res.count < 1
|
38
|
+
categories = Hash[Octo::Category.first(rand(1..Octo::Category.count)).collect do |x|
|
39
|
+
[x.cat_text, rand(20..200)]
|
40
|
+
end]
|
41
|
+
tags = Hash[Octo::Tag.first(rand(1..Octo::Tag.count)).collect do |x|
|
42
|
+
[x.tag_text, rand(20.200)]
|
43
|
+
end]
|
44
|
+
trending = ['trending', 'non trending'].collect do |x|
|
45
|
+
[x, rand(10..50)]
|
46
|
+
end
|
47
|
+
args = {
|
48
|
+
user: user,
|
49
|
+
categories: categories,
|
50
|
+
tags: tags,
|
51
|
+
trending: trending,
|
52
|
+
engagement: rand(0..3)
|
53
|
+
}
|
54
|
+
res = []
|
55
|
+
if ts.class == Range
|
56
|
+
start_ts = ts.begin.beginning_of_day
|
57
|
+
end_ts = ts.end.end_of_day
|
58
|
+
start_ts.to(end_ts, 1.day).each do |_ts|
|
59
|
+
_args = args.merge({ ts: _ts})
|
60
|
+
res << self.new(_args).save!
|
61
|
+
end
|
62
|
+
elsif ts.class == Time
|
63
|
+
_args = args.merge({ts: ts})
|
64
|
+
res << self.new(_args).save!
|
65
|
+
end
|
66
|
+
end
|
67
|
+
self.aggregate res
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.aggregate(res)
|
71
|
+
personas = [:categories, :tags, :trending]
|
72
|
+
personas.inject({}) do |result, p|
|
73
|
+
result[p] = res.collect do |r|
|
74
|
+
r.send(p)
|
75
|
+
end.inject({}) do |sum, values|
|
76
|
+
values.each do |k,v|
|
77
|
+
sum[k] = sum.fetch(k, 0) + v
|
78
|
+
sum
|
79
|
+
end
|
80
|
+
end
|
81
|
+
result
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def _engaged_text(val)
|
88
|
+
case val
|
89
|
+
when HIGH_ENGAGED
|
90
|
+
'Highly Engaged'
|
91
|
+
when MEDIUM_ENGAGED
|
92
|
+
'Moderately Engaged'
|
93
|
+
when LOW_ENGAGED
|
94
|
+
'Low Engagement'
|
95
|
+
when DEAD
|
96
|
+
'Slipping Out'
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|