Module: SplitCat::ExperimentsHelper
- Defined in:
- app/helpers/split_cat/experiments_helper.rb
Instance Method Summary collapse
- #experiment_csv_link(experiment) ⇒ Object
- #experiment_goal(goal) ⇒ Object
- #experiment_goal_list(experiment) ⇒ Object
- #experiment_hypothesis(hypothesis) ⇒ Object
- #experiment_hypothesis_list(experiment) ⇒ Object
- #experiment_hypothesis_percentage(hypothesis, value) ⇒ Object
- #experiment_info(experiment) ⇒ Object
- #experiment_info_row(name, value) ⇒ Object
- #experiment_report(experiment) ⇒ Object
- #experiment_report_goal(goal) ⇒ Object
- #experiment_report_header(experiment) ⇒ Object
- #experiment_report_totals(experiment) ⇒ Object
- #experiment_search_form(name, active) ⇒ Object
- #experiment_table(experiments) ⇒ Object
- #experiment_table_header ⇒ Object
- #experiment_table_row(experiment) ⇒ Object
Instance Method Details
#experiment_csv_link(experiment) ⇒ Object
4 5 6 7 8 9 10 |
# File 'app/helpers/split_cat/experiments_helper.rb', line 4 def experiment_csv_link( experiment ) content_tag( :p ) do text = t( :export_as_csv, :scope => :split_cat ) path = experiment_path( experiment, :format => 'csv' ) concat link_to text, path end end |
#experiment_goal(goal) ⇒ Object
20 21 22 23 24 25 26 |
# File 'app/helpers/split_cat/experiments_helper.rb', line 20 def experiment_goal( goal ) content_tag( :p ) do concat content_tag( :b, goal.name ) concat ' - ' concat goal.description end end |
#experiment_goal_list(experiment) ⇒ Object
12 13 14 15 16 17 18 |
# File 'app/helpers/split_cat/experiments_helper.rb', line 12 def experiment_goal_list( experiment ) content_tag( :ul ) do experiment.goals.each do |goal| concat content_tag( :li, experiment_goal( goal ) ) end end end |
#experiment_hypothesis(hypothesis) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'app/helpers/split_cat/experiments_helper.rb', line 28 def experiment_hypothesis( hypothesis ) ratio = hypothesis.weight.to_f / hypothesis.experiment.total_weight content_tag( :p ) do concat content_tag( :b, hypothesis.name ) concat sprintf( " (%0.0f%%)", ratio * 100 ) concat ' - ' concat hypothesis.description end end |
#experiment_hypothesis_list(experiment) ⇒ Object
39 40 41 42 43 44 45 |
# File 'app/helpers/split_cat/experiments_helper.rb', line 39 def experiment_hypothesis_list( experiment ) content_tag( :ul ) do experiment.hypotheses.each do |hypothesis| concat content_tag( :li, experiment_hypothesis( hypothesis ) ) end end end |
#experiment_hypothesis_percentage(hypothesis, value) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'app/helpers/split_cat/experiments_helper.rb', line 47 def experiment_hypothesis_percentage( hypothesis, value ) experiment = hypothesis.experiment value = number_with_delimiter( value || 0 ) ratio = experiment.hypothesis_counts[ hypothesis.name ] || 0 return sprintf( "%s ()", value ) if ratio == 0 return sprintf( "%s (%0.1f%%)", value, ( value.to_f / ratio ) * 100 ) end |
#experiment_info(experiment) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'app/helpers/split_cat/experiments_helper.rb', line 57 def experiment_info( experiment ) content_tag( :table ) do concat experiment_info_row( :id, experiment.id ) concat experiment_info_row( :name, experiment.name ) concat experiment_info_row( :description, experiment.description ) concat experiment_info_row( :created, experiment.created_at ) concat experiment_info_row( :subjects, number_with_delimiter( experiment.total_subjects ) ) end end |
#experiment_info_row(name, value) ⇒ Object
67 68 69 70 71 72 |
# File 'app/helpers/split_cat/experiments_helper.rb', line 67 def experiment_info_row( name, value ) content_tag( :tr ) do concat content_tag( :th, t( name, :scope => :split_cat ) ) concat content_tag( :td, value ) end end |
#experiment_report(experiment) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'app/helpers/split_cat/experiments_helper.rb', line 74 def experiment_report( experiment ) content_tag( :table, :border => 1 ) do concat experiment_report_header( experiment ) concat experiment_report_totals( experiment ) experiment.goals.each do |goal| concat experiment_report_goal( goal ) end end end |
#experiment_report_goal(goal) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/helpers/split_cat/experiments_helper.rb', line 84 def experiment_report_goal( goal ) experiment = goal.experiment style = cycle( 'background-color: #dddddd;', '' ) content_tag( :tr ) do concat content_tag( :th, goal.name, :style => style ) experiment.hypotheses.each do |hypothesis| count = experiment.goal_counts[ goal.name ][ hypothesis.name ] percentage = experiment_hypothesis_percentage( hypothesis, count ) concat content_tag( :td, percentage, :style => style ) end end end |
#experiment_report_header(experiment) ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'app/helpers/split_cat/experiments_helper.rb', line 99 def experiment_report_header( experiment ) content_tag( :tr ) do concat content_tag( :th ) experiment.hypotheses.each do |hypothesis| concat content_tag( :th, hypothesis.name ) end end end |
#experiment_report_totals(experiment) ⇒ Object
108 109 110 111 112 113 114 115 116 |
# File 'app/helpers/split_cat/experiments_helper.rb', line 108 def experiment_report_totals( experiment ) content_tag( :tr ) do concat content_tag( :th, t( :total, :scope => :split_cat ) ) experiment.hypotheses.each do |hypothesis| count = experiment.hypothesis_counts[ hypothesis.name ] concat content_tag( :td, experiment_hypothesis_percentage( hypothesis, count ) ) end end end |
#experiment_search_form(name, active) ⇒ Object
118 119 120 |
# File 'app/helpers/split_cat/experiments_helper.rb', line 118 def experiment_search_form( name, active) render :partial => 'search', :locals => { :name => name, :active => active } end |
#experiment_table(experiments) ⇒ Object
122 123 124 125 126 127 128 |
# File 'app/helpers/split_cat/experiments_helper.rb', line 122 def experiment_table( experiments ) show = t( :show, :scope => :split_cat ) header = experiment_table_header rows = experiments.map { |e| experiment_table_row( e ) } content = header + rows.join.html_safe return content_tag( :table, content, :border => 1 ) end |
#experiment_table_header ⇒ Object
130 131 132 133 134 135 136 137 138 |
# File 'app/helpers/split_cat/experiments_helper.rb', line 130 def experiment_table_header id = t( :id, :scope => :split_cat ) name = t( :name, :scope => :split_cat ) return content_tag( :tr ) do concat content_tag( :th, id ) concat content_tag( :th, name ) end end |
#experiment_table_row(experiment) ⇒ Object
140 141 142 143 144 145 146 147 148 149 |
# File 'app/helpers/split_cat/experiments_helper.rb', line 140 def experiment_table_row( experiment ) show = t( :show, :scope => :split_cat ) link = link_to show, :controller => :experiments, :action => :show, :id => experiment.id return content_tag( :tr ) do concat content_tag( :td, experiment.id ) concat content_tag( :td, experiment.name ) concat content_tag( :td, link ) end end |