[ranch] 19: Add an output selector.

https://svn.lrde.epita.fr/svn/ranch/trunk Index: ChangeLog from Nicolas Despr�s <nicolas.despres@gmail.com> Add an output selector. * web/ranch/test/functional/graph_form_controller_test.rb: Test the draw request with a non default output arg_num number. * web/ranch/test/fixtures/outputs.yml: Add output with different name/unit to test the feature. * web/ranch/app/helpers/graph_helper.rb: Accept arg_num as argument. * web/ranch/app/helpers/graph_form_helper.rb: An helper to build a output selector. * web/ranch/app/controllers/graph_controller.rb: Accept a variable output arg_num. * web/ranch/app/controllers/graph_form_controller.rb: Set the proper output arg_num. * web/ranch/app/views/graph_form/index.rhtml: Add a output selector in the form. app/controllers/graph_controller.rb | 3 +-- app/controllers/graph_form_controller.rb | 5 ++++- app/helpers/graph_form_helper.rb | 21 +++++++++++++++++++++ app/helpers/graph_helper.rb | 10 ++++++++-- app/views/graph_form/index.rhtml | 3 ++- test/fixtures/outputs.yml | 23 +++++++++++++++++------ test/functional/graph_form_controller_test.rb | 15 +++++++++++++++ 7 files changed, 68 insertions(+), 12 deletions(-) Index: web/ranch/test/functional/graph_form_controller_test.rb --- web/ranch/test/functional/graph_form_controller_test.rb (revision 18) +++ web/ranch/test/functional/graph_form_controller_test.rb (working copy) @@ -74,4 +74,19 @@ assert flash.has_key? :error end + def test_draw_output_arg_num + post :draw, { + :project_id => 1, + :bench_name => 'determinize', + :revision => { :start => 1, :stop => 10 }, + :output_arg_num => 0, + } + assert_response :success + assert_template 'index' + + assert_equal 1, assigns(:project).id + assert_equal 'determinize', assigns(:bench_name) + assert_equal 0, assigns(:output_arg_num) + end + end Index: web/ranch/test/fixtures/outputs.yml --- web/ranch/test/fixtures/outputs.yml (revision 18) +++ web/ranch/test/fixtures/outputs.yml (working copy) @@ -1,12 +1,23 @@ <% id = 0 %> -<% val = 5; (1..10).each do |rev| %> -<%= "determinize_r#{rev}_utime:" %> +<% arg_num = 0 + { + 'utime' => 'sec', + 'memory' => 'KB', + 'nb_states' => '' + }.each do |name, unit| %> + +<% val = 5 + arg_num += 1 + (1..10).each do |rev| %> + +<%= "determinize_r#{rev}_#{name}:" %> id: <%= id += 1 %> - name: utime - value: <%= val += rev %> - unit: sec + name: <%= name %> + value: <%= val += rev + name.size %> + unit: <%= unit.inspect %> bench_id: <%= rev %> - arg_num: 1 + arg_num: <%= arg_num %> +<% end %> <% end %> Index: web/ranch/app/helpers/graph_helper.rb --- web/ranch/app/helpers/graph_helper.rb (revision 18) +++ web/ranch/app/helpers/graph_helper.rb (working copy) @@ -1,13 +1,19 @@ module GraphHelper - def graph_reg_tag(project_id, bench_name, rev_start, rev_stop, options={}) + def graph_reg_tag(project_id, + bench_name, + rev_start, + rev_stop, + arg_num, + options={}) url = { :controller => 'graph', :action => 'regression', :project_id => project_id, :bench_name => bench_name, :rev_start => rev_start, - :rev_stop => rev_stop + :rev_stop => rev_stop, + :arg_num => arg_num } options = url.merge(options) "<img src=\"#{url_for options}\" " + Index: web/ranch/app/helpers/graph_form_helper.rb --- web/ranch/app/helpers/graph_form_helper.rb (revision 18) +++ web/ranch/app/helpers/graph_form_helper.rb (working copy) @@ -1,2 +1,23 @@ module GraphFormHelper + + def outputs_tag(name, bench_name, arg_num=0, nb_arg=1, options={}) + bench = Bench.find_by_name bench_name + outputs = Output.find_by_sql "SELECT name, unit, arg_num " + + "FROM outputs " + + "WHERE bench_id = #{bench.id} " + + "GROUP BY arg_num " + + "ORDER BY arg_num" + + str = %(<select id="#{name}" name="#{name}">\n) + str += %(<option value="0" #{arg_num.zero? ? 'selected="selected"' : ''}>) + str += "**ALL**</option>\n" + outputs.each do |output| + str += %(<option value="#{output.arg_num}") + str += %( selected="selected") if output.arg_num == arg_num + str += %(>#{output.name}(#{output.unit})</option>\n) + end + str += %(</select>\n) + end + + end Index: web/ranch/app/controllers/graph_controller.rb --- web/ranch/app/controllers/graph_controller.rb (revision 18) +++ web/ranch/app/controllers/graph_controller.rb (working copy) @@ -5,7 +5,6 @@ def regression @project = Project.find params[:project_id] @bench_name = params[:bench_name] - @output_num = 1 #FIXME: manage several outputs results = Bench.find_by_sql "SELECT outputs.value, outputs.name, " + "outputs.unit, benches.revision " + @@ -13,7 +12,7 @@ "WHERE benches.project_id = #{@project.id} " + "AND benches.name = '#@bench_name' " + "AND outputs.bench_id = benches.id " + - "AND outputs.arg_num = #@output_num " + + "AND outputs.arg_num = #{params[:arg_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 18) +++ web/ranch/app/controllers/graph_form_controller.rb (working copy) @@ -1,5 +1,6 @@ class GraphFormController < ApplicationController - helper :graph + helper :graph, :graph_form + layout 'ranch' DEFAULT_REVISION_RANGE = 100 @@ -7,6 +8,7 @@ def index @bench_name = params[:bench_name] @project = Project.find params[:project_id] + @output_arg_num = 0 @draw_on = false @revision = {} @revision[:stop] = @project.head_revision @@ -17,6 +19,7 @@ def draw @bench_name = params[:bench_name] @project = Project.find params[:project_id] + @output_arg_num = params[:output_arg_num].to_i @draw_on = true @revision = params[:revision] head_rev = @project.head_revision Index: web/ranch/app/views/graph_form/index.rhtml --- web/ranch/app/views/graph_form/index.rhtml (revision 18) +++ web/ranch/app/views/graph_form/index.rhtml (working copy) @@ -19,6 +19,7 @@ "value" => @revision[:start] %></td> <td><%= text_field "revision", "stop", "size" => 8, "value" => @revision[:stop] %></td> + <td><%= outputs_tag "output_arg_num", @bench_name, @output_arg_num %></td> </tr> </table> </p> @@ -29,7 +30,7 @@ <% if @draw_on %> <%= graph_reg_tag @project.id, @bench_name, - @revision[:start], @revision[:stop] %> + @revision[:start], @revision[:stop], @output_arg_num %> <% else %> <%= content_tag "p", "No chart to display - click on Draw" %> <% end %>
participants (1)
-
Nicolas Despr�s