Module: Conductor::DashboardHelper

Defined in:
app/helpers/conductor/dashboard_helper.rb

Instance Method Summary collapse

Instance Method Details

#current_weights(group_name, group) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'app/helpers/conductor/dashboard_helper.rb', line 4

def current_weights(group_name, group)
  total = group.inject(0) {|res, x| res += x.weight}
  data = []
  legend = []
  group.each do |x|
    legend << "#{x.alternative} (#{"%0.2f" % (x.weight.to_f/total.to_f*100)}%)"
    data << x.weight
  end
  return Gchart.pie(:data => data, :legend => legend, :size => '600x200')
end

#daily_stats(group_name, group) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/helpers/conductor/dashboard_helper.rb', line 20

def daily_stats(group_name, group)
  data = []
  legend = []
  colors = []
  group.group_by(&:alternative).map do |alternative, rows|
    legend << alternative
    data << rows.sort_by(&:activity_date).map(&:views)
    colors << random_color
  end
  
  min_value = group.min {|a,b| a.views <=> b.views }.views
  max_value = group.max {|a,b| a.views <=> b.views }.views
  dr = group.min {|a,b| a.activity_date <=> b.activity_date }.activity_date..group.max {|a,b| a.activity_date <=> b.activity_date }.activity_date
  
  return Gchart.line(:size => '600x250', 
              :legend => legend,
              :data => data,
              :axis_with_labels => ['x','y'],
              :axis_labels => [dr.step(3).map {|x| x},(min_value..max_value).step(10).map {|x| x}],
              :line_colors => colors)
end

#get_weight(group_name, alternative_name) ⇒ Object



15
16
17
18
# File 'app/helpers/conductor/dashboard_helper.rb', line 15

def get_weight(group_name, alternative_name)
  itm = Conductor::Experiment::Weight.for_group(group_name).with_alternative(alternative_name)
  return itm.first.weight if itm &&  itm.first
end

#random_colorObject

Method to select a random color from a list of hex codes

Example: random_color()

> “ff0000”



70
71
72
73
# File 'app/helpers/conductor/dashboard_helper.rb', line 70

def random_color()
  color_list = %w{000000 0000ff ff0000 ffff00 00ffff ff00ff 00ff00}
  return color_list[rand(color_list.size)]
end

#weight_history(group_name, group) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/helpers/conductor/dashboard_helper.rb', line 42

def weight_history(group_name, group)
  data = []
  legend = []
  colors = []
  group.group_by(&:alternative).each do |alternative, rows|
    legend << alternative
    data << rows.sort_by(&:computed_at).map(&:weight)
    colors << random_color
  end
  
  min_value = group.min {|a,b| a.weight <=> b.weight }.weight
  max_value = group.max {|a,b| a.weight <=> b.weight }.weight
  dr = group.min {|a,b| a.computed_at <=> b.computed_at}.computed_at.to_date..group.max {|a,b| a.computed_at <=> b.computed_at }.computed_at.to_date
  
  return Gchart.line(:size => '700x350', 
              :legend => legend,
              :data => data,
              :axis_with_labels => ['x','y'],
              :axis_labels => [dr.step(1).map {|x| x},(min_value..max_value).step(10).map {|x| x}],
              :line_colors => colors,
              :encoding => 'extended')
end