Support for parameters in web app.
authorJan Vrany <jan.vrany@fit.cvut.cz>
Sat, 24 Aug 2013 00:18:50 +0100
changeset 177 8e7f0029550d
parent 176 3e985ae7ad4d
child 178 bafafc76f0be
Support for parameters in web app. Parameters are now imported and saved in the DB. Tag-based comparison now can deal with them and correctly displays results with multiple results for same benchmark (but different parameter set)
web/app/assets/javascripts/bar_charts.js
web/app/assets/stylesheets/charts.css.scss
web/app/models/benchmark_result.rb
web/app/models/import_query.rb
web/app/models/tag.rb
web/app/views/tags/_tags_table.html.erb
web/db/schema.rb
--- a/web/app/assets/javascripts/bar_charts.js	Fri Aug 23 20:28:29 2013 +0100
+++ b/web/app/assets/javascripts/bar_charts.js	Sat Aug 24 00:18:50 2013 +0100
@@ -10,7 +10,16 @@
 						x: parseInt($(barValue).data("index")),
 						y: parseInt($(barValue).data("value"))
 					};
+				}).toArray(),
+
+				labels: $(barValues).find(".chart-bar-labels").map(function(idx, barLabels) {
+					return {
+						x: parseInt($(barLabels).data("index")),
+						name: $(barLabels).data("name"),
+						parameters: $(barLabels).data("parameters")
+					};
 				}).toArray()
+
 			})
 		});
 		return data;
@@ -18,11 +27,14 @@
 
 	function indexToLabel(graph, index) {
 
-		if ((index + 0.5) % 1 === 0) {
+		//return "";
+		
+		//if ((index + 0.5) % 1 === 0) {
 			return $(graph).find(".chart-bar-labels[data-index=" + Math.floor(index) + "]").data("name");
-		} else {
-			return "";
-		}
+		//} else {
+		//	return "XXX";
+		//}
+		
 	}
 
 	$(".chart-bar").each(function(idx, element) {
@@ -30,7 +42,8 @@
 
 		var graph = new Rickshaw.Graph({
 			element: $(element).find(".chart")[0],
-			renderer: 'bar',
+			renderer: 'scatterplot',
+			//renderer: 'bar',
 			series: gatherData($(element), palette)
 		});
 
@@ -46,30 +59,77 @@
 			orientation: 'bottom',
 			tickFormat: function(idx) {
 				return indexToLabel(element, idx);
+			},					
+			tickTransformation: function(svg) {	
+				svg.style("text-anchor", "end")
+     		 		.attr("dx", "-0.8em")
+         		.attr("dy", "-0.3em")
+         		.attr("transform", 'rotate(-90)');            		
 			},
+			pixelsPerTick: 37,
 			element: $(element).find(".chart-x-axis")[0],
 		});
+
+
+
 		x_axis.render();
 
 		var legend = new Rickshaw.Graph.Legend({
 			graph: graph,
-			element: $(element).find(".legend")[0]
+			element: $(element).find(".chart-legend")[0]
 		});
 
+		/*
 		var highlighter = new Rickshaw.Graph.Behavior.Series.Highlight({
 			graph: graph,
 			legend: legend
 		});
+    */
 
+
+		
 		var hoverDetail = new Rickshaw.Graph.HoverDetail( {
 			graph: graph,
-			xFormatter: function(x) { return ""; },
-			formatter: function(series, x, y) { 
-				return y + " [ms]<br/>" + series.name;
+			xFormatter: function(x) { 
+				//return graph.series[0].labels[x].name
+				return ""; 
+			},
+			formatter: function(series, x, y) { 				
+				var params = series.labels[x].parameters;
+				var table = "";
+				var i;
+				if (params.lenth != 0) {
+					for (i = 0; i < params.length; i++) {
+						table += "<tr><td>" + params[i].name + ":</td><td>" + params[i].value + "</td></tr>"
+					}
+					table = "<table>" + table + "</table>"
+				}
+				return (y + " [ms]<br/>" 
+					+ series.labels[x].name + "<br/>"
+					+ table
+					+ series.name);
 			},
 		} );
 
+
+		var shelving = new Rickshaw.Graph.Behavior.Series.Toggle( {
+			graph: graph,
+			legend: legend
+		} );
+
+		var order = new Rickshaw.Graph.Behavior.Series.Order( {
+			graph: graph,
+			legend: legend
+		} );
+
+		var highlight = new Rickshaw.Graph.Behavior.Series.Highlight( {
+			graph: graph,
+			legend: legend
+		} );
+
+
 		graph.renderer.unstack = true;
+		//graph.renderer.gapSize = 0.3;
 		graph.render();
 	});
 });
