https://svn.lrde.epita.fr/svn/ranch/trunk
Index: ChangeLog
from Nicolas Despr�s <nicolas.despres(a)gmail.com>
Map an inputs set to an outputs set.
* web/ranch/test/functional/graph_form_controller_test.rb: Test that
the input_set_num is set.
* web/ranch/test/fixtures/inputs.yml: Clean up the code.
* web/ranch/test/fixtures/outputs.yml: More "realistic" value.
* web/ranch/test/fixtures/benches.yml: Add a revision number to all
the benches.
* web/ranch/app/helpers/graph_helper.rb: Pass the input set number
to the grapher.
* web/ranch/app/controllers/graph_controller.rb,
* web/ranch/app/controllers/graph_form_controller.rb: Exploit the
input set number.
* web/ranch/app/views/graph_form/index.rhtml: Add a drop down box
filled with all the input set.
* web/ranch/db/schema.rb: Add a set_num filed to the inputs and
outputs table.
app/controllers/graph_controller.rb | 1
app/controllers/graph_form_controller.rb | 8 +-
app/helpers/graph_helper.rb | 4 +
app/views/graph_form/index.rhtml | 75 ++++++++++++++++----------
db/schema.rb | 4 +
test/fixtures/benches.yml | 4 +
test/fixtures/inputs.yml | 26 +++++----
test/fixtures/outputs.yml | 27 ++++-----
test/functional/graph_form_controller_test.rb | 6 +-
9 files changed, 98 insertions(+), 57 deletions(-)
Index: web/ranch/test/functional/graph_form_controller_test.rb
--- web/ranch/test/functional/graph_form_controller_test.rb (revision 23)
+++ web/ranch/test/functional/graph_form_controller_test.rb (working copy)
@@ -41,6 +41,7 @@
assert_not_nil assigns(:bench_name)
assert_not_nil assigns(:output_arg_num)
assert_not_nil assigns(:inputs)
+ assert_not_nil assigns(:input_set_num)
assert_kind_of Hash, assigns(:revision)
assert_equal 2, assigns(:revision)[:start]
assert_equal 8, assigns(:revision)[:stop]
@@ -60,6 +61,7 @@
assert_not_nil assigns(:bench_name)
assert_not_nil assigns(:output_arg_num)
assert_not_nil assigns(:inputs)
+ assert_not_nil assigns(:input_set_num)
assert_kind_of Hash, assigns(:revision)
assert_equal 1, assigns(:revision)[:start]
assert_equal assigns(:project).head_revision, assigns(:revision)[:stop]
@@ -77,9 +79,10 @@
assert_equal 1, assigns(:project).id
assert_equal 'determinize', assigns(:bench_name)
- assert flash.has_key? :error
+ assert(flash.has_key?(:error))
assert_not_nil assigns(:output_arg_num)
assert_not_nil assigns(:inputs)
+ assert_not_nil assigns(:input_set_num)
end
def test_draw_output_arg_num
@@ -97,6 +100,7 @@
assert_equal 0, assigns(:output_arg_num)
assert_equal 3, assigns(:output_arg_nb)
assert_not_nil assigns(:inputs)
+ assert_not_nil assigns(:input_set_num)
end
end
Index: web/ranch/test/fixtures/inputs.yml
--- web/ranch/test/fixtures/inputs.yml (revision 23)
+++ web/ranch/test/fixtures/inputs.yml (working copy)
@@ -1,27 +1,33 @@
<% id = 0 %>
-<% (1..10).each do |rev| %>
+# Generate a set of determinize inputs.
+
+<% (1..10).each do |bench_id| %>
<% val = 2
- while val <= 256 do %>
+ set_num = 0
+ while set_num < 4 do %>
-<% arg_num = 0
+ <% arg_num = 1
{
'nb_states' => '',
'nb_transition' => '',
'foo' => 'unit_foo'
}.each do |name, unit| %>
-<%= "determinize_r#{rev}_#{name}_#{val}:" %>
+<%= "determinize_r#{bench_id}_#{name}_#{set_num}:" %>
id: <%= id += 1 %>
name: <%= name %>
unit: <%= unit.inspect %>
value: <%= val %>
- bench_id: <%= rev %>
- arg_num: <%= arg_num += 1 %>
-
-<% end
- val *= 2 %>
-<% end %>
+ bench_id: <%= bench_id %>
+ arg_num: <%= arg_num %>
+ set_num: <%= set_num %>
+
+ <% arg_num += 1
+ end %>
+ <% val *= 2
+ set_num += 1
+ end %>
<% end %>
Index: web/ranch/test/fixtures/outputs.yml
--- web/ranch/test/fixtures/outputs.yml (revision 23)
+++ web/ranch/test/fixtures/outputs.yml (working copy)
@@ -1,28 +1,29 @@
<% id = 0 %>
-<% val = 5
+<% outputs = {
+ 'utime' => { :unit => 'sec', :val => 20, :inc => -1 },
+ 'memory' => { :unit => 'KB', :val => 50000, :inc => -1000
},
+ 'nb_states' => { :unit => '', :val => 5, :inc => 42 },
+ }
(1..10).each do |rev| %>
-<% input = 2
- while input <= 256 do %>
+ <% set_num = 0
+ while set_num < 4 do %>
<% arg_num = 0
- {
- 'utime' => 'sec',
- 'memory' => 'KB',
- 'nb_states' => ''
- }.each do |name, unit| %>
+ outputs.each do |name, desc| %>
-<%= "determinize_r#{rev}_#{name}:" %>
+<%= "determinize_r#{rev}_#{name}_#{set_num}:" %>
id: <%= id += 1 %>
name: <%= name %>
- unit: <%= unit.inspect %>
- value: <%= val += input + rev + name.size %>
+ unit: <%= desc[:unit].inspect %>
+ value: <%= desc[:val] += desc[:inc] + set_num * 10%>
bench_id: <%= rev %>
arg_num: <%= arg_num += 1 %>
+ set_num: <%= set_num %>
-<% end
- input *= 2 %>
<% end %>
+ <% set_num += 1
+ end %>
<% end %>
Index: web/ranch/test/fixtures/benches.yml
--- web/ranch/test/fixtures/benches.yml (revision 23)
+++ web/ranch/test/fixtures/benches.yml (working copy)
@@ -13,13 +13,17 @@
id: <%= id += 1 %>
project_id: 1
name: quotient
+ revision: 1
open:
id: <%= id += 1 %>
project_id: 2
name: open
+ revision: 1
+
close:
id: <%= id += 1 %>
project_id: 2
name: close
+ revision: 1
Index: web/ranch/app/helpers/graph_helper.rb
--- web/ranch/app/helpers/graph_helper.rb (revision 23)
+++ web/ranch/app/helpers/graph_helper.rb (working copy)
@@ -5,6 +5,7 @@
rev_start,
rev_stop,
arg_num,
+ input_set_num,
options={})
url = {
:controller => 'graph',
@@ -13,7 +14,8 @@
:bench_name => bench_name,
:rev_start => rev_start,
:rev_stop => rev_stop,
- :arg_num => arg_num
+ :arg_num => arg_num,
+ :input_set_num => input_set_num
}
options = url.merge(options)
"<img src=\"#{url_for options}\" " +
Index: web/ranch/app/controllers/graph_controller.rb
--- web/ranch/app/controllers/graph_controller.rb (revision 23)
+++ web/ranch/app/controllers/graph_controller.rb (working copy)
@@ -13,6 +13,7 @@
"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"
Index: web/ranch/app/controllers/graph_form_controller.rb
--- web/ranch/app/controllers/graph_form_controller.rb (revision 23)
+++ web/ranch/app/controllers/graph_form_controller.rb (working copy)
@@ -9,6 +9,7 @@
@bench_name = params[:bench_name]
@project = Project.find params[:project_id]
select_inputs
+ @intput_set_num = 0
@output_arg_num = 0
@draw_on = false
@revision = {}
@@ -22,6 +23,7 @@
@project = Project.find params[:project_id]
@draw_on = true
select_inputs
+ @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 " +
@@ -29,11 +31,11 @@
"WHERE benches.project_id = #{(a)project.id} " +
"AND benches.name = '#@bench_name' " +
"AND outputs.bench_id = benches.id " +
+ "AND outputs.set_num = #@input_set_num " +
"GROUP BY outputs.arg_num " +
"ORDER BY outputs.arg_num "
@output_arg_nb = @output_arg_nb.size
end
-
@revision = params[:revision]
head_rev = @project.head_revision
@revision[:stop] = @revision[:stop].to_i
@@ -56,12 +58,12 @@
def select_inputs
@inputs = Input.find_by_sql "SELECT inputs.name, inputs.unit, " +
- "inputs.value, inputs.arg_num " +
+ "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.arg_num"
+ "ORDER BY inputs.set_num, inputs.arg_num"
end
end
Index: web/ranch/app/views/graph_form/index.rhtml
--- web/ranch/app/views/graph_form/index.rhtml (revision 23)
+++ web/ranch/app/views/graph_form/index.rhtml (working copy)
@@ -8,6 +8,9 @@
<p>
<center>
<p>
+
+<!-- REVISION -->
+
<p>
<table>
<tr>
@@ -23,61 +26,77 @@
"value" => @revision[:stop] %></td>
</tr>
</table>
-</p><p>
-<table>
- <tr>
- <td>Output:</td>
- <td><%= outputs_tag "output_arg_num", @bench_name, @output_arg_num
%></td>
- </tr>
-</table>
-</p><p>
+</p>
+
+<!-- INPUTS -->
+
+<p>
<table>
<tr>
<td>Inputs</td>
- <td>Value</td>
- </tr>
- <% arg_num = 1
- i = 0
- while i < @inputs.size do %>
- <tr>
- <%= content_tag "td", "#{@inputs[i].name}(#{@inputs[i].unit})"
%>
<td>
- <select id="#{(a)inputs[i].name}" name="#{(a)inputs[i].name}">
- <% while i < @inputs.size and arg_num == @inputs[i].arg_num do %>
- <%= content_tag "option", @inputs[i].value.to_s,
- :value => @inputs[i].value.to_s %>
-
- <% i += 1
- end
- arg_num += 1 %>
+ <select id="input_set_num" name="input_set_num">
+ <% i = 0
+ set_num = 0
+ while i < @inputs.size do
+ option_caption = ""
+ while i < @inputs.size and set_num == @inputs[i].set_num do
+ option_caption += "#{(a)inputs[i].name} #{(a)inputs[i].value}
#{(a)inputs[i].unit}, "
+ i += 1
+ end %>
+ <% option_opt = { :value => set_num }
+ option_opt[:selected] = "selected" if set_num == @input_set_num
%>
+ <%= content_tag "option", option_caption, option_opt %>
+ <% set_num += 1
+ end %>
</select>
</td>
</tr>
- <% end %>
</table>
</p>
+
+<!-- OUTPUTS -->
+
+<p>
+<table>
+ <tr>
+ <td>Output:</td>
+ <td><%= outputs_tag "output_arg_num", @bench_name, @output_arg_num
%></td>
+ </tr>
+</table>
+</p>
+
+<!-- SUBMIT BUTTON -->
+
</p>
<p style="color: red;"><%= flash[:error] %></p>
<p><%= submit_tag "Draw" %></p>
-<p>
<%= end_form_tag %>
+
+<!-- DRAWING -->
+
+<p>
<% if @draw_on %>
<% if @output_arg_num.zero? %>
<% 1.upto(@output_arg_nb) do |i| %>
<p>
<%= graph_reg_tag @project.id, @bench_name,
- @revision[:start], @revision[:stop], i %>
+ @revision[:start], @revision[:stop],
+ i, @input_set_num %>
</p>
<% end %>
<% else %>
<%= graph_reg_tag @project.id, @bench_name,
- @revision[:start], @revision[:stop], @output_arg_num %>
+ @revision[:start], @revision[:stop],
+ @output_arg_num, @input_set_num %>
<% end %>
<% else %>
<%= content_tag "p", "No chart to display - click on Draw"
%>
<% end %>
-</p></center></p>
+</p>
+
+</center></p>
<p><%= link_to "Back", :controller => "benches",
:action => "list",
:project_id => @project.id %></p>
Index: web/ranch/db/schema.rb
--- web/ranch/db/schema.rb (revision 23)
+++ web/ranch/db/schema.rb (working copy)
@@ -17,7 +17,8 @@
t.column "unit", :string, :limit => 128, :default =>
"nounit", :null => false
t.column "value", :float, :default => 0.0, :null => false
t.column "bench_id", :integer, :default => 0, :null => false
- t.column "arg_num", :integer, :limit => 8, :default => 0, :null =>
false
+ t.column "arg_num", :integer, :limit => 8, :default => 1, :null =>
false
+ t.column "set_num", :integer, :default => 0, :null => false
end
create_table "outputs", :force => true do |t|
@@ -26,6 +27,7 @@
t.column "unit", :string, :limit => 128, :default =>
"nounit", :null => false
t.column "bench_id", :integer, :default => 0, :null => false
t.column "arg_num", :integer, :limit => 8, :default => 1, :null =>
false
+ t.column "set_num", :integer, :default => 0, :null => false
end
add_index "outputs", ["bench_id"], :name =>
"bench_id"