lib/split/experiment.rb in split-0.6.5 vs lib/split/experiment.rb in split-0.6.6
- old
+ new
@@ -39,10 +39,15 @@
def self.all
Split.redis.smembers(:experiments).map {|e| find(e)}
end
+ # Return experiments without a winner (considered "active") first
+ def self.all_active_first
+ all.sort_by{|e| e.winner ? 1 : 0} # sort_by hack since true/false isn't sortable
+ end
+
def self.find(name)
if Split.redis.exists(name)
obj = self.new name
obj.load_from_redis
else
@@ -63,11 +68,11 @@
def save
validate!
if new_record?
Split.redis.sadd(:experiments, name)
- Split.redis.hset(:experiment_start_times, @name, Time.now.to_i)
+ start unless Split.configuration.start_manually
@alternatives.reverse.each {|a| Split.redis.lpush(name, a.name)}
@goals.reverse.each {|a| Split.redis.lpush(goals_key, a)} unless @goals.nil?
else
existing_alternatives = load_alternatives_from_redis
@@ -151,9 +156,13 @@
alternatives.first
end
def reset_winner
Split.redis.hdel(:experiment_winner, name)
+ end
+
+ def start
+ Split.redis.hset(:experiment_start_times, @name, Time.now.to_i)
end
def start_time
t = Split.redis.hget(:experiment_start_times, @name)
if t