--- a/web/app/assets/stylesheets/charts.css.scss	Fri Aug 23 20:28:29 2013 +0100
+++ b/web/app/assets/stylesheets/charts.css.scss	Sat Aug 24 00:18:50 2013 +0100
@@ -1,3 +1,8 @@
+
+.chart-legend {
+  left: 40px;
+}
+
 .chart-container {
 	padding: 10px;
 	padding-bottom: 30px;
@@ -16,4 +21,5 @@
 
 .chart-container .chart-x-axis {
 	margin-left: 40px;
+  height: 30em;
 }
--- a/web/app/models/benchmark_result.rb	Fri Aug 23 20:28:29 2013 +0100
+++ b/web/app/models/benchmark_result.rb	Sat Aug 24 00:18:50 2013 +0100
@@ -14,6 +14,8 @@
   belongs_to :benchmark_info, inverse_of: :benchmark_results
   belongs_to :benchmark_batch, inverse_of: :benchmark_results
   has_many :benchmark_durations, dependent: :destroy, inverse_of: :benchmark_result
+  has_many :benchmark_parameters, dependent: :destroy, inverse_of: :benchmark_result
+
 
   def average_duration
     sum = benchmark_durations.inject(0) { |acc, val| acc += val.duration }
--- a/web/app/models/import_query.rb	Fri Aug 23 20:28:29 2013 +0100
+++ b/web/app/models/import_query.rb	Sat Aug 24 00:18:50 2013 +0100
@@ -18,9 +18,14 @@
       results["times"].each do |duration|
         result.benchmark_durations.create!(duration: duration)
       end
+
+      results["parameters"].each do | name, value|
+        result.benchmark_parameters.create!(name: name, value: value)
+      end
+      
     end
 
-    tags = find_tags(data["name"])
+    tags = find_tags(data["tags"] || data["name"])
     tags.each { |t| batch.tags << t }
     
     batch
--- a/web/app/models/tag.rb	Fri Aug 23 20:28:29 2013 +0100
+++ b/web/app/models/tag.rb	Sat Aug 24 00:18:50 2013 +0100
@@ -14,6 +14,12 @@
       sort { |a, b| a.name <=> b.name }
   end
 
+  def benchmark_batches_latest_for(benchmark_configuration)
+    benchmark_batches.
+      where(benchmark_configuration: benchmark_configuration)
+  end
+
+
   def latest_results_for(benchmark_info, benchmark_configuration)
     benchmark_batches.
       joins(:benchmark_results).
--- a/web/app/views/tags/_tags_table.html.erb	Fri Aug 23 20:28:29 2013 +0100
+++ b/web/app/views/tags/_tags_table.html.erb	Sat Aug 24 00:18:50 2013 +0100
@@ -1,28 +1,38 @@
+<% 
+require 'json' 
+%>
 <div class="row-fluid">
   <div class="chart chart-bar">
     <% tag.all_configurations.each do |benchmark_configuration| %>
       <div class="chart-bar-values"
         data-name="<%= benchmark_configuration.name %>">
-        <% tag.all_benchmark_infos.each_with_index do |benchmark_info, index| %>
-          <div class="chart-bar-value"
-            data-index="<%= index %>"
-            data-value="<%= tag.latest_results_for(
-              benchmark_info, 
-              benchmark_configuration
-            ).min_duration %>">
-          </div>
-          <div class="chart-bar-labels"
-            data-name="<%= benchmark_info.name %>"
-            data-index="<%= index %>">
-          </div>
+        <% index = 0 %>
+        <% tag.benchmark_batches_latest_for(benchmark_configuration).each do | batch | %>
+          <% batch.benchmark_results.each do | result | %>
+
+            <div class="chart-bar-value"
+              data-index="<%= index %>"
+              data-value="<%= result.min_duration %>">
+            </div>
+            <div class="chart-bar-labels"
+              data-index="<%= index %>"
+              data-name="<%= result.benchmark_info.name %>"
+              data-parameters="<%= JSON.generate(result.benchmark_parameters.collect { | p | p.to_json }) %>">
+            </div>
+
+          <% index += 1 %>
+          <% end %>
         <% end %>
       </div>
     <% end %>
+    <div class="chart-legend span10"></div>
     <div class="chart-container span10">       
       <div class="chart-y-axis"></div>
       <div class="chart"></div>
       <div class="chart-x-axis"></div>
     </div>
-    <div class="legend"></div>
+
+
+    
   </div>
 </div>
--- a/web/db/schema.rb	Fri Aug 23 20:28:29 2013 +0100
+++ b/web/db/schema.rb	Sat Aug 24 00:18:50 2013 +0100
@@ -11,7 +11,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 20130822093812) do
+ActiveRecord::Schema.define(version: 20130822205900) do
 
   create_table "benchmark_batches", force: true do |t|
     t.datetime "performed_at"
@@ -50,6 +50,14 @@
     t.string   "name"
   end
 
+  create_table "benchmark_parameters", force: true do |t|
+    t.integer  "benchmark_result_id"
+    t.string   "name"
+    t.string   "value"
+    t.datetime "created_at"
+    t.datetime "updated_at"
+  end
+
   create_table "benchmark_results", force: true do |t|
     t.integer  "benchmark_info_id"
     t.datetime "created_at"