Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/split/dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ class Dashboard < Sinatra::Base
redirect url('/')
end

post '/reopen/:experiment' do
@experiment = Split::Experiment.find(params[:experiment])
@experiment.reset_winner
redirect url('/')
end

delete '/:experiment' do
@experiment = Split::Experiment.find(params[:experiment])
@experiment.delete
Expand Down
7 changes: 6 additions & 1 deletion lib/split/dashboard/public/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ function confirmWinner() {
function confirmStep(step) {
var agree = confirm(step);
return agree ? true : false;
}
}

function confirmReopen() {
var agree = confirm("This will reopen the experiment. Are you sure?");
return agree ? true : false;
}
5 changes: 5 additions & 0 deletions lib/split/dashboard/views/_controls.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<% if experiment.has_winner? %>
<form action="<%= url "/reopen/#{experiment.name}" %>" method='post' onclick="return confirmReopen()">
<input type="submit" value="Reopen Experiment">
</form>
<% end %>
<% if experiment.start_time %>
<form action="<%= url "/reset/#{experiment.name}" %>" method='post' onclick="return confirmReset()">
<input type="submit" value="Reset Data">
Expand Down
2 changes: 1 addition & 1 deletion lib/split/dashboard/views/_experiment.erb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<span title='z-score: <%= round(alternative.z_score(goal), 3) %>'><%= confidence_level(alternative.z_score(goal)) %></span>
</td>
<td>
<% if experiment.winner %>
<% if experiment.has_winner? %>
<% if experiment.winner.name == alternative.name %>
Winner
<% else %>
Expand Down
4 changes: 4 additions & 0 deletions lib/split/experiment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ def winner
end
end

def has_winner?
!winner.nil?
end

def winner=(winner_name)
Split.redis.hset(:experiment_winner, name, winner_name.to_s)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/split/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def reset!(experiment)
end

def finish_experiment(experiment, options = {:reset => true})
return true unless experiment.winner.nil?
return true if experiment.has_winner?
should_reset = experiment.resettable? && options[:reset]
if ab_user[experiment.finished_key] && !should_reset
return true
Expand Down Expand Up @@ -168,7 +168,7 @@ def start_trial(trial)
if override_present?(experiment.name)
ret = override_alternative(experiment.name)
ab_user[experiment.key] = ret if Split.configuration.store_override
elsif ! experiment.winner.nil?
elsif experiment.has_winner?
ret = experiment.winner.name
else
clean_old_versions(experiment)
Expand Down
2 changes: 1 addition & 1 deletion lib/split/trial.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def initialize(attrs = {})
end

def alternative
@alternative ||= if experiment.winner
@alternative ||= if experiment.has_winner?
experiment.winner
end
end
Expand Down
47 changes: 47 additions & 0 deletions spec/dashboard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,53 @@ def link(color)
end
end

describe "index page" do
context "with winner" do
before { experiment.winner = 'red' }

it "displays `Reopen Experiment` button" do
get '/'

expect(last_response.body).to include('Reopen Experiment')
end
end

context "without winner" do
it "should not display `Reopen Experiment` button" do
get '/'

expect(last_response.body).to_not include('Reopen Experiment')
end
end
end

describe "reopen experiment" do
before { experiment.winner = 'red' }

it 'redirects' do
post "/reopen/#{experiment.name}"

expect(last_response).to be_redirect
end

it "removes winner" do
post "/reopen/#{experiment.name}"

expect(experiment).to_not have_winner
end

it "keeps existing stats" do
red_link.participant_count = 5
blue_link.participant_count = 7
experiment.winner = 'blue'

post "/reopen/#{experiment.name}"

expect(red_link.participant_count).to eq(5)
expect(blue_link.participant_count).to eq(7)
end
end

it "should reset an experiment" do
red_link.participant_count = 5
blue_link.participant_count = 7
Expand Down
16 changes: 16 additions & 0 deletions spec/experiment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,22 @@ def alternative(color)
end
end

describe 'has_winner?' do
context 'with winner' do
before { experiment.winner = 'red' }

it 'returns true' do
expect(experiment).to have_winner
end
end

context 'without winner' do
it 'returns false' do
expect(experiment).to_not have_winner
end
end
end

describe 'reset' do
before { experiment.save }
it 'should reset all alternatives' do
Expand Down