lib/split/experiment.rb in split-1.4.4 vs lib/split/experiment.rb in split-1.4.5
- old
+ new
@@ -19,28 +19,28 @@
@name = name.to_s
alternatives = extract_alternatives_from_options(options)
if alternatives.empty? && (exp_config = Split.configuration.experiment_for(name))
- set_alternatives_and_options(
+ options = {
alternatives: load_alternatives_from_configuration,
goals: Split::GoalsCollection.new(@name).load_from_configuration,
metadata: load_metadata_from_configuration,
resettable: exp_config[:resettable],
algorithm: exp_config[:algorithm]
- )
+ }
else
- set_alternatives_and_options(
- alternatives: alternatives,
- goals: options[:goals],
- metadata: options[:metadata],
- resettable: options[:resettable],
- algorithm: options[:algorithm]
- )
+ options[:alternatives] = alternatives
end
+
+ set_alternatives_and_options(options)
end
+ def self.finished_key(key)
+ "#{key}:finished"
+ end
+
def set_alternatives_and_options(options)
self.alternatives = options[:alternatives]
self.goals = options[:goals]
self.resettable = options[:resettable]
self.algorithm = options[:algorithm]
@@ -65,15 +65,14 @@
options[:resettable] = exp_config[:resettable]
options[:algorithm] = exp_config[:algorithm]
end
end
- self.alternatives = alts
- self.goals = options[:goals]
- self.algorithm = options[:algorithm]
- self.resettable = options[:resettable]
+ options[:alternatives] = alts
+ set_alternatives_and_options(options)
+
# calculate probability that each alternative is the winner
@alternative_probabilities = {}
alts
end
@@ -84,11 +83,10 @@
Split.redis.sadd(:experiments, name)
start unless Split.configuration.start_manually
@alternatives.reverse.each {|a| Split.redis.lpush(name, a.name)}
goals_collection.save
save_metadata
- Split.redis.set(metadata_key, @metadata.to_json) unless @metadata.nil?
else
existing_alternatives = load_alternatives_from_redis
existing_goals = Split::GoalsCollection.new(@name).load_from_redis
existing_metadata = load_metadata_from_redis
unless existing_alternatives == @alternatives.map(&:name) && existing_goals == @goals && existing_metadata == @metadata
@@ -225,11 +223,11 @@
def goals_key
"#{name}:goals"
end
def finished_key
- "#{key}:finished"
+ self.class.finished_key(key)
end
def metadata_key
"#{name}:metadata"
end
@@ -265,14 +263,19 @@
Split.redis.del(metadata_key)
end
def load_from_redis
exp_config = Split.redis.hgetall(experiment_config_key)
- self.resettable = exp_config['resettable']
- self.algorithm = exp_config['algorithm']
- self.alternatives = load_alternatives_from_redis
- self.goals = Split::GoalsCollection.new(@name).load_from_redis
- self.metadata = load_metadata_from_redis
+
+ options = {
+ resettable: exp_config['resettable'],
+ algorithm: exp_config['algorithm'],
+ alternatives: load_alternatives_from_redis,
+ goals: Split::GoalsCollection.new(@name).load_from_redis,
+ metadata: load_metadata_from_redis
+ }
+
+ set_alternatives_and_options(options)
end
def calc_winning_alternatives
# Super simple cache so that we only recalculate winning alternatives once per day
days_since_epoch = Time.now.utc.to_i / 86400