class Laboratory::Experiment::AnalysisSummary

Attributes

event_id[R]
experiment[R]

Public Class Methods

new(experiment, event_id) click to toggle source
# File lib/laboratory/experiment/analysis_summary.rb, line 6
def initialize(experiment, event_id)
  @experiment = experiment
  @event_id = event_id
end

Public Instance Methods

confidence_level_in_performance_delta() click to toggle source
# File lib/laboratory/experiment/analysis_summary.rb, line 27
def confidence_level_in_performance_delta
  Laboratory::Calculations::ConfidenceLevel.calculate(
    n1: participant_count_for_variant(lowest_performing_variant),
    p1: event_total_count_for_variant(lowest_performing_variant),
    n2: participant_count_for_variant(highest_performing_variant),
    p2: event_total_count_for_variant(highest_performing_variant)
  )
end
highest_performing_variant() click to toggle source
# File lib/laboratory/experiment/analysis_summary.rb, line 11
def highest_performing_variant
  sorted_variants.first
end
lowest_performing_variant() click to toggle source
# File lib/laboratory/experiment/analysis_summary.rb, line 15
def lowest_performing_variant
  sorted_variants.last
end
performance_delta_between_highest_and_lowest() click to toggle source
# File lib/laboratory/experiment/analysis_summary.rb, line 19
def performance_delta_between_highest_and_lowest
  numerator =
    (conversion_rate_for_variant(highest_performing_variant) -
      conversion_rate_for_variant(lowest_performing_variant))
  denominator = conversion_rate_for_variant(lowest_performing_variant)
  numerator.fdiv(denominator).round(2)
end

Private Instance Methods

conversion_rate_for_variant(variant) click to toggle source
# File lib/laboratory/experiment/analysis_summary.rb, line 47
def conversion_rate_for_variant(variant)
  event_total_count_for_variant(variant)
    .fdiv(participant_count_for_variant(variant))
end
event_for_variant(variant) click to toggle source
# File lib/laboratory/experiment/analysis_summary.rb, line 67
def event_for_variant(variant)
  variant.events.find do |event|
    event.id == event_id
  end
end
event_total_count_for_variant(variant) click to toggle source
# File lib/laboratory/experiment/analysis_summary.rb, line 42
def event_total_count_for_variant(variant)
  event = event_for_variant(variant)
  event.event_recordings.uniq(&:user_id).count
end
participant_count_for_variant(variant) click to toggle source
# File lib/laboratory/experiment/analysis_summary.rb, line 38
def participant_count_for_variant(variant)
  variant.participant_ids.count
end
relevant_variants() click to toggle source
# File lib/laboratory/experiment/analysis_summary.rb, line 52
def relevant_variants
  experiment.variants.select do |variant|
    variant.events.any? do |event|
      event.id == event_id
    end
  end
end
sorted_variants() click to toggle source
# File lib/laboratory/experiment/analysis_summary.rb, line 60
def sorted_variants
  relevant_variants.sort_by do |variant|
    # Order in descending order
    -1 * conversion_rate_for_variant(variant)
  end
end