mountain-goat 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
- data/README.md +5 -4
- data/generators/mg/mg_generator.rb +2 -2
- data/generators/mg/templates/update_mountain_goat_tables_v2.rb +73 -0
- data/lib/mountain-goat/controllers/mg/choices_controller.rb +81 -0
- data/lib/mountain-goat/controllers/mg/goals_controller.rb +136 -0
- data/lib/mountain-goat/controllers/mg/records_controller.rb +46 -0
- data/lib/mountain-goat/controllers/mg/tests_controller.rb +139 -0
- data/lib/mountain-goat/mg_core.rb +403 -0
- data/lib/mountain-goat/models/mg/choice.rb +50 -0
- data/lib/mountain-goat/models/mg/gi_meta.rb +10 -0
- data/lib/mountain-goat/models/mg/goal.rb +183 -0
- data/lib/mountain-goat/models/mg/goal_meta_type.rb +20 -0
- data/lib/mountain-goat/models/mg/gs_meta.rb +10 -0
- data/lib/mountain-goat/models/mg/record.rb +59 -0
- data/lib/mountain-goat/models/mg/test.rb +31 -0
- data/lib/mountain-goat/public/g-funnel.js +168 -0
- data/lib/mountain-goat/switch_choice.rb +32 -0
- data/lib/mountain-goat/version.rb +1 -1
- data/lib/mountain-goat/views/mountain_goat/layouts/.tmp_mountain_goat.html.erb.50680~ +76 -0
- data/lib/mountain-goat/views/mountain_goat/mg/choices/_choice_form.html.erb +37 -0
- data/lib/mountain-goat/views/mountain_goat/mg/choices/edit.html.erb +13 -0
- data/lib/mountain-goat/views/mountain_goat/mg/choices/index.html.erb +34 -0
- data/lib/mountain-goat/views/mountain_goat/mg/choices/new.html.erb +15 -0
- data/lib/mountain-goat/views/mountain_goat/mg/choices/show.html.erb +30 -0
- data/lib/mountain-goat/views/mountain_goat/mg/goals/.tmp__goal_form.html.erb.5027~ +0 -0
- data/lib/mountain-goat/views/mountain_goat/mg/goals/.tmp__goal_meta_type_form.html.erb.39992~ +0 -0
- data/lib/mountain-goat/views/mountain_goat/mg/goals/.tmp_edit.html.erb.55874~ +0 -0
- data/lib/mountain-goat/views/mountain_goat/mg/goals/.tmp_index.html.erb.97274~ +36 -0
- data/lib/mountain-goat/views/mountain_goat/mg/goals/_goal_form.html.erb +28 -0
- data/lib/mountain-goat/views/mountain_goat/mg/goals/_goal_meta_type_form.html.erb +34 -0
- data/lib/mountain-goat/views/mountain_goat/mg/goals/edit.html.erb +12 -0
- data/lib/mountain-goat/views/mountain_goat/mg/goals/index.html.erb +37 -0
- data/lib/mountain-goat/views/mountain_goat/mg/goals/new.html.erb +12 -0
- data/lib/mountain-goat/views/mountain_goat/mg/goals/show.html.erb +32 -0
- data/lib/mountain-goat/views/mountain_goat/mg/records/_record.html.erb +16 -0
- data/lib/mountain-goat/views/mountain_goat/mg/records/_records.html.erb +5 -0
- data/lib/mountain-goat/views/mountain_goat/mg/records/_records_form.html.erb +21 -0
- data/lib/mountain-goat/views/mountain_goat/mg/records/edit.html.erb +13 -0
- data/lib/mountain-goat/views/mountain_goat/mg/records/index.html.erb +17 -0
- data/lib/mountain-goat/views/mountain_goat/mg/records/new.html.erb +13 -0
- data/lib/mountain-goat/views/mountain_goat/mg/records/show.html.erb +14 -0
- data/lib/mountain-goat/views/mountain_goat/mg/report_items/.tmp__chart.html.erb.13419~ +18 -0
- data/lib/mountain-goat/views/mountain_goat/mg/report_items/.tmp__funnel.html.erb.60493~ +18 -0
- data/lib/mountain-goat/views/mountain_goat/mg/report_items/.tmp__report_item_form.html.erb.87420~ +10 -0
- data/lib/mountain-goat/views/mountain_goat/mg/report_items/.tmp__report_item_pivot_form.html.erb.77056~ +14 -0
- data/lib/mountain-goat/views/mountain_goat/mg/report_items/.tmp_edit.html.erb.31048~ +19 -0
- data/lib/mountain-goat/views/mountain_goat/mg/report_items/.tmp_new.html.erb.36371~ +17 -0
- data/lib/mountain-goat/views/mountain_goat/mg/report_items/_funnel.html.erb +13 -0
- data/lib/mountain-goat/views/mountain_goat/mg/reports/.tmp__report_form.html.erb.76535~ +21 -0
- data/lib/mountain-goat/views/mountain_goat/mg/reports/.tmp__report_report_items.html.erb.26030~ +5 -0
- data/lib/mountain-goat/views/mountain_goat/mg/reports/.tmp_edit.html.erb.78064~ +36 -0
- data/lib/mountain-goat/views/mountain_goat/mg/reports/.tmp_index.html.erb.74591~ +23 -0
- data/lib/mountain-goat/views/mountain_goat/mg/reports/.tmp_show.html.erb.58427~ +21 -0
- data/lib/mountain-goat/views/mountain_goat/mg/tests/_test_form.html.erb +25 -0
- data/lib/mountain-goat/views/mountain_goat/mg/tests/edit.html.erb +12 -0
- data/lib/mountain-goat/views/mountain_goat/mg/tests/index.html.erb +48 -0
- data/lib/mountain-goat/views/mountain_goat/mg/tests/new.html.erb +12 -0
- data/lib/mountain-goat/views/mountain_goat/mg/tests/show.html.erb +63 -0
- metadata +69 -6
- data/lib/mountain-goat/metric_tracking.rb +0 -401
- data/lib/mountain-goat/switch_variant.rb +0 -32
data/.gitignore
ADDED
data/README.md
CHANGED
@@ -40,13 +40,13 @@ For more information, read my blog post on how mountain goat quickly accomplishe
|
|
40
40
|
|
41
41
|
## Upgrade from < 1.0.0
|
42
42
|
|
43
|
-
If you are upgrading from Mountain Goat < 1.0.
|
43
|
+
If you are upgrading from Mountain Goat < 1.0.2, please run the following command (please overwrite mountain-goat.yml when prompted):
|
44
44
|
|
45
|
-
./script/generate mg --update=1.0.0,1.0.
|
45
|
+
./script/generate mg --update=1.0.0,1.0.2
|
46
46
|
|
47
47
|
rake db:migrate
|
48
48
|
|
49
|
-
This will install new migrations necessary for version 1.0.
|
49
|
+
This will install new migrations necessary for version 1.0.2. Leave out the 1.0.0 from the command if you are upgrading from version 1.0.0.
|
50
50
|
|
51
51
|
## Install
|
52
52
|
|
@@ -267,7 +267,8 @@ As mountain goat is a suite that is added into your project dynamically, the fol
|
|
267
267
|
* mg_reports
|
268
268
|
|
269
269
|
## Change log
|
270
|
-
1.0.
|
270
|
+
1.0.2 - Big UI overhaul ~ Robert
|
271
|
+
- Renamed objects to reflect real-world thinking (e.g. metric => test)
|
271
272
|
- Fixed glitch in bandit choice selection
|
272
273
|
1.0.0 - Changed from a/b testing to multi-armed bandit
|
273
274
|
- Added Mountain Goat Reporting
|
@@ -2,7 +2,7 @@ class MgGenerator < Rails::Generator::Base
|
|
2
2
|
def add_options!(opt)
|
3
3
|
opt.on('-p', '--password=password', String, "Your password to access Mountain Goat") { |v| options[:password] = v}
|
4
4
|
opt.on('-w', '--wkhtmltopdf=/path/to/dir', String, "Path to installation of wkhtmltopdf (optional)") { |v| options[:wkhtmltopdf] = v}
|
5
|
-
opt.on('-u', '--update=1.0.0,1.0.
|
5
|
+
opt.on('-u', '--update=1.0.0,1.0.2', String, "If you have previously installed Mountain Goat, use to generate *update* tables.") { |v| options[:update] = v}
|
6
6
|
puts <<-HELPFUL_INSTRUCTIONS
|
7
7
|
|
8
8
|
Mountain Goat is your home for in-house bandit testing.
|
@@ -42,7 +42,7 @@ class MgGenerator < Rails::Generator::Base
|
|
42
42
|
m.migration_template 'update_mountain_goat_tables.rb', 'db/migrate', { :migration_file_name => "update_mountain_goat_tables" }
|
43
43
|
end
|
44
44
|
|
45
|
-
if update.include?("1.0.1")
|
45
|
+
if update.include?("1.0.2") || update.include?("1.0.1")
|
46
46
|
m.migration_template 'update_mountain_goat_tables_v2.rb', 'db/migrate', { :migration_file_name => "update_mountain_goat_tables_v2" }
|
47
47
|
end
|
48
48
|
|
@@ -0,0 +1,73 @@
|
|
1
|
+
class UpdateMountainGoatTablesV2 < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
rename_table :mg_ci_metas, :mg_gi_metas
|
5
|
+
rename_table :mg_cs_metas, :mg_gs_metas
|
6
|
+
rename_table :mg_convert_meta_types, :mg_goal_meta_types
|
7
|
+
rename_table :mg_converts, :mg_goals
|
8
|
+
rename_table :mg_metric_variants, :mg_choices
|
9
|
+
rename_table :mg_metrics, :mg_tests
|
10
|
+
rename_table :mg_rallies, :mg_records
|
11
|
+
|
12
|
+
rename_column :mg_gi_metas, :rally_id, :mg_record_id
|
13
|
+
rename_column :mg_gi_metas, :convert_meta_type_id, :mg_goal_meta_type_id
|
14
|
+
rename_column :mg_goal_meta_types, :convert_id, :mg_goal_id
|
15
|
+
add_column :mg_goal_meta_types, :is_hidden, :boolean, :default => false
|
16
|
+
rename_column :mg_goals, :convert_type, :goal_type
|
17
|
+
remove_column :mg_goals, :reward
|
18
|
+
add_column :mg_goals, :is_hidden, :boolean, :default => false
|
19
|
+
rename_column :mg_gs_metas, :rally_id, :mg_record_id
|
20
|
+
rename_column :mg_gs_metas, :convert_meta_type_id, :mg_goal_meta_type_id
|
21
|
+
rename_column :mg_choices, :metric_id, :mg_test_id
|
22
|
+
rename_column :mg_choices, :conversions, :reward_count
|
23
|
+
rename_column :mg_tests, :metric_type, :test_type
|
24
|
+
add_column :mg_tests, :is_hidden, :boolean, :default => false
|
25
|
+
rename_column :mg_records, :convert_id, :mg_goal_id
|
26
|
+
rename_column :mg_report_items, :report_id, :mg_report_id
|
27
|
+
|
28
|
+
add_column :mg_goals, :rewards_given, :integer, :default => 0
|
29
|
+
add_column :mg_goals, :rewards_total, :float
|
30
|
+
add_column :mg_records, :reward, :float
|
31
|
+
|
32
|
+
add_column :mg_reports, :report_type, :string, :default => 'graph'
|
33
|
+
add_column :mg_reports, :report_opts, :text
|
34
|
+
add_column :mg_reports, :meta, :string
|
35
|
+
add_column :mg_reports, :meta2, :string
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.down
|
39
|
+
rename_table :mg_gi_metas, :mg_ci_metas
|
40
|
+
rename_table :mg_gs_metas, :mg_cs_metas
|
41
|
+
rename_table :mg_goal_meta_types, :mg_convert_meta_types
|
42
|
+
rename_table :mg_goals, :mg_converts
|
43
|
+
rename_table :mg_choices, :mg_metric_variants
|
44
|
+
rename_table :mg_tests, :mg_metrics
|
45
|
+
rename_table :mg_records, :mg_rallies
|
46
|
+
|
47
|
+
rename_column :mg_gi_metas, :mg_record_id, :rally_id
|
48
|
+
rename_column :mg_gi_metas, :mg_goal_meta_type_id, :convert_meta_type_id
|
49
|
+
rename_column :mg_goal_meta_types, :mg_goal_id, :convert_id
|
50
|
+
remove_column :mg_goal_meta_types, :is_hidden
|
51
|
+
rename_column :mg_goals, :goal_type, :convert_type
|
52
|
+
add_column :mg_goals, :reward, :float
|
53
|
+
remove_column :mg_goals, :is_hidden
|
54
|
+
rename_column :mg_gs_metas, :mg_record_id, :rally_id
|
55
|
+
rename_column :mg_gs_metas, :mg_goal_meta_type_id, :convert_meta_type_id
|
56
|
+
rename_column :mg_choices, :mg_test_id, :metric_id
|
57
|
+
rename_column :mg_choices, :reward_count, :conversions
|
58
|
+
rename_column :mg_tests, :test_type, :metric_type
|
59
|
+
remove_column :mg_tests, :is_hidden
|
60
|
+
rename_column :mg_records, :mg_goal_id, :convert_id
|
61
|
+
rename_column :mg_report_items, :mg_report_id, :report_id
|
62
|
+
|
63
|
+
remove_column :mg_goals, :rewards_given
|
64
|
+
remove_column :mg_goals, :rewards_total
|
65
|
+
remove_column :mg_records, :reward
|
66
|
+
|
67
|
+
remove_column :mg_reports, :report_type
|
68
|
+
remove_column :mg_reports, :report_opts
|
69
|
+
remove_column :mg_reports, :meta
|
70
|
+
remove_column :mg_reports, :meta2
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
|
2
|
+
class Mg::ChoicesController < Mg
|
3
|
+
|
4
|
+
# GET /mg/choices
|
5
|
+
# GET /mg/choices.xml
|
6
|
+
def index
|
7
|
+
@choices = Mg::Choice.all
|
8
|
+
|
9
|
+
respond_to do |format|
|
10
|
+
format.html # index.html.erb
|
11
|
+
format.xml { render :xml => @choices }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# GET /mg/choices/1
|
16
|
+
# GET /mg/coihces/1.xml
|
17
|
+
def show
|
18
|
+
@choice = Mg::Choice.find(params[:id])
|
19
|
+
|
20
|
+
respond_to do |format|
|
21
|
+
format.html # show.html.erb
|
22
|
+
format.xml { render :xml => @choice }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# GET /mg/tests/:test_id/choices/new
|
27
|
+
# GET /mg/tests/:test_id/choices/new.xml
|
28
|
+
def new
|
29
|
+
@test = Mg::Test.find( params[:test_id] )
|
30
|
+
@choice = Mg::Choice.new( :mg_test_id => @test.id )
|
31
|
+
|
32
|
+
respond_to do |format|
|
33
|
+
format.html # new.html.erb
|
34
|
+
format.xml { render :xml => @choice }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# GET /mg/choices/1/edit
|
39
|
+
def edit
|
40
|
+
@choice = Mg::Choice.find(params[:id])
|
41
|
+
end
|
42
|
+
|
43
|
+
# POST /mg/tests/:test_id/choices
|
44
|
+
# POST /mg/tests/:test_id/choices.xml
|
45
|
+
def create
|
46
|
+
@test = Mg::Test.find( params[:choice][:mg_test_id] )
|
47
|
+
@choice = Mg::Choice.new(params[:choice])
|
48
|
+
|
49
|
+
if @choice.save
|
50
|
+
flash[:notice] = 'Choice was successfully created.'
|
51
|
+
redirect_to mg_test_url :id => @choice.mg_test.id
|
52
|
+
else
|
53
|
+
render :action => "new"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# PUT /mg/choices/1
|
58
|
+
# PUT /mg/choices/1.xml
|
59
|
+
def update
|
60
|
+
@choice = Mg::Choice.find(params[:id])
|
61
|
+
|
62
|
+
if @choice.update_attributes(params[:choice])
|
63
|
+
flash[:notice] = 'Choice was successfully updated.'
|
64
|
+
redirect_to mg_test_url :id => @choice.mg_test.id
|
65
|
+
else
|
66
|
+
render :action => "edit"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# DELETE /mg/choices/1
|
71
|
+
# DELETE /mg/choices/1.xml
|
72
|
+
def destroy
|
73
|
+
@choice = Mg::Choice.find(params[:id])
|
74
|
+
@choice.destroy
|
75
|
+
|
76
|
+
respond_to do |format|
|
77
|
+
format.html { redirect_to mg_choices_url }
|
78
|
+
format.xml { head :ok }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
|
2
|
+
class Mg::GoalsController < Mg
|
3
|
+
|
4
|
+
# GET /mg/goal
|
5
|
+
# GET /mg/goals.xml
|
6
|
+
def index
|
7
|
+
@goals = Mg::Goal.all(:conditions => { :is_hidden => false } )
|
8
|
+
@hidden_goals = Mg::Goal.all(:conditions => { :is_hidden => true } )
|
9
|
+
|
10
|
+
respond_to do |format|
|
11
|
+
format.html # index.html.erb
|
12
|
+
format.xml { render :xml => @goals }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# GET /mg/goals/1
|
17
|
+
# GET /mg/goals/1.xml
|
18
|
+
def show
|
19
|
+
@goal = Mg::Goal.find(params[:id])
|
20
|
+
|
21
|
+
@results_per_day = []
|
22
|
+
created_at = @goal.created_at
|
23
|
+
running_date = Time.utc( created_at.year, created_at.month, created_at.day )
|
24
|
+
|
25
|
+
while running_date < Time.zone.now
|
26
|
+
@results_per_day.push({ :date => running_date.to_i * 1000, :val => @goal.mg_records.find( :all, :conditions => { :created_at => running_date..(running_date + 60 * 60 * 24) } ).count })
|
27
|
+
running_date += 60 * 60 * 24
|
28
|
+
end
|
29
|
+
|
30
|
+
@results_by_gmt = {}
|
31
|
+
@results_by_gmt_titles = {}
|
32
|
+
|
33
|
+
@goal.mg_goal_meta_types.each do |gmt|
|
34
|
+
@results_by_gmt[gmt.id] = []
|
35
|
+
@results_by_gmt_titles[gmt.id] = {}
|
36
|
+
i = 0
|
37
|
+
gmt.meta.all(:select => "data, count(*) as count", :group => "data").each do |meta|
|
38
|
+
next if meta.data.nil?
|
39
|
+
if gmt.meta_type == 'cs_meta' || gmt.meta_type == 'gs_meta'
|
40
|
+
@results_by_gmt[gmt.id].push( { :name => i, :val => meta.count } )
|
41
|
+
@results_by_gmt_titles[gmt.id].merge!({ i => meta.data })
|
42
|
+
else
|
43
|
+
@results_by_gmt[gmt.id].push( { :name => meta.data, :val => meta.count } )
|
44
|
+
end
|
45
|
+
|
46
|
+
i += 1
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
respond_to do |format|
|
51
|
+
format.html # show.html.erb
|
52
|
+
format.xml { render :xml => @goal }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# GET /mg/goals/new
|
57
|
+
# GET /mg/goals/new.xml
|
58
|
+
def new
|
59
|
+
@goal = Mg::Goal.new
|
60
|
+
|
61
|
+
respond_to do |format|
|
62
|
+
format.html # new.html.erb
|
63
|
+
format.xml { render :xml => @goal }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# GET /mg/goals/1/edit
|
68
|
+
def edit
|
69
|
+
@goal = Mg::Goal.find(params[:id])
|
70
|
+
end
|
71
|
+
|
72
|
+
# POST /mg/goals
|
73
|
+
# POST /mg/goals.xml
|
74
|
+
def create
|
75
|
+
@goal = Mg::Goal.new(params[:goal])
|
76
|
+
|
77
|
+
if @goal.save
|
78
|
+
flash[:notice] = 'Goal was successfully created.'
|
79
|
+
redirect_to mg_goal_url :id => @goal.id
|
80
|
+
else
|
81
|
+
render :action => "new"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# PUT /goals/1
|
86
|
+
# PUT /goals/1.xml
|
87
|
+
def update
|
88
|
+
@goal = Mg::Goal.find(params[:id])
|
89
|
+
|
90
|
+
if @goal.update_attributes(params[:goal])
|
91
|
+
flash[:notice] = 'Goal was successfully updated.'
|
92
|
+
redirect_to mg_goal_url :id => @goal.id
|
93
|
+
else
|
94
|
+
render :action => "edit"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
# GET /mg/goals/1/hide
|
100
|
+
# GET /mg/goals/1/hide.xml
|
101
|
+
def hide
|
102
|
+
@goal = Mg::Goal.find(params[:id])
|
103
|
+
@goal.update_attribute(:is_hidden, true)
|
104
|
+
flash[:notice] = "Goal #{@goal.name} has been hidden."
|
105
|
+
|
106
|
+
respond_to do |format|
|
107
|
+
format.html { redirect_to mg_goals_url }
|
108
|
+
format.xml { head :ok }
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# GET /mg/goals/1/unhide
|
113
|
+
# GET /mg/goals/1/unhide.xml
|
114
|
+
def unhide
|
115
|
+
@goal = Mg::Goal.find(params[:id])
|
116
|
+
@goal.update_attribute(:is_hidden, false)
|
117
|
+
flash[:notice] = "Goal #{@goal.name} has been restored."
|
118
|
+
|
119
|
+
respond_to do |format|
|
120
|
+
format.html { redirect_to mg_goals_url }
|
121
|
+
format.xml { head :ok }
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# DELETE /mg/goals/1
|
126
|
+
# DELETE /mg/goals/1.xml
|
127
|
+
def destroy
|
128
|
+
@goal = Mg::Goal.find(params[:id])
|
129
|
+
@goal.destroy
|
130
|
+
|
131
|
+
respond_to do |format|
|
132
|
+
format.html { redirect_to mg_goals_url }
|
133
|
+
format.xml { head :ok }
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
|
2
|
+
class Mg::RecordsController < Mg
|
3
|
+
|
4
|
+
# GET /mg/records
|
5
|
+
# GET /mg/goals/:goal_id/records
|
6
|
+
def index
|
7
|
+
@page = !params[:page].nil? ? params[:page].to_i : 1
|
8
|
+
@goal = Mg::Goal.find(params[:goal_id]) if !params[:goal_id].nil?
|
9
|
+
|
10
|
+
if @goal
|
11
|
+
@records = @goal.mg_records.find(:all, :conditions => { }, :order => "created_at DESC", :limit => 100, :offset => ( @page - 1 ) * 100 )
|
12
|
+
else
|
13
|
+
@records = Mg::Record.find(:all, :conditions => { }, :order => "created_at DESC", :limit => 100, :offset => ( @page - 1 ) * 100 )
|
14
|
+
end
|
15
|
+
|
16
|
+
respond_to do |format|
|
17
|
+
format.html { }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def new_records
|
22
|
+
recent_record = params[:recent_record].to_i
|
23
|
+
goal = Mg::Goal.find(params[:goal_id].to_i) unless params[:goal_id].blank?
|
24
|
+
|
25
|
+
if goal
|
26
|
+
@records = goal.mg_records.find(:all, :conditions => [ 'id > ?', recent_record ], :order => "id DESC" )
|
27
|
+
else
|
28
|
+
@records = Mg::Record.find(:all, :conditions => [ 'id > ?', recent_record ], :order => "id DESC" )
|
29
|
+
end
|
30
|
+
|
31
|
+
if @records.count > 0
|
32
|
+
render :json => { :success => true,
|
33
|
+
:result => render_to_string(:partial => 'mg/records/records', :locals => { :records => @records } ),
|
34
|
+
:recent_record_id => @records.first.id }
|
35
|
+
else
|
36
|
+
render :json => { :success => false }
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
# GET /mg/records/:id
|
42
|
+
def show
|
43
|
+
@record = Mg::Record.find(params[:id])
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
|
2
|
+
class Mg::TestsController < Mg
|
3
|
+
|
4
|
+
# GET /mg/tests
|
5
|
+
# GET /mg/tests.xml
|
6
|
+
def index
|
7
|
+
@tests = Mg::Test.all(:conditions => { :is_hidden => false } )
|
8
|
+
@hidden_tests = Mg::Test.all(:conditions => { :is_hidden => true } )
|
9
|
+
|
10
|
+
respond_to do |format|
|
11
|
+
format.html # index.html.erb
|
12
|
+
format.xml { render :xml => @tests }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# TODO: Whhhhha?
|
17
|
+
# GET /mg/tests/1
|
18
|
+
# GET /mg/tests/1.xml
|
19
|
+
def show
|
20
|
+
@test = Mg::Test.find(params[:id])
|
21
|
+
|
22
|
+
@rates = {}
|
23
|
+
@rates[:served] = []
|
24
|
+
@rates[:reward_count] = []
|
25
|
+
@rates[:reward_rates] = []
|
26
|
+
@rates[:titles] = {}
|
27
|
+
i = 0
|
28
|
+
@test.mg_choices.each do |mv|
|
29
|
+
@rates[:served].push( { :choice_type => i, :value => mv.served } )
|
30
|
+
@rates[:reward_count].push( { :choice_type => i, :value => mv.reward_count } )
|
31
|
+
@rates[:reward_rates].push( { :choice_type => i, :value => mv.reward_rate } )
|
32
|
+
@rates[:titles].merge!({i => mv.name})
|
33
|
+
i += 1
|
34
|
+
end
|
35
|
+
|
36
|
+
logger.warn @rates[:titles].inspect
|
37
|
+
|
38
|
+
respond_to do |format|
|
39
|
+
format.html # show.html.erb
|
40
|
+
format.xml { render :xml => @test }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# GET /mg/tests/new
|
45
|
+
# GET /mg/tests/new.xml
|
46
|
+
def new
|
47
|
+
@test = Mg::Test.new
|
48
|
+
|
49
|
+
respond_to do |format|
|
50
|
+
format.html # new.html.erb
|
51
|
+
format.xml { render :xml => @test }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# GET /mg/tests/1/edit
|
56
|
+
def edit
|
57
|
+
@test = Mg::Test.find(params[:id])
|
58
|
+
end
|
59
|
+
|
60
|
+
# POST /mg/tests
|
61
|
+
# POST /mg/tests.xml
|
62
|
+
def create
|
63
|
+
@test = Mg::Test.new(params[:test])
|
64
|
+
|
65
|
+
if @test.save
|
66
|
+
flash[:notice] = 'Test was successfully created.'
|
67
|
+
redirect_to mg_test_url :id => @test.id
|
68
|
+
else
|
69
|
+
render :action => "new"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# PUT /mg/tests/1
|
74
|
+
# PUT /mg/tests/1.xml
|
75
|
+
def update
|
76
|
+
@test = Mg::Test.find(params[:id])
|
77
|
+
|
78
|
+
if @test.update_attributes(params[:test])
|
79
|
+
flash[:notice] = 'Test was successfully updated.'
|
80
|
+
redirect_to mg_test_url :id => @test.id
|
81
|
+
else
|
82
|
+
render :action => "edit"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# GET /mg/tests/1/hide
|
87
|
+
# GET /mg/tests/1/hide.xml
|
88
|
+
def hide
|
89
|
+
@test = Mg::Test.find(params[:id])
|
90
|
+
@test.update_attribute(:is_hidden, true)
|
91
|
+
flash[:notice] = "Test #{@test.title} has been hidden."
|
92
|
+
|
93
|
+
respond_to do |format|
|
94
|
+
format.html { redirect_to mg_tests_url }
|
95
|
+
format.xml { head :ok }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# GET /mg/tests/1/unhide
|
100
|
+
# GET /mg/tests/1/unhide.xml
|
101
|
+
def unhide
|
102
|
+
@test = Mg::Test.find(params[:id])
|
103
|
+
@test.update_attribute(:is_hidden, false)
|
104
|
+
flash[:notice] = "Test #{@test.title} has been restored."
|
105
|
+
|
106
|
+
respond_to do |format|
|
107
|
+
format.html { redirect_to mg_tests_url }
|
108
|
+
format.xml { head :ok }
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# DELETE /mg/tests/1
|
113
|
+
# DELETE /mg/tests/1.xml
|
114
|
+
def destroy
|
115
|
+
@test = Mg::Test.find(params[:id])
|
116
|
+
@test.destroy
|
117
|
+
|
118
|
+
respond_to do |format|
|
119
|
+
format.html { redirect_to(mg_tests_url) }
|
120
|
+
format.xml { head :ok }
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
#TODO: This only works if we are using cookie storage? Clear session as well
|
125
|
+
def fresh_choices
|
126
|
+
#clear choices
|
127
|
+
#logger.warn "Headerish #{response.headers['cookie']}"
|
128
|
+
|
129
|
+
cookies.each do |cookie|
|
130
|
+
if cookie[0] =~ /test_([a-z0-9_]+)/
|
131
|
+
logger.warn "Deleting cookie #{cookie[0]}"
|
132
|
+
cookies.delete cookie[0]
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
flash[:notice] = "Your tests have been cleared from cookies."
|
137
|
+
redirect_to :back
|
138
|
+
end
|
139
|
+
end
|