Module: Split::Export

Extended by:
Export
Included in:
Export
Defined in:
lib/split/export.rb,
lib/split/export/version.rb

Constant Summary collapse

VERSION =
"1.1.0"

Instance Method Summary collapse

Instance Method Details

#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_csvObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/split/export.rb', line 13

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|
      experiment.alternatives.each do |alternative|
        csv << [experiment.name,
                alternative.name,
                alternative.participant_count,
                alternative.completed_count,
                round(alternative.conversion_rate, 3),
                round(alternative.z_score, 3),
                alternative.control?,
                alternative.to_s == experiment.winner.to_s]
      end
    end
  end
end