cohortly 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,12 +15,14 @@ module Cohortly
15
15
 
16
16
  def self.store!(args)
17
17
  data = args[4]
18
- if data[:controller] && !data[:controller]['cohortly']
18
+ data[:tags] = []
19
+ if data[:controller]
20
+ return if data[:controller]['cohortly']
19
21
  data[:tags] = Cohortly::TagConfig.tags_for(data[:controller], data[:action])
20
- data[:user_email] = data[:email] if data[:email]
21
- data[:tags] += data[:add_tags] if data[:add_tags]
22
- create(data)
23
22
  end
23
+ data[:user_email] = data[:email] if data[:email]
24
+ data[:tags] += data[:add_tags] if data[:add_tags]
25
+ create(data)
24
26
  end
25
27
 
26
28
  def self.cohort_chart_for_tag(tags = nil)
@@ -66,7 +66,7 @@ module Cohortly
66
66
  def percent_line(cohort_key)
67
67
  line = report_line(cohort_key)
68
68
  base = user_count_in_cohort(cohort_key)
69
- line.collect { |x| (x/base.to_f * 100).round }.unshift base
69
+ line.collect { |x| (x && base > 0.0 ) ? (x/base.to_f * 100).round : 0 }.unshift base
70
70
  end
71
71
 
72
72
  def report_totals
@@ -1,3 +1,3 @@
1
1
  module Cohortly
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -1,8 +1,5 @@
1
1
  require 'test_helper'
2
2
 
3
-
4
-
5
-
6
3
  class CohortlyTest < ActiveSupport::TestCase
7
4
 
8
5
  test "tag config" do
@@ -23,7 +20,6 @@ class CohortlyTest < ActiveSupport::TestCase
23
20
 
24
21
  test "cohortly record event" do
25
22
 
