cohort_me 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -57,6 +57,7 @@ Options you can pass to CohortMe.analyze:
57
57
  * `:activation_conditions` - If you need anything fancy to find activated users. For example, if your acivation_class is Document (meaning find activated Users who have created their first Document) you could pass in: `:activation_conditions => ["(content IS NOT NULL && content != '')]`, which means: Find activated Users who have create their first Document that has non-empty content.
58
58
  * `:activity_class` - Default is the same class used as the activation_class. However, is there a different Class representing an Event the user creates in your database when they revisit your application? Do you expect users to create a new Message each week? Or a new Friend?
59
59
  * `:activity_user_id` - Defaults to "user_id".
60
+ * `:start_from_interval` - Number of periods [days | weeks | months] before today to show the cohort analysis for. Defaults to 12.
60
61
 
61
62
 
62
63
  Examples
@@ -76,6 +77,15 @@ For my group messaging tool, my cohort analysis might look like this:
76
77
  activity_class: Message)
77
78
  ```
78
79
 
80
+ If I wanted to see this for the past 24 months, the code would look like this:
81
+
82
+ ```ruby
83
+ @cohorts = CohortMe.analyze(period: "months",
84
+ activation_class: Group,
85
+ activity_class: Message,
86
+ start_from_interval: 24)
87
+ ```
88
+
79
89
  CohortMe will look at Groups to find activated users: people who created their first Group. Next, CohortMe will look to the Message model to find out when those users have returned to my app to create that Message activity.
80
90
 
81
91
  This assumes a Group belongs to a user through an attribute called "user_id". But if the attribute is "owner_id" on a Group, that's fine, you can do:
data/lib/cohort_me.rb CHANGED
@@ -4,6 +4,7 @@ module CohortMe
4
4
 
5
5
  def self.analyze(options={})
6
6
 
7
+ start_from_interval = options[:start_from_interval] || 12
7
8
  interval_name = options[:period] || "weeks"
8
9
  activation_class = options[:activation_class]
9
10
  activation_table_name = ActiveModel::Naming.plural(activation_class)
@@ -19,13 +20,13 @@ module CohortMe
19
20
  cohort_label = nil
20
21
 
21
22
  if interval_name == "weeks"
22
- start_from = 12.weeks.ago
23
+ start_from = start_from_interval.weeks.ago
23
24
  time_conversion = 604800
24
25
  elsif interval_name == "days"
25
- start_from = 12.days.ago
26
+ start_from = start_from_interval.days.ago
26
27
  time_conversion = 86400
27
28
  elsif interval_name == "months"
28
- start_from = 12.months.ago
29
+ start_from = start_from_interval.months.ago
29
30
  time_conversion = 1.month.seconds
30
31
  end
31
32
 
@@ -81,4 +82,4 @@ module CohortMe
81
82
  end
82
83
 
83
84
 
84
- end
85
+ end
@@ -27,7 +27,7 @@
27
27
  <% (@cohorts.size).times do |i| %>
28
28
  <td>
29
29
  <% if @cohorts.size - index > (i + 1) %>
30
- <%= "#{((row[1][i].to_f/start.to_f) * 100.00).round(0)}%" %>
30
+ <%= "#{((row[1][:count][i].to_f/start.to_f) * 100.00).round(0)}%" %>
31
31
  <% else %>
32
32
  --
33
33
  <% end %>
@@ -38,4 +38,4 @@
38
38
  <% end %>
39
39
 
40
40
 
41
- </table>
41
+ </table>
@@ -1,3 +1,3 @@
1
1
  module CohortMe
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cohort_me
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-19 00:00:00.000000000 Z
12
+ date: 2013-02-20 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Cohort analysis for a Rails app
15
15
  email: