Sha256: e8e6a1da67c45cfc85f4c12a5d942edc4987326b6064d513dd4e6fba15e8c68d

Contents?: true

Size: 933 Bytes

Versions: 2

Compression:

Stored size: 933 Bytes

Contents

require 'split'
require 'csv'
require 'bigdecimal'

module Split
  module Export
    extend self

    def round(number, precision = 2)
      BigDecimal.new(number.to_s).round(precision).to_f
    end

    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
split-export-1.1.0 lib/split/export.rb
split-export-1.0.0 lib/split/export.rb