https://svn.lrde.epita.fr/svn/ranch/trunk
Index: ChangeLog
from Nicolas Despr�s <nicolas.despres(a)gmail.com>
Move the revision field from benches to outputs.
* web/ranch/test/fixtures/outputs.yml: The bench_id is now always
equal to one.
* web/ranch/test/fixtures/benches.yml: No longer iteration over
revision.
* web/ranch/app/models/bench.rb: Overload input request to force to
order by set_num and arg_num.
* web/ranch/app/controllers/graph_form_controller.rb,
* web/ranch/app/controllers/graph_controller.rb: Only takes the bench
id as parameter. Query only on the outputs table.
* web/ranch/app/views/layouts/_left_margin.rhtml: Only gives the
bench id as parameter.
* web/ranch/test/functional/graph_form_controller_test.rb,
* web/ranch/app/helpers/graph_helper.rb,
* web/ranch/app/views/graph_form/index.rhtml: Update to the new
parameter signature.
app/controllers/graph_controller.rb | 23 +++++++----------
app/controllers/graph_form_controller.rb | 34 ++++++--------------------
app/helpers/graph_helper.rb | 6 +---
app/models/bench.rb | 6 ++++
app/views/graph_form/index.rhtml | 11 +++-----
app/views/layouts/_left_margin.rhtml | 3 --
test/fixtures/benches.yml | 4 ---
test/fixtures/outputs.yml | 4 ++-
test/functional/graph_form_controller_test.rb | 24 +++++++-----------
9 files changed, 47 insertions(+), 68 deletions(-)
Index: web/ranch/test/functional/graph_form_controller_test.rb
--- web/ranch/test/functional/graph_form_controller_test.rb (revision 39)
+++ web/ranch/test/functional/graph_form_controller_test.rb (working copy)
@@ -14,12 +14,12 @@
end
def test_index
- get :index, { :project_id => 1, :bench_name => 'determinize' }
+ get :index, { :bench_id => 1 }
assert_response :success
assert_template 'index'
assert_not_nil assigns(:project)
- assert_not_nil assigns(:bench_name)
+ assert_not_nil assigns(:bench)
assert_not_nil assigns(:output_arg_num)
assert_not_nil assigns(:inputs)
assert !assigns(:draw_on)
@@ -30,15 +30,14 @@
def test_draw_regular_revision_range
post :draw, {
- :project_id => 1,
- :bench_name => 'determinize',
+ :bench_id => 1,
:revision => { :start => 2, :stop => 8 }
}
assert_response :success
assert_template 'index'
assert_not_nil assigns(:project)
- assert_not_nil assigns(:bench_name)
+ assert_not_nil assigns(:bench)
assert_not_nil assigns(:output_arg_num)
assert_not_nil assigns(:inputs)
assert_not_nil assigns(:input_set_num)
@@ -50,15 +49,14 @@
def test_draw_bad_revision_range
post :draw, {
- :project_id => 1,
- :bench_name => 'determinize',
+ :bench_id => 1,
:revision => { :start => -42, :stop => 500 }
}
assert_response :success
assert_template 'index'
assert_not_nil assigns(:project)
- assert_not_nil assigns(:bench_name)
+ assert_not_nil assigns(:bench)
assert_not_nil assigns(:output_arg_num)
assert_not_nil assigns(:inputs)
assert_not_nil assigns(:input_set_num)
@@ -70,15 +68,14 @@
def test_draw_start_sup_stop
post :draw, {
- :project_id => 1,
- :bench_name => 'determinize',
+ :bench_id => 1,
:revision => { :start => 42, :stop => 10 }
}
assert_response :redirect
assert_redirected_to :action => 'index'
assert_equal 1, assigns(:project).id
- assert_equal 'determinize', assigns(:bench_name)
+ assert_equal 'determinize', assigns(:bench).name
assert(flash.has_key?(:error))
assert_not_nil assigns(:output_arg_num)
assert_not_nil assigns(:inputs)
@@ -87,8 +84,7 @@
def test_draw_output_arg_num
post :draw, {
- :project_id => 1,
- :bench_name => 'determinize',
+ :bench_id => 1,
:revision => { :start => 1, :stop => 10 },
:output_arg_num => 0,
}
@@ -96,7 +92,7 @@
assert_template 'index'
assert_equal 1, assigns(:project).id
- assert_equal 'determinize', assigns(:bench_name)
+ assert_equal 'determinize', assigns(:bench).name
assert_equal 0, assigns(:output_arg_num)
assert_equal 3, assigns(:output_arg_nb)
assert_not_nil assigns(:inputs)
Index: web/ranch/test/fixtures/outputs.yml
--- web/ranch/test/fixtures/outputs.yml (revision 39)
+++ web/ranch/test/fixtures/outputs.yml (working copy)
@@ -1,5 +1,7 @@
<% id = 0 %>
+# Ouputs for the determinize (id = 1) bench.
+
<% outputs = {
'utime' => { :unit => 'sec', :val => 20, :inc => -1 },
'memory' => { :unit => 'KB', :val => 50000, :inc => -1000
},
@@ -18,7 +20,7 @@
name: <%= name %>
unit: <%= desc[:unit].inspect %>
value: <%= desc[:val] += desc[:inc] + set_num * 10%>
- bench_id: <%= rev %>
+ bench_id: <%= 1 %>
arg_num: <%= arg_num += 1 %>
set_num: <%= set_num %>
system_id: 0
Index: web/ranch/test/fixtures/benches.yml
--- web/ranch/test/fixtures/benches.yml (revision 39)
+++ web/ranch/test/fixtures/benches.yml (working copy)
@@ -1,11 +1,9 @@
<% id = 0 %>
-<% (1..10).each do |rev| %>
-<%= "determinize_r#{rev}:" %>
+determinize:
id: <%= id += 1 %>
project_id: 1
name: determinize
-<% end %>
quotient:
id: <%= id += 1 %>
Index: web/ranch/app/helpers/graph_helper.rb
--- web/ranch/app/helpers/graph_helper.rb (revision 39)
+++ web/ranch/app/helpers/graph_helper.rb (working copy)
@@ -1,7 +1,6 @@
module GraphHelper
- def graph_reg_tag(project_id,
- bench_name,
+ def graph_reg_tag(bench_id,
rev_start,
rev_stop,
arg_num,
@@ -10,8 +9,7 @@
url = {
:controller => 'graph',
:action => 'regression',
- :project_id => project_id,
- :bench_name => bench_name,
+ :bench_id => bench_id,
:rev_start => rev_start,
:rev_stop => rev_stop,
:arg_num => arg_num,
Index: web/ranch/app/models/bench.rb
--- web/ranch/app/models/bench.rb (revision 39)
+++ web/ranch/app/models/bench.rb (working copy)
@@ -6,4 +6,10 @@
validates_presence_of :name
validates_length_of :name, :maximum => 255
+ def input
+ Input.find(:all,
+ :conditions => [ "bench_id = ?", id ],
+ :order => "set_num, arg_num")
+ end
+
end
Index: web/ranch/app/controllers/graph_controller.rb
--- web/ranch/app/controllers/graph_controller.rb (revision 39)
+++ web/ranch/app/controllers/graph_controller.rb (working copy)
@@ -3,20 +3,17 @@
load 'grapher.rb'
def regression
- @project = Project.find params[:project_id]
- @bench_name = params[:bench_name]
+ @bench = Bench.find_by_id params[:bench_id]
+ @project = @bench.project
- results = Bench.find_by_sql "SELECT outputs.value, outputs.name, " +
- "outputs.unit, benches.revision " +
- "FROM outputs, benches " +
- "WHERE benches.project_id = #{(a)project.id} " +
- "AND benches.name = '#@bench_name' " +
- "AND outputs.bench_id = benches.id " +
- "AND outputs.arg_num = #{params[:arg_num]} " +
- "AND outputs.set_num = #{params[:input_set_num]} " +
- "AND #{params[:rev_start]} <= benches.revision " +
- "AND benches.revision <= #{params[:rev_stop]} " +
- "ORDER BY benches.revision"
+ results = Bench.find_by_sql "SELECT value, name, unit, revision " +
+ "FROM outputs " +
+ "WHERE bench_id = #{(a)bench.id} " +
+ "AND arg_num = #{params[:arg_num]} " +
+ "AND set_num = #{params[:input_set_num]} " +
+ "AND #{params[:rev_start]} <= revision " +
+ "AND revision <= #{params[:rev_stop]} " +
+ "ORDER BY revision"
data = results.collect { |v| v.value.to_f }
labels = results.collect { |v| "r#{v.revision}" }
Index: web/ranch/app/controllers/graph_form_controller.rb
--- web/ranch/app/controllers/graph_form_controller.rb (revision 39)
+++ web/ranch/app/controllers/graph_form_controller.rb (working copy)
@@ -9,9 +9,9 @@
DEFAULT_REVISION_RANGE = 100
def index
- @bench_name = params[:bench_name]
- @project = Project.find params[:project_id]
- select_inputs
+ @bench = Bench.find_by_id params[:bench_id]
+ @project = @bench.project
+ @inputs = @bench.input
@intput_set_num = 0
@output_arg_num = 0
@draw_on = false
@@ -22,18 +22,16 @@
end
def draw
- @bench_name = params[:bench_name]
- @project = Project.find params[:project_id]
+ @bench = Bench.find_by_id params[:bench_id]
+ @project = @bench.project
@draw_on = true
- select_inputs
+ @inputs = @bench.input
@input_set_num = params[:input_set_num].to_i
@output_arg_num = params[:output_arg_num].to_i
if @output_arg_num.zero?
@output_arg_nb = Output.find_by_sql "SELECT outputs.arg_num " +
- "FROM outputs, benches " +
- "WHERE benches.project_id = #{(a)project.id} " +
- "AND benches.name = '#@bench_name' " +
- "AND outputs.bench_id = benches.id " +
+ "FROM outputs " +
+ "WHERE outputs.bench_id = #{(a)bench.id} " +
"AND outputs.set_num = #@input_set_num " +
"GROUP BY outputs.arg_num " +
"ORDER BY outputs.arg_num "
@@ -51,22 +49,8 @@
else
flash[:error] = 'The start revision must be lesser than ' +
'the stop revision.'
- redirect_to(:action => 'index',
- :project_id => @project.id,
- :bench_name => @bench_name)
+ redirect_to(:action => 'index', :bench_id => @bench.id)
end
end
- protected
-
- def select_inputs
- @inputs = Input.find_by_sql "SELECT inputs.name, inputs.unit, " +
- "inputs.value, inputs.arg_num, inputs.set_num " +
- "FROM inputs, benches " +
- "WHERE benches.id = #{(a)project.id} " +
- "AND benches.name = '#@bench_name' " +
- "AND benches.id = inputs.bench_id " +
- "ORDER BY inputs.set_num, inputs.arg_num"
- end
-
end
Index: web/ranch/app/views/layouts/_left_margin.rhtml
--- web/ranch/app/views/layouts/_left_margin.rhtml (revision 39)
+++ web/ranch/app/views/layouts/_left_margin.rhtml (working copy)
@@ -19,8 +19,7 @@
<td>
<%= link_to bench.name, :controller => "graph_form",
:action => "index",
- :project_id => project.id,
- :bench_name => bench.name %>
+ :bench_id => bench.id %>
</td>
</tr>
<% end %>
Index: web/ranch/app/views/graph_form/index.rhtml
--- web/ranch/app/views/graph_form/index.rhtml (revision 39)
+++ web/ranch/app/views/graph_form/index.rhtml (working copy)
@@ -1,8 +1,7 @@
<!-- -*- html -*- -->
-<%= content_tag "h3", "#{(a)project.name}name}: #{@bench_name}" %>
+<%= content_tag "h3", "#{(a)project.name}name}: #{(a)bench.name}" %>
<%= start_form_tag :action => "draw",
- :project_id => @project.id,
- :bench_name => @bench_name %>
+ :bench_id => @bench.id %>
<table cellspacing=10>
@@ -60,7 +59,7 @@
<td>
<table>
<tr>
- <td><%= outputs_tag "output_arg_num", @bench_name, @output_arg_num
%></td>
+ <td><%= outputs_tag "output_arg_num", @bench.name, @output_arg_num
%></td>
</tr>
</td>
</table>
@@ -82,13 +81,13 @@
<% if @output_arg_num.zero? %>
<% 1.upto(@output_arg_nb) do |i| %>
<p>
- <%= graph_reg_tag @project.id, @bench_name,
+ <%= graph_reg_tag @bench.id,
@revision[:start], @revision[:stop],
i, @input_set_num %>
</p>
<% end %>
<% else %>
- <%= graph_reg_tag @project.id, @bench_name,
+ <%= graph_reg_tag @bench.id,
@revision[:start], @revision[:stop],
@output_arg_num, @input_set_num %>
<% end %>