Skip to content
Browse files

graph with number of assertions over time

  • Loading branch information...
1 parent 31487c8 commit d2d4c70da0b3c28287ee451781de3c5e34ab90b5 @comboy comboy committed Apr 3, 2012
View
15 app/controllers/projects_controller.rb
@@ -5,4 +5,19 @@ def show
def choose
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
View
1 app/views/common/_sidebar.html.haml
@@ -6,6 +6,7 @@
%ul
= menu_li "Project info", :controller => '/projects', :action => 'show'
= menu_li "Latest commits", :controller => '/commits', :action => 'index', :project_name => @project.name
+ = menu_li "Statistics", :controller => '/projects', :action => 'stats', :project_name => @project.name
View
1 app/views/layouts/application.html.haml
@@ -4,6 +4,7 @@
= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"
= javascript_include_tag "jquery.simplemodal"
= javascript_include_tag 'application.js'
+ = yield :head
%body
#header
View
55 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();
+ });
+
View
2,599 public/javascripts/jquery.flot.js
2,599 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.

0 comments on commit d2d4c70

Please sign in to comment.
Something went wrong with that request. Please try again.