Class: MixpanelTest::Analysis
- Inherits:
-
Object
- Object
- MixpanelTest::Analysis
- Defined in:
- lib/mixpanel_test/analysis.rb
Instance Method Summary collapse
- #add_documentation_object(obj) ⇒ Object
- #add_event(ev) ⇒ Object
- #add_events(arr) ⇒ Object
- #documentation_object ⇒ Object
- #format_documentation ⇒ Object
- #format_verbose ⇒ Object
-
#initialize(options = {}) ⇒ Analysis
constructor
A new instance of Analysis.
- #initialize_for_event(ev) ⇒ Object
- #initialize_for_event_property_list(name, props) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Analysis
Returns a new instance of Analysis.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/mixpanel_test/analysis.rb', line 5 def initialize( = {}) @events_count = {} @events_properties_counts = {} @events_properties_values_counts = {} @properties_counts = {} @properties_values_counts = {} @super_properties_counts = {} @super_properties_values_counts = {} end |
Instance Method Details
#add_documentation_object(obj) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/mixpanel_test/analysis.rb', line 52 def add_documentation_object(obj) # Each event and property counts for an undefined number > 0. # Discard notes # Only useful for merging two documentation objects obj["events"].each do |name, props| initialize_for_event_property_list(name, props) @events_count[name] += 1 props.each do |p_name| @events_properties_counts[name][p_name] += 1 @properies_count[p_name] += 1 end end obj["properties"].each do |p| @properties_count[p["name"]] ||= 0 @properties_count[p["name"]] += 1 p["values"].each do |v| @properties_values_count[p["name"]][v] ||= 0 @properties_values_count[p["name"]][v] += 1 end end end |
#add_event(ev) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/mixpanel_test/analysis.rb', line 84 def add_event(ev) initialize_for_event(ev) name = ev["event"] ev["properties"].each do |k, v| # Increment property counters @properties_counts[k] += 1 @events_properties_counts[name][k] += 1 @events_properties_values_counts[name][k][v] += 1 @properties_values_counts[k][v] += 1 end end |
#add_events(arr) ⇒ Object
80 81 82 |
# File 'lib/mixpanel_test/analysis.rb', line 80 def add_events(arr) arr.each do |ev| add_event(ev) end end |
#documentation_object ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/mixpanel_test/analysis.rb', line 126 def documentation_object default_notes = "Undocumented" { "events" => @events_count.keys.map do |k| { k => { "notes" => default_notes, "properties" => @events_properties_counts[k].keys } } end, "properties" => @properties_counts.keys.map do |k| { "name" => k, "notes" => default_notes, "values" => @properties_values_counts[k].keys } end } end |
#format_documentation ⇒ Object
120 121 122 123 124 |
# File 'lib/mixpanel_test/analysis.rb', line 120 def format_documentation pp documentation_object end |
#format_verbose ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/mixpanel_test/analysis.rb', line 101 def format_verbose puts "Mixpanel events caught:" pp @events_count puts "Mixpanel properties caught for each event:" pp @events_properties_counts puts "All Mixpanel properties caught:" pp @properties_counts puts "Mixpanel values frequency by property:" pp @properties_values_counts puts "Mixpanel values frequency by property and event:" pp @events_properties_values_counts end |
#initialize_for_event(ev) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mixpanel_test/analysis.rb', line 17 def initialize_for_event(ev) name = ev["event"] initialize_for_event_property_list(name, ev["properties"].keys) ev["properties"].each do |k, v| # Initialize property counters @events_properties_values_counts[name][k][v] ||= 0 @properties_values_counts[k][v] ||= 0 end end |
#initialize_for_event_property_list(name, props) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/mixpanel_test/analysis.rb', line 33 def initialize_for_event_property_list(name, props) # Initialize counters @events_count[name] ||= 0 @events_properties_counts[name] ||= {} @events_properties_values_counts[name] ||= {} props.each do |k| # Initialize property counters @events_properties_counts[name][k] ||= 0 @events_properties_values_counts[name][k] ||= {} @properties_counts[k] ||= 0 @properties_values_counts[k] ||= {} end end |