Skip to content

Commit

Permalink
disable cohorting revision
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-phung committed May 27, 2020
1 parent f9fc878 commit 0dcc853
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
25 changes: 13 additions & 12 deletions lib/split/dashboard/views/_controls.erb
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<% if experiment.cohorting_disabled? %>
<form action="<%= url "/update_cohorting?experiment=#{experiment.name}" %>" method='post' onclick="return confirmEnableCohorting()">
<input type="hidden" name="cohorting_action" value="enable">
<input type="submit" value="Enable Cohorting" class="green">
</form>
<% else %>
<form action="<%= url "/update_cohorting?experiment=#{experiment.name}" %>" method='post' onclick="return confirmDisableCohorting()">
<input type="hidden" name="cohorting_action" value="disable">
<input type="submit" value="Disable Cohorting" class="red">
</form>
<% end %>
<span class="divider">|</span>
<% if experiment.has_winner? %>
<form action="<%= url "/reopen?experiment=#{experiment.name}" %>" method='post' onclick="return confirmReopen()">
<input type="submit" value="Reopen Experiment">
</form>
<% else %>
<% if experiment.cohorting_disabled? %>
<form action="<%= url "/update_cohorting?experiment=#{experiment.name}" %>" method='post' onclick="return confirmEnableCohorting()">
<input type="hidden" name="cohorting_action" value="enable">
<input type="submit" value="Enable Cohorting" class="green">
</form>
<% else %>
<form action="<%= url "/update_cohorting?experiment=#{experiment.name}" %>" method='post' onclick="return confirmDisableCohorting()">
<input type="hidden" name="cohorting_action" value="disable">
<input type="submit" value="Disable Cohorting" class="red">
</form>
<% end %>
<% end %>
<span class="divider">|</span>
<% if experiment.start_time %>
<form action="<%= url "/reset?experiment=#{experiment.name}" %>" method='post' onclick="return confirmReset()">
<input type="submit" value="Reset Data">
Expand Down
15 changes: 12 additions & 3 deletions lib/split/experiment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def delete
end
reset_winner
redis.srem(:experiments, name)
redis.hdel(experiment_config_key, :cohorting)
remove_experiment_cohorting
remove_experiment_configuration
Split.configuration.on_experiment_delete.call(self)
increment_version
Expand Down Expand Up @@ -389,15 +389,19 @@ def jstring(goal = nil)
end

def cohorting_disabled?
value = redis.hget(experiment_config_key, :cohorting)
value.nil? ? false : value.downcase == "true"
@cohorting_disabled ||= begin
value = redis.hget(experiment_config_key, :cohorting)
value.nil? ? false : value.downcase == "true"
end
end

def disable_cohorting
@cohorting_disabled = true
redis.hset(experiment_config_key, :cohorting, true)
end

def enable_cohorting
@cohorting_disabled = false
redis.hset(experiment_config_key, :cohorting, false)
end

Expand Down Expand Up @@ -482,5 +486,10 @@ def experiment_configuration_has_changed?
def goals_collection
Split::GoalsCollection.new(@name, @goals)
end

def remove_experiment_cohorting
@cohorting_disabled = false
redis.hdel(experiment_config_key, :cohorting)
end
end
end
6 changes: 4 additions & 2 deletions lib/split/trial.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ def choose!(context = nil)
end
end

@user[@experiment.key] = alternative.name unless @experiment.has_winner? || !should_store_alternative? || (new_participant && @experiment.cohorting_disabled?)
new_participant_and_cohorting_disabled = new_participant && @experiment.cohorting_disabled?

@user[@experiment.key] = alternative.name unless @experiment.has_winner? || !should_store_alternative? || new_participant_and_cohorting_disabled
@alternative_choosen = true
run_callback context, Split.configuration.on_trial unless @options[:disabled] || Split.configuration.disabled? || (new_participant && @experiment.cohorting_disabled?)
run_callback context, Split.configuration.on_trial unless @options[:disabled] || Split.configuration.disabled? || new_participant_and_cohorting_disabled
alternative
end

Expand Down

0 comments on commit 0dcc853

Please sign in to comment.