bit_analytics 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bit_analytics.rb +35 -34
- data/lib/bit_analytics/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5fce88feba09c13d6a91ed272942b54b2e800eed
|
4
|
+
data.tar.gz: cddf8c287cce5180edd39e353da711fdde010cf9
|
5
5
|
!binary "U0hBNTEy":
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba179695e5699412b98a4c9261a8d2d910accbc7c3466e980f1a0927d5dd5ae4318952670c9d3aa640bd62a1131a110bf908e58c71159f68ce7b6816342cee93
|
7
|
+
data.tar.gz: f79c8be49beb2ebf38df68a2d76a6dfe246fc8548d2208ae69321b0b6ed4437a804625d5a6b5f16ff58dc7116c4ef877771a0de16ab813c3b6b81f8509a0e103
|
data/lib/bit_analytics.rb
CHANGED
@@ -12,17 +12,18 @@ class BitAnalytics
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
#--- Events marking and deleting ---
|
16
15
|
# Marks an event for hours, days, weeks and months.
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
16
|
+
#
|
17
|
+
# * +event_name+ - The name of the event, could be "active" or "new_signups"
|
18
|
+
# * +uuid+ - An unique id, typically user id. The id should not be huge, read Redis documentation why (bitmaps)
|
19
|
+
# * +now+ - Which date should be used as a reference point, default is `Time.now.getutc`
|
20
|
+
# * +track_hourly+ - Should hourly stats be tracked
|
21
|
+
#
|
22
|
+
# ==== Example
|
22
23
|
# Mark id 1 as active
|
23
|
-
# mark_event('active', 1)
|
24
|
+
# @bit_analytics.mark_event('active', 1)
|
24
25
|
# Mark task completed for id 252
|
25
|
-
# mark_event('tasks:completed', 252)
|
26
|
+
# @bit_analytics.mark_event('tasks:completed', 252)
|
26
27
|
def mark_event(event_name, uuid, now: nil, track_hourly: nil)
|
27
28
|
# Has memory applications
|
28
29
|
track_hourly ||= false
|
@@ -116,11 +117,11 @@ class BitAnalytics
|
|
116
117
|
|
117
118
|
#--- Events ---
|
118
119
|
|
119
|
-
# Extends with an obj.has_events_marked
|
120
|
-
# that returns
|
121
|
-
# otherwise
|
120
|
+
# Extends with an obj.has_events_marked
|
121
|
+
# that returns truw if there are any events marked,
|
122
|
+
# otherwise false is returned.
|
122
123
|
|
123
|
-
#
|
124
|
+
# Extends also with a obj.delete
|
124
125
|
# (useful for deleting temporary calculations).
|
125
126
|
|
126
127
|
module MixinEventsMisc
|
@@ -132,8 +133,8 @@ class BitAnalytics
|
|
132
133
|
end
|
133
134
|
end
|
134
135
|
|
135
|
-
# Extends with an obj.get_count
|
136
|
-
# count all the events. Supports also
|
136
|
+
# Extends with an obj.get_count that uses BITCOUNT to
|
137
|
+
# count all the events. Supports also length.
|
137
138
|
|
138
139
|
module MixinCounts
|
139
140
|
def get_count
|
@@ -146,8 +147,8 @@ class BitAnalytics
|
|
146
147
|
end
|
147
148
|
|
148
149
|
# Makes it possible to see if an uuid has been marked.
|
149
|
-
# Example
|
150
|
-
# user_active_today =
|
150
|
+
# ==== Example
|
151
|
+
# user_active_today = @bit_analytics.day_events('active', 2012, 10, 23).includes?(123)
|
151
152
|
module MixinContains
|
152
153
|
def includes?(uuid)
|
153
154
|
if @redis.getbit(self.redis_key, uuid) == 1
|
@@ -166,8 +167,8 @@ end
|
|
166
167
|
|
167
168
|
|
168
169
|
# Events for a month.
|
169
|
-
# Example
|
170
|
-
#
|
170
|
+
# ==== Example
|
171
|
+
# @bit_analytics.month_events('active', 2012, 10)
|
171
172
|
class MonthEvents < BitAnalytics
|
172
173
|
include RedisConnection
|
173
174
|
include MixinCounts
|
@@ -182,8 +183,8 @@ class MonthEvents < BitAnalytics
|
|
182
183
|
end
|
183
184
|
|
184
185
|
# Events for a week.
|
185
|
-
# Example
|
186
|
-
#
|
186
|
+
# ==== Example
|
187
|
+
# @bit_analytics.week_events('active', 2012, 48)
|
187
188
|
class WeekEvents < BitAnalytics
|
188
189
|
include RedisConnection
|
189
190
|
include MixinCounts
|
@@ -196,8 +197,8 @@ class WeekEvents < BitAnalytics
|
|
196
197
|
end
|
197
198
|
|
198
199
|
# Events for a day.
|
199
|
-
# Example
|
200
|
-
#
|
200
|
+
# ==== Example
|
201
|
+
# @bit_analytics.day_events('active', 2012, 10, 23)
|
201
202
|
class DayEvents < BitAnalytics
|
202
203
|
include RedisConnection
|
203
204
|
include MixinCounts
|
@@ -210,8 +211,8 @@ class DayEvents < BitAnalytics
|
|
210
211
|
end
|
211
212
|
|
212
213
|
# Events for a hour.
|
213
|
-
# Example
|
214
|
-
#
|
214
|
+
# ==== Example
|
215
|
+
# @bit_analytics.hour_events('active', 2012, 10, 23, 13)
|
215
216
|
class HourEvents < BitAnalytics
|
216
217
|
include RedisConnection
|
217
218
|
include MixinCounts
|
@@ -224,22 +225,22 @@ class HourEvents < BitAnalytics
|
|
224
225
|
end
|
225
226
|
|
226
227
|
#--- Bit operations ---
|
228
|
+
|
227
229
|
# Base class for bit operations (AND, OR, XOR).
|
228
230
|
# Please note that each bit operation creates a new key prefixed with `bitanalytics_bitop_`.
|
229
231
|
# These temporary keys can be deleted with `delete_temporary_bitop_keys`.
|
230
|
-
|
231
232
|
# You can even nest bit operations.
|
232
|
-
# Example
|
233
|
-
# active_2_months =
|
234
|
-
#
|
235
|
-
#
|
233
|
+
# ==== Example
|
234
|
+
# active_2_months = @bit_analytics.bit_op_and(
|
235
|
+
# @bit_analytics.month_events('active', last_month.year, last_month.month),
|
236
|
+
# @bit_analytics.month_events('active', now.year, now.month)
|
236
237
|
# )
|
237
|
-
# active_2_months =
|
238
|
-
#
|
239
|
-
#
|
240
|
-
#
|
238
|
+
# active_2_months = @bit_analytics.bit_op_and(
|
239
|
+
# @bit_analytics.bit_op_and(
|
240
|
+
# @bit_analytics.month_events('active', last_month.year, last_month.month),
|
241
|
+
# @bit_analytics.month_events('active', now.year, now.month)
|
241
242
|
# ),
|
242
|
-
#
|
243
|
+
# @bit_analytics.month_events('active', now.year, now.month)
|
243
244
|
# )
|
244
245
|
class BitOperation < BitAnalytics
|
245
246
|
include MixinContains
|