Permalink
Browse files

Added multigraph.rb to generate multiple graphs

  • Loading branch information...
1 parent 37b1b93 commit aad52064ad1150d64f1ea9a235a48a2ed73e62ee Casper devboxmatsumoto.springer-sbm.com committed Feb 21, 2013
Showing with 81 additions and 3 deletions.
  1. +5 −1 jsonwriter.rb
  2. +29 −0 multigraph.rb
  3. +2 −2 statrunner.rb
  4. +45 −0 template/multigraph.html
View
@@ -9,11 +9,15 @@ def output_json(configuration,commits)
end
def output_array(configuration,commits)
+ generate_array(configuration,commits).to_json
+ end
+
+ def generate_array(configuration,commits)
title = ["date"] + configuration.collect.map{|key,command|key}
stats = [title]
commits.each { |commit| stats <<
(commit.select{|key,entry|key != :hash}.map{|key,entry|entry})
}
- stats.to_json
+ stats
end
end
View
@@ -0,0 +1,29 @@
+#!/usr/bin/env ruby
+require './statcollector.rb'
+require './jsonwriter.rb'
+require './csvwriter.rb'
+require 'psych'
+require 'json'
+
+configurations = ARGV.map {|yamlFile|
+ yaml = Psych.load_file(yamlFile)
+ StatConfiguration.new(yaml)
+}
+
+graphs = configurations.map {|configuration|
+ collector = StatCollector.new(configuration)
+ statistics = collector.get_statistics
+ writer = JSONWriter.new()
+ {
+ :name => configuration.name,
+ :statistics => writer.generate_array(configuration,statistics)
+ }
+}
+
+data = "var graphs = #{graphs.to_json};"
+html = graphs.map {|graph| "<div id=\"#{graph[:name]}\" style=\"float:left\"></div>"}.join("\n")
+
+template = File.open("./template/multigraph.html").read
+puts template.sub("$$DATA$$",data).sub("$$HTML$$",html)
+
+
View
@@ -19,10 +19,10 @@
puts statistics
when "array"
writer = JSONWriter.new()
- puts writer.output(configuration,statistics)
+ puts writer.output_json(configuration,statistics)
else #graph
writer = JSONWriter.new()
- output = writer.output(configuration,statistics)
+ output = writer.output_array(configuration,statistics)
template = File.open("./template/googlegraph.html").read
puts template.sub("$$DATA$$",output)
end
View
@@ -0,0 +1,45 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
+ <title>
+ Google Visualization API Sample
+ </title>
+ <script type="text/javascript" src="http://www.google.com/jsapi"></script>
+ <script type="text/javascript">
+ google.load('visualization', '1', {packages: ['corechart']});
+ </script>
+ <script type="text/javascript">
+ function drawVisualizations() {
+ for(var key in graphs) {
+ graph = graphs[key]
+ drawVisualization(graph.name, graph.statistics)
+ }
+ }
+
+ function drawVisualization(name,statistics) {
+
+ var data = google.visualization.arrayToDataTable(statistics);
+ var ac = new google.visualization.AreaChart(document.getElementById(name));
+ ac.draw(data, {
+ title : name,
+ isStacked: false,
+ width: 400,
+ height: 300,
+ vAxis: {title: "Number of Tests"},
+ hAxis: {title: "Date"}
+ });
+ }
+
+
+ $$DATA$$
+ google.setOnLoadCallback(drawVisualizations);
+ </script>
+ </head>
+ <body style="font-family: Arial;border: 0 none;">
+ <h1>Tests over time</h1>
+ $$HTML$$
+ </body>
+</html>
+
+

0 comments on commit aad5206

Please sign in to comment.