Module: Split::Export
- Extended by:
- Export
- Included in:
- Export
- Defined in:
- lib/split/export.rb,
lib/split/export/version.rb
Constant Summary collapse
- VERSION =
"2.0.0"
Instance Method Summary collapse
- #experiment_to_csv(experiment) ⇒ Object
- #round(number, precision = 2) ⇒ Object
- #to_csv ⇒ Object
-
#z_score_all_goals(alternative) ⇒ Object
this method calculates the z_score for an alternative including all goals.
Instance Method Details
#experiment_to_csv(experiment) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/split/export.rb', line 50 def experiment_to_csv(experiment) csv = CSV.generate do |csv| csv << ["Alternative", "Goal", "Participants", "Completed", "Conversion Rate", "Z Score", "Control", "Winner"] experiment = Split::ExperimentCatalog.find(experiment) break if !experiment goals = [nil] + experiment.goals # nil corresponds to conversions without any goals. experiment.alternatives.each do |alternative| goals.each do |goal| csv << [alternative.name, goal, alternative.participant_count, alternative.completed_count(goal), round(alternative.conversion_rate(goal), 3), round(alternative.z_score(goal), 3), alternative.control?, alternative.to_s == experiment.winner.to_s] end end end end |
#round(number, precision = 2) ⇒ Object
9 10 11 |
# File 'lib/split/export.rb', line 9 def round(number, precision = 2) BigDecimal.new(number.to_s).round(precision).to_f end |
#to_csv ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/split/export.rb', line 30 def to_csv csv = CSV.generate do |csv| csv << ['Experiment', 'Alternative', 'Participants', 'Completed', 'Conversion Rate', 'Z score', 'Control', 'Winner'] Split::ExperimentCatalog.all.each do |experiment| goals = experiment.goals + [nil] # nil corresponds to conversions without any goals. experiment.alternatives.each do |alternative| csv << [experiment.name, alternative.name, alternative.participant_count, goals.inject(0) { |sum, g| sum + alternative.completed_count(g) }, round(goals.inject(0) { |sum, g| sum + alternative.conversion_rate(g) }, 3), round(z_score_all_goals(alternative), 3), alternative.control?, alternative.to_s == experiment.winner.to_s] end end end end |
#z_score_all_goals(alternative) ⇒ Object
this method calculates the z_score for an alternative including all goals. This behavior should be added to Alternative#z_score but until then, this method will do. I lifted most of the code from that method.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/split/export.rb', line 15 def z_score_all_goals(alternative) goals = alternative.goals + [nil] control = alternative.experiment.control return 'N/A' if control.name == alternative.name p_a = goals.inject(0) { |sum, g| sum + alternative.conversion_rate(g) } p_c = goals.inject(0) { |sum, g| sum + control.conversion_rate(g) } n_a = alternative.participant_count n_c = control.participant_count z_score = Split::Zscore.calculate(p_a, n_a, p_c, n_c) end |