Navigation Menu

Skip to content

Commit

Permalink
graph with number of assertions over time
Browse files Browse the repository at this point in the history
  • Loading branch information
comboy committed Apr 3, 2012
1 parent 31487c8 commit d2d4c70
Show file tree
Hide file tree
Showing 5 changed files with 2,671 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/controllers/projects_controller.rb
Expand Up @@ -5,4 +5,19 @@ def show


def choose def choose
end end

def stats
must_be_in_project
@assertions = {}
@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
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}
end
end
end end
1 change: 1 addition & 0 deletions app/views/common/_sidebar.html.haml
Expand Up @@ -6,6 +6,7 @@
%ul %ul
= menu_li "Project info", :controller => '/projects', :action => 'show' = menu_li "Project info", :controller => '/projects', :action => 'show'
= menu_li "Latest commits", :controller => '/commits', :action => 'index', :project_name => @project.name = menu_li "Latest commits", :controller => '/commits', :action => 'index', :project_name => @project.name
= menu_li "Statistics", :controller => '/projects', :action => 'stats', :project_name => @project.name






1 change: 1 addition & 0 deletions app/views/layouts/application.html.haml
Expand Up @@ -4,6 +4,7 @@
= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" = javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"
= javascript_include_tag "jquery.simplemodal" = javascript_include_tag "jquery.simplemodal"
= javascript_include_tag 'application.js' = javascript_include_tag 'application.js'
= yield :head
%body %body


#header #header
Expand Down
55 changes: 55 additions & 0 deletions app/views/projects/stats.html.haml
@@ -0,0 +1,55 @@
- content_for :head do
= javascript_include_tag "jquery.flot"

%h2 Stats

%h3 Last 100 commits

%h4 Number of assertions

#choices{:style => "float: right;"}
#placeholder{ :style => "width:600px;height:300px;"}


: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();
});

0 comments on commit d2d4c70

Please sign in to comment.