Module: DashboardHelper
- Defined in:
- lib/conductor/helpers/dashboard_helper.rb
Instance Method Summary collapse
- #current_weights(group_name, group) ⇒ Object
- #daily_stats(group_name, group) ⇒ Object
-
#random_color ⇒ Object
Method to select a random color from a list of hex codes.
- #weight_history(group_name, group) ⇒ Object
Instance Method Details
#current_weights(group_name, group) ⇒ Object
2 3 4 5 6 7 8 9 10 11 |
# File 'lib/conductor/helpers/dashboard_helper.rb', line 2 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
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/conductor/helpers/dashboard_helper.rb', line 13 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 |
#random_color ⇒ Object
Method to select a random color from a list of hex codes
Example: random_color()
> “ff0000”
63 64 65 66 |
# File 'lib/conductor/helpers/dashboard_helper.rb', line 63 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
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/conductor/helpers/dashboard_helper.rb', line 35 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 |