Sha256: ec82e5c678d8880d4060bb4d59065dbd6bbfa5a7a1cf1e4d9330cebae79cb017

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

class 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::#{Conductor.attribute_for_weighting}::#{group_name}::Alternatives")
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
conductor-0.8.3 lib/conductor/roll_up.rb