26
-
27
23
  payload = { :user_start_date => Time.now - 1.month,
28
24
  :user_id => 5,
29
25
  :user_email => "jordon@example.com",
@@ -44,7 +40,27 @@ class CohortlyTest < ActiveSupport::TestCase
44
40
  assert_equal metric.user_start_date.utc.to_s, payload[:user_start_date].utc.to_s
45
41
 
46
42
  end
43
+
44
+ test "cohortly record event without controller or action" do
47
45
 
46
+ payload = { :user_start_date => Time.now - 1.month,
47
+ :user_id => 5,
48
+ :user_email => "jordon@example.com",
49
+ :add_tags => ['login', 'over13'] }
50
+
51
+ ActiveSupport::Notifications.instrument("cohortly.event", payload)
52
+
53
+ metric = Cohortly::Metric.first
54
+ assert metric, "should create metric"
55
+ assert metric.created_at
56
+ assert metric.tags.include? 'login'
57
+ assert metric.tags.include? 'over13'
58
+ assert_equal metric.controller, nil
59
+ assert_equal metric.user_email, 'jordon@example.com'
60
+ assert_equal metric.user_start_date.utc.to_s, payload[:user_start_date].utc.to_s
61
+
62
+ end
63
+
48
64
  test "report map reduce" do
49
65
  setup_data_to_report_on
50
66
  Cohortly::Metric.cohort_chart_for_tag
@@ -53,8 +69,8 @@ class CohortlyTest < ActiveSupport::TestCase
53
69
  report = Cohortly::Report.new('cohort_report')
54
70
  assert_equal report.month_to_time('2011-08'), Time.utc(2011, 8)
55
71
  assert_equal report.time_to_month(Time.utc(2011,8)), '2011-08'
56
- assert_equal report.start_month, (Time.now - 15.months).year.to_s + '-0' + (Time.now - 14.months).month.to_s
57
- assert_equal report.month_cohorts.length, 15
72
+ assert_equal report.start_month, (Time.now - 15.months).year.to_s + '-0' + (Time.now - 15.months).month.to_s
73
+ assert_equal report.month_cohorts.length, 16
58
74
 
59
75
  # assert_equal report.report_line(report.month_cohorts[2]), []
60
76
  assert_equal report.report_totals, [[14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],
@@ -76,8 +92,8 @@ class CohortlyTest < ActiveSupport::TestCase
76
92
 
77
93
  test "counting uniq users in cohort" do
78
94
  setup_data_to_report_on
79
- Cohortly::Metric.cohort_chart_for_tag
80
- report = Cohortly::Report.new('cohort_report')
95
+ Cohortly::Metric.cohort_chart_for_tag()
96
+ report = Cohortly::Report.new(Cohortly::Metric.report_table_name())
81
97
  start_month = report.start_month
82
98
  start_month_time = report.month_to_time(report.start_month)
83
99
  next_month = report.time_to_month(start_month_time + 1.month)
@@ -198,3 +198,227 @@ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-09-27 20:59:07 -0700
198
198
  Processing by Cohortly::ReportsController#index as HTML
199
199
  Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/application (46.3ms)
200
200
  Completed 200 OK in 51ms (Views: 50.6ms)
201
+
202
+
203
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 11:45:07 -0700
204
+ Processing by Cohortly::ReportsController#index as HTML
205
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (1.1ms)
206
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (32.9ms)
207
+ Completed in 103ms
208
+
209
+
210
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 11:51:19 -0700
211
+ Processing by Cohortly::ReportsController#index as HTML
212
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (0.8ms)
213
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (23.2ms)
214
+ Completed in 29ms
215
+
216
+
217
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 11:51:41 -0700
218
+ Processing by Cohortly::ReportsController#index as HTML
219
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (0.8ms)
220
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (23.2ms)
221
+ Completed in 31ms
222
+
223
+
224
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 11:55:46 -0700
225
+ Processing by Cohortly::ReportsController#index as HTML
226
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (0.9ms)
227
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (23.2ms)
228
+ Completed in 33ms
229
+
230
+
231
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 11:56:06 -0700
232
+ Processing by Cohortly::ReportsController#index as HTML
233
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (1.2ms)
234
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (23.5ms)
235
+ Completed in 55ms
236
+
237
+
238
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 11:57:41 -0700
239
+ Processing by Cohortly::ReportsController#index as HTML
240
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (0.8ms)
241
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (23.3ms)
242
+ Completed in 44ms
243
+
244
+
245
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 11:59:23 -0700
246
+ Processing by Cohortly::ReportsController#index as HTML
247
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (1.0ms)
248
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (23.3ms)
249
+ Completed in 69ms
250
+
251
+
252
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 12:00:40 -0700
253
+ Processing by Cohortly::ReportsController#index as HTML
254
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (0.9ms)
255
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (23.5ms)
256
+ Completed in 59ms
257
+
258
+
259
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 12:01:45 -0700
260
+ Processing by Cohortly::ReportsController#index as HTML
261
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (1.0ms)
262
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (25.4ms)
263
+ Completed in 94ms
264
+
265
+
266
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 12:02:02 -0700
267
+ Processing by Cohortly::ReportsController#index as HTML
268
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (0.9ms)
269
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (43.4ms)
270
+ Completed 200 OK in 91ms (Views: 47.9ms)
271
+
272
+
273
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 12:02:48 -0700
274
+ Processing by Cohortly::ReportsController#index as HTML
275
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (0.9ms)
276
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (44.3ms)
277
+ Completed 200 OK in 129ms (Views: 48.8ms)
278
+
279
+
280
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 12:03:09 -0700
281
+ Processing by Cohortly::ReportsController#index as HTML
282
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (0.9ms)
283
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (40.3ms)
284
+ Completed 200 OK in 108ms (Views: 46.0ms)
285
+
286
+
287
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 12:04:32 -0700
288
+ Processing by Cohortly::ReportsController#index as HTML
289
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (1.0ms)
290
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (43.6ms)
291
+ Completed 200 OK in 134ms (Views: 48.5ms)
292
+
293
+
294
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 12:05:26 -0700
295
+ Processing by Cohortly::ReportsController#index as HTML
296
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (0.9ms)
297
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (41.5ms)
298
+ Completed 200 OK in 104ms (Views: 46.0ms)
299
+
300
+
301
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 12:06:33 -0700
302
+ Processing by Cohortly::ReportsController#index as HTML
303
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (0.9ms)
304
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (40.2ms)
305
+ Completed 200 OK in 125ms (Views: 46.2ms)
306
+
307
+
308
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 12:06:51 -0700
309
+ Processing by Cohortly::ReportsController#index as HTML
310
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (0.9ms)
311
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (39.0ms)
312
+ Completed 200 OK in 105ms (Views: 43.6ms)
313
+
314
+
315
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 12:08:42 -0700
316
+ Processing by Cohortly::ReportsController#index as HTML
317
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (0.8ms)
318
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (39.5ms)
319
+ Completed 200 OK in 131ms (Views: 44.1ms)
320
+
321
+
322
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 12:09:36 -0700
323
+ Processing by Cohortly::ReportsController#index as HTML
324
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (1.0ms)
325
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (42.5ms)
326
+ Completed 200 OK in 108ms (Views: 48.9ms)
327
+
328
+
329
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 12:10:00 -0700
330
+ Processing by Cohortly::ReportsController#index as HTML
331
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (1.0ms)
332
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (88.0ms)
333
+ Completed 200 OK in 180ms (Views: 94.0ms)
334
+
335
+
336
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 12:11:21 -0700
337
+ Processing by Cohortly::ReportsController#index as HTML
338
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (0.9ms)
339
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (88.5ms)
340
+ Completed 200 OK in 163ms (Views: 94.0ms)
341
+
342
+
343
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 12:12:15 -0700
344
+ Processing by Cohortly::ReportsController#index as HTML
345
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (1.3ms)
346
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (44.5ms)
347
+ Completed 200 OK in 137ms (Views: 50.5ms)
348
+
349
+
350
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 12:13:08 -0700
351
+ Processing by Cohortly::ReportsController#index as HTML
352
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (1.1ms)
353
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (87.8ms)
354
+ Completed 200 OK in 153ms (Views: 93.8ms)
355
+
356
+
357
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 12:15:44 -0700
358
+ Processing by Cohortly::ReportsController#index as HTML
359
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (1.3ms)
360
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (45.1ms)
361
+ Completed 200 OK in 125ms (Views: 49.8ms)
362
+
363
+
364
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 12:16:06 -0700
365
+ Processing by Cohortly::ReportsController#index as HTML
366
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (0.9ms)
367
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (40.2ms)
368
+ Completed 200 OK in 104ms (Views: 45.5ms)
369
+
370
+
371
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 12:16:47 -0700
372
+ Processing by Cohortly::ReportsController#index as HTML
373
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (0.9ms)
374
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (44.8ms)
375
+ Completed 200 OK in 139ms (Views: 49.4ms)
376
+
377
+
378
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 12:18:42 -0700
379
+ Processing by Cohortly::ReportsController#index as HTML
380
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (0.9ms)
381
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (42.0ms)
382
+ Completed 200 OK in 109ms (Views: 48.0ms)
383
+
384
+
385
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 12:19:59 -0700
386
+ Processing by Cohortly::ReportsController#index as HTML
387
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (0.9ms)
388
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (41.3ms)
389
+ Completed 200 OK in 130ms (Views: 47.0ms)
390
+
391
+
392
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 12:22:43 -0700
393
+ Processing by Cohortly::ReportsController#index as HTML
394
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (0.9ms)
395
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (43.4ms)
396
+ Completed 200 OK in 110ms (Views: 49.8ms)
397
+
398
+
399
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 12:29:01 -0700
400
+ Processing by Cohortly::ReportsController#index as HTML
401
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (1.0ms)
402
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (42.9ms)
403
+ Completed 200 OK in 133ms (Views: 47.7ms)
404
+
405
+
406
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 12:31:19 -0700
407
+ Processing by Cohortly::ReportsController#index as HTML
408
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (1.0ms)
409
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (42.9ms)
410
+ Completed 200 OK in 110ms (Views: 47.9ms)
411
+
412
+
413
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 12:33:50 -0700
414
+ Processing by Cohortly::ReportsController#index as HTML
415
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (0.8ms)
416
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (40.8ms)
417
+ Completed 200 OK in 48ms (Views: 46.0ms)
418
+
419
+
420
+ Started GET "/cohortly/reports" for 127.0.0.1 at 2011-10-08 12:35:42 -0700
421
+ Processing by Cohortly::ReportsController#index as HTML
422
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/metrics/_tags.html.erb (0.8ms)
423
+ Rendered /Users/bhauman/workspace/cohortly/app/views/cohortly/reports/index.html.erb within layouts/cohortly/application (40.5ms)
424
+ Completed 200 OK in 46ms (Views: 45.0ms)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: cohortly
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.4
5
+ version: 0.0.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Bruce Hauman
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-10-05 00:00:00 -07:00
13
+ date: 2011-10-08 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies: []
16
16