Sha256: 5c01410af9543f407dff4bccc99edc916641e815f11c0884ca1d47abda031235

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 KB

Contents

module Conductor
  class RollUp
    def self.process
      Conductor::Experiment::Raw.since(14.days.ago).group_by(&:created_date).each do |day, daily_rows|

        # remove all the existing data for that day
        Conductor::Experiment::Daily.delete_all(:activity_date => day)

        daily_rows.group_by(&:group_name).each do |group_name, group_rows|
          group_rows.group_by(&:alternative).each do |alternative_name, alternatives|
            conversion_value = alternatives.select {|x| !x.conversion_value.nil?}.inject(0) {|res, x| res += x.conversion_value}
            views = alternatives.count
            conversions = alternatives.count {|x| !x.conversion_value.nil?}
            Conductor::Experiment::Daily.create!(:activity_date => day,
                                                 :group_name => group_name,
                                                 :alternative => alternative_name,
                                                 :conversion_value => conversion_value,
                                                 :views => views,
                                                 :conversions => conversions )
          end
          
          # delete the cache for this group so it can be recreated with the new values
          Conductor.cache.delete("Conductor::Experiment::#{group_name}::Alternatives")
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
conductor-0.9.4 lib/conductor/roll_up.rb
conductor-0.9.3 lib/conductor/roll_up.rb