Module: SplitCat::ExperimentsHelper

Defined in:
app/helpers/split_cat/experiments_helper.rb

Instance Method Summary collapse

Instance Method Details



4
5
6
7
8
9
10
# File 'app/helpers/split_cat/experiments_helper.rb', line 4

def experiment_csv_link( experiment )
  ( :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 )
  ( :p ) do
    concat ( :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 )
  ( :ul ) do
    experiment.goals.each do |goal|
      concat ( :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

  ( :p ) do
    concat ( :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 )
  ( :ul ) do
    experiment.hypotheses.each do |hypothesis|
      concat ( :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 )
  ( :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 )
  ( :tr ) do
    concat ( :th, t( name, :scope => :split_cat ) )
    concat ( :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 )
  ( :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;', '' )

  ( :tr ) do
    concat ( :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 ( :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 )
  ( :tr ) do
    concat ( :th )
    experiment.hypotheses.each do |hypothesis|
      concat ( :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 )
  ( :tr ) do
    concat ( :th, t( :total, :scope => :split_cat ) )
    experiment.hypotheses.each do |hypothesis|
      count = experiment.hypothesis_counts[ hypothesis.name ]
      concat ( :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 ( :table, content, :border => 1 )
end

#experiment_table_headerObject



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 ( :tr ) do
    concat ( :th, id )
    concat ( :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 ( :tr ) do
     concat ( :td, experiment.id )
     concat ( :td, experiment.name )
     concat ( :td, link )
    end
end