Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring: Extract ExperimentStore #225

Merged
merged 1 commit into from Dec 5, 2013
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Refactoring: Extract ExperimientStore

Extracts the responsibility of finding experiments to another class
  • Loading branch information...
nberger committed Dec 5, 2013
commit 5cff275f9e9b74e788610092a748bc5d499a74e6
@@ -3,6 +3,7 @@
configuration
exceptions
experiment
experiment_catalog
extensions
helper
metric
@@ -38,31 +38,20 @@ def initialize(name, options = {})
end

def self.all
Split.redis.smembers(:experiments).map {|e| find(e)}
ExperimentCatalog.all
end

# Return experiments without a winner (considered "active") first
def self.all_active_first
all.partition{|e| not e.winner}.map{|es| es.sort_by(&:name)}.flatten
ExperimentCatalog.all_active_first
end

def self.find(name)
if Split.redis.exists(name)
obj = self.new name
obj.load_from_redis
else
obj = nil
end
obj
ExperimentCatalog.find(name)
end

def self.find_or_create(label, *alternatives)
experiment_name_with_version, goals = normalize_experiment(label)
name = experiment_name_with_version.to_s.split(':')[0]

exp = self.new name, :alternatives => alternatives, :goals => goals
exp.save
exp
ExperimentCatalog.find_or_create(label, *alternatives)
end

def save
@@ -247,17 +236,6 @@ def load_from_redis

protected

def self.normalize_experiment(label)
if Hash === label
experiment_name = label.keys.first
goals = label.values.first
else
experiment_name = label
goals = []
end
return experiment_name, goals
end

def experiment_config_key
"experiment_configurations/#{@name}"
end
@@ -0,0 +1,45 @@
module Split
class ExperimentCatalog
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.partition{|e| not e.winner}.map{|es| es.sort_by(&:name)}.flatten
end

def self.find(name)
if Split.redis.exists(name)
obj = Experiment.new name
obj.load_from_redis
else
obj = nil
end
obj
end

def self.find_or_create(label, *alternatives)
experiment_name_with_version, goals = normalize_experiment(label)
name = experiment_name_with_version.to_s.split(':')[0]

exp = Experiment.new name, :alternatives => alternatives, :goals => goals
exp.save
exp
end

private

def self.normalize_experiment(label)
if Hash === label
experiment_name = label.keys.first
goals = label.values.first
else
experiment_name = label
goals = []
end
return experiment_name, goals
end

end
end
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.