Skip to content

Commit 9e96b47

Browse files
author
Andrew Nesbitt
committed
Merge pull request splitrb#241 from swrobel/metrics-on-dashboard
Metrics on dashboard
2 parents 2bfbaf5 + 3682bc9 commit 9e96b47

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

lib/split/dashboard.rb

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class Dashboard < Sinatra::Base
1717
get '/' do
1818
# Display experiments without a winner at the top of the dashboard
1919
@experiments = Split::Experiment.all_active_first
20+
21+
@metrics = Split::Metric.all
22+
2023
# Display Rails Environment mode (or Rack version if not using Rails)
2124
if Object.const_defined?('Rails')
2225
@current_env = Rails.env.titlecase

lib/split/dashboard/views/_experiment.erb

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
Experiment: <%= experiment.name %>
1010
<% if experiment.version > 1 %><span class='version'>v<%= experiment.version %></span><% end %>
1111
<% unless goal.nil? %><span class='goal'>Goal:<%= goal %></span><% end %>
12+
<% metrics = @metrics.select {|metric| metric.experiments.include? experiment} %>
13+
<% unless metrics.empty? %>
14+
<span class='goal'>Metrics:<%= metrics.map(&:name).join(', ') %></span>
15+
<% end %>
1216
</h2>
1317

1418
<% if goal.nil? %>

lib/split/metric.rb

+20-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,25 @@ def self.find(name)
4242
metric
4343
end
4444

45+
def self.find_or_create(attrs)
46+
metric = find(attrs[:name])
47+
unless metric
48+
metric = new(attrs)
49+
metric.save
50+
end
51+
metric
52+
end
53+
54+
def self.all
55+
redis_metrics = Split.redis.hgetall(:metrics).collect do |key, value|
56+
find(key)
57+
end
58+
configuration_metrics = Split.configuration.metrics.collect do |key, value|
59+
new(name: key, experiments: value)
60+
end
61+
redis_metrics | configuration_metrics
62+
end
63+
4564
def self.possible_experiments(metric_name)
4665
experiments = []
4766
metric = Split::Metric.find(metric_name)
@@ -78,4 +97,4 @@ def self.normalize_metric(label)
7897
return metric_name, goals
7998
end
8099
end
81-
end
100+
end

spec/dashboard_spec.rb

+13
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ def link(color)
2121
Split::Experiment.find_or_create({"link_color" => ["goal_1", "goal_2"]}, "blue", "red")
2222
}
2323

24+
let(:metric) {
25+
Split::Metric.find_or_create(name: 'testmetric', experiments: [experiment, experiment_with_goals])
26+
}
27+
2428
let(:red_link) { link("red") }
2529
let(:blue_link) { link("blue") }
2630

@@ -43,6 +47,15 @@ def link(color)
4347
post "/start/#{experiment.name}"
4448
get '/'
4549
last_response.body.should include('Reset Data')
50+
last_response.body.should_not include('Metrics:')
51+
end
52+
end
53+
54+
context "experiment with metrics" do
55+
it "should display the names of associated metrics" do
56+
metric
57+
get '/'
58+
last_response.body.should include('Metrics:testmetric')
4659
end
4760
end
4861

0 commit comments

Comments
 (0)