Sha256: 887bb2d9e4b7174b1125697a1ecc1bb8341361c6859ecf8a73da73380c8109e1

Contents?: true

Size: 1.67 KB

Versions: 1

Compression:

Stored size: 1.67 KB

Contents

require 'conductor/experiment'
require 'conductor/roll_up'
require 'conductor/weights'
require 'conductor/experiment/raw'
require 'conductor/experiment/daily'
require 'conductor/experiment/weight'
require 'conductor/experiment/history'
require 'conductor/controller/dashboard'
require 'conductor/helpers/dashboard_helper'


class Conductor
  MAX_WEIGHTING_FACTOR = 1.25
  MINIMUM_LAUNCH_DAYS = 7
  DBG = false

  cattr_writer :cache
  cattr_writer :days_till_weighting
  
  def self.cache
    @@cache || Rails.cache
  end

  class << self
    def identity=(value)
      @conductor_identity = value
    end

    def identity
      return (@conductor_identity || ActiveSupport::SecureRandom.hex(16))
    end
    
    def minimum_launch_days
      return (@@days_till_weighting || MINIMUM_LAUNCH_DAYS)
    end
    
    def attribute_for_weighting=(value)
      raise "Conductor.attribute_for_weighting must be either :views, :conversions or :conversion_value (default)" unless [:views, :conversions, :conversion_value].include?(value) 
      @attribute_for_weighting = value
    end
    
    def attribute_for_weighting
      return (@attribute_for_weighting || :conversion_value)
    end

    def log(msg)
      puts msg if DBG
    end

    def sanitize(str)
      str.gsub(/\s/,'_').downcase
    end
  end

end


class Array
  def sum_it(attribute)
    self.map {|x| x.send(attribute) }.compact.sum
  end

  def weighted_mean_of_attribute(attribute)
    self.map {|x| x.send(attribute) }.compact.weighted_mean
  end

  def weighted_mean
    w_sum = sum(self)
    return 0.00 if w_sum == 0.00
    
    w_prod = 0
    self.each_index {|i| w_prod += (i+1) * self[i].to_f}
    w_prod.to_f / w_sum.to_f
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
conductor-0.7.0 lib/conductor.rb