summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib.php110
-rw-r--r--test_index.php13
2 files changed, 123 insertions, 0 deletions
diff --git a/lib.php b/lib.php
index 48ec11f..5d1cfde 100644
--- a/lib.php
+++ b/lib.php
@@ -236,3 +236,113 @@ function build_stats($pkgs)
$pkgs
);
}
+
+
+class mga_bs_charts
+{
+
+ public static function js_init()
+ {
+ return <<<S
+<script type="text/javascript" src="https://www.google.com/jsapi"></script>
+<script type="text/javascript">
+
+ // Load the Visualization API and the piechart package.
+ google.load('visualization', '1.0', {'packages':['corechart']});
+
+ // Set a callback to run when the Google Visualization API is loaded.
+ google.setOnLoadCallback(drawChart);
+</script>
+S;
+ }
+
+ public static function js_draw_charts()
+ {
+ return <<<S
+function drawChart() {
+ draw_status_chart();
+ draw_buildtime_chart();
+ draw_buildschedule_chart();
+}
+S;
+ }
+
+ public static function js_draw_status_chart($stats, $id)
+ {
+ $rows = array();
+ foreach ($stats as $status => $count) {
+ $rows[] = sprintf("['%s', %d]", $status, $count);
+ }
+ $rows = implode(', ', $rows);
+ $s = <<<S
+function draw_status_chart() {
+ var data = new google.visualization.DataTable();
+ data.addColumn('string', 'Status');
+ data.addColumn('number', 'Packages');
+ data.addRows([{$rows}]);
+
+ var options = {'title':'Packages status',
+ 'width':300,
+ 'height':300};
+
+ var chart = new google.visualization.PieChart(document.getElementById('{$id}'));
+ chart.draw(data, options);
+}
+S;
+ return $s;
+ }
+
+ public static function js_draw_buildtime_chart($data, $id)
+ {
+ $d = print_r($data, true);
+ $rows = array("['Duration', 'Builds']", '[1, 3]');
+ foreach ($data as $duration => $count) {
+ $rows[] = sprintf("['%s', %d]", $duration, $count);
+ }
+ $rows = implode(', ', $rows);
+ return <<<S
+function draw_buildtime_chart() {
+ /*
+ {$d}
+ */
+ var data = google.visualization.arrayToDataTable([{$rows}]);
+ var options = {
+ title: 'Builds duration',
+ hAxis: {title: ''},
+ 'width':600,
+ 'height':300
+ };
+ var chart = new google.visualization.ColumnChart(document.getElementById('{$id}'));
+ chart.draw(data, options);
+}
+S;
+ }
+
+ public static function js_draw_buildschedule_chart($data, $id)
+ {
+ $d = print_r($data, true);
+ $rows = array("['Hour', 'Builds']", '[1, 3]');
+ foreach ($data as $hour => $count) {
+ $rows[] = sprintf("['%s', %d]", $hour, $count);
+ }
+ $rows = implode(', ', $rows);
+ return <<<S
+function draw_buildschedule_chart() {
+ /*
+ {$d}
+ */
+ var data = google.visualization.arrayToDataTable([{$rows}]);
+ var options = {
+ title: 'Builds layout',
+ hAxis: {title: ''},
+ 'width':600,
+ 'height':300
+ };
+ var chart = new google.visualization.ColumnChart(document.getElementById('{$id}'));
+ chart.draw(data, options);
+}
+S;
+ }
+
+}
+
diff --git a/test_index.php b/test_index.php
index 232ff64..eebb7d4 100644
--- a/test_index.php
+++ b/test_index.php
@@ -412,6 +412,19 @@ else
?>
</ul>
<div class="clear"></div>
+ <hr>
+ <div id="status-chart"></div>
+ <div id="buildtime-chart"></div>
+ <div id="buildschedule-chart"></div>
+ <?php
+ echo '<script>',
+ mga_bs_charts::js_draw_status_chart($stats, 'status-chart'),
+ mga_bs_charts::js_draw_buildtime_chart($buildtime_stats, 'buildtime-chart'),
+ mga_bs_charts::js_draw_buildschedule_chart($build_dates, 'buildschedule-chart'),
+ mga_bs_charts::js_draw_charts(),
+ '</script>';
+ echo mga_bs_charts::js_init();
+ ?>
<hr />
<p>Generated at <?php echo $date_gen; ?>.
Code for this page is in <a href="http://svnweb.mageia.org/soft/build_system/web/">http://svnweb.mageia.org/soft/build_system/web/</a>.</p>