Permalink
Browse files

more graphs

  • Loading branch information...
1 parent a93e1b4 commit 737a81ac1a7abef7a86bdaa8d51dbd4ac0f21c92 @comboy comboy committed Apr 5, 2012
Showing with 49 additions and 46 deletions.
  1. +20 −6 app/controllers/projects_controller.rb
  2. +29 −40 app/views/projects/stats.html.haml
@@ -8,16 +8,30 @@ def choose
def stats
must_be_in_project
- @assertions = {}
+ @assertions = []
+ @tests_failing = []
+ @run_times = []
@project.test_suites.each do |ts|
# IMPROVE: N+!, but it's stats, we can cache
data = @project.commits.order('committed_at DESC').limit(500).map do |commit|
- number = TestSuiteRun.where(:commit_id => commit.id, :test_suite_id => ts.id).average(:assertions_count).to_i
- number == 0 ? nil : number
+ r = TestSuiteRun.select('max(assertions_count) assertions_count, min(errors_count) errors_count ,min(failures_count) failures_count, avg(run_time) run_time').where(:commit_id => commit.id, :test_suite_id => ts.id).first
+ r['assertions_count'] = nil if r['assertions_count'] == 0
+ r['total_errors'] = r['errors_count'].to_i + r['failures_count'].to_i
+ r['run_time'] = nil if r['run_time'] == 0
+ r
end
- data_with_index = []
- data.compact.reverse.each_with_index { |d,i| data_with_index << [i,d] }
- @assertions[ts.name] = {:label => ts.name, :data => data_with_index}
+
+ @assertions << {:label => ts.name, :data => flot_data(data,'assertions_count')}
+ @tests_failing << {:label => ts.name, :data => flot_data(data,'total_errors')}
+ @run_times << {:label => ts.name, :data => flot_data(data,'run_time')}
end
end
+
+ protected
+
+ def flot_data(data, value)
+ data_with_index = []
+ data.compact.reverse.each_with_index { |d,i| data_with_index << [i,d[value]] }
+ data_with_index
+ end
end
@@ -3,53 +3,42 @@
%h2 Stats
-%h3 Last 100 commits
+%h3 Last 500 commits
%h4 Number of assertions
+#assertions{ :style => "width:700px;height:300px;"}
-#choices{:style => "float: right;"}
-#placeholder{ :style => "width:600px;height:300px;"}
+%h4 Number of tests_failing
+#tests_failing{ :style => "width:700px;height:300px;"}
+%h4 Test suites run times
+#run_times{ :style => "width:700px;height:300px;"}
+
+-# IMPROVE: DRY
:javascript
$(function () {
- var datasets = #{@assertions.to_json};
- // hard-code color indices to prevent them from shifting as
- // countries are turned on/off
- var i = 0;
- $.each(datasets, function(key, val) {
- val.color = i;
- ++i;
- });
-
- // insert checkboxes
- var choiceContainer = $("#choices");
- $.each(datasets, function(key, val) {
- choiceContainer.append('<br/><input type="checkbox" name="' + key +
- '" checked="checked" id="id' + key + '">' +
- '<label for="id' + key + '">'
- + val.label + '</label>');
- });
- choiceContainer.find("input").click(plotAccordingToChoices);
-
-
- function plotAccordingToChoices() {
- var data = [];
-
- choiceContainer.find("input:checked").each(function () {
- var key = $(this).attr("name");
- if (key && datasets[key])
- data.push(datasets[key]);
- });
-
- if (data.length > 0)
- $.plot($("#placeholder"), data, {
- yaxis: { min: 0 },
- xaxis: { tickDecimals: 0 }
- });
- }
-
- plotAccordingToChoices();
+ var assertions = #{@assertions.to_json};
+ $.plot($("#assertions"), assertions, {
+ yaxis: { min: 0 },
+ xaxis: { tickDecimals: 0 },
+ legend: { position: 'nw' }
+ });
+
+ var tests_failing = #{@tests_failing.to_json};
+ $.plot($("#tests_failing"), tests_failing, {
+ yaxis: { min: 0 },
+ xaxis: { tickDecimals: 0 },
+ legend: { position: 'nw' }
+ });
+
+ var run_times = #{@run_times.to_json};
+ $.plot($("#run_times"), run_times, {
+ yaxis: { min: 0 },
+ xaxis: { tickDecimals: 0 },
+ legend: { position: 'nw' }
+ });
+
});

0 comments on commit 737a81a

Please sign in to comment.