narcissus: point to new source location
[angstrom:dr777s-narcissus.git] / graph.php
1 <html>
2 <head>
3 <title>Narcissus - Online image builder for the Angstrom distribution</title>
4
5 <meta http-equiv="refresh" content="600">
6
7 <script language="javascript" type="text/javascript" src="scripts/js/jquery-1.4.4.min.js"></script>
8 <script language="javascript" type="text/javascript" src="scripts/js/jquery.isotope.min.js"></script>
9 <script language="javascript" type="text/javascript" src="scripts/js/MochiKit.js"></script>
10 <script language="javascript" type="text/javascript" src="scripts/js/plotkit/Base.js"></script>
11 <script language="javascript" type="text/javascript" src="scripts/js/plotkit/Layout.js"></script>
12 <script language="javascript" type="text/javascript" src="scripts/js/plotkit/Canvas.js"></script>
13 <script language="javascript" type="text/javascript" src="scripts/js/plotkit/SweetCanvas.js"></script>
14
15 <link rel="stylesheet" type="text/css" title="dominion" href="css/dominion.css" media="screen" />
16 <?
17 /* Narcissus - Online image builder for the angstrom distribution
18  * Koen Kooi (c) 2008,2009 - all rights reserved 
19  */
20
21 $builds = array("beagleboard" => array("20090621" => 0));
22 $total = 0;
23
24 $firstdate = time() + 500;
25 $lastdate = 0;
26 $maxbuilds = 0;
27
28 $handle = fopen ("./deploy/stats.txt", "a+");
29 while ($stats = fscanf($handle, "%s %s\n")) {
30     list ($timestamp, $machine) = $stats;
31         $builddate = date("Ymd", $timestamp);
32         if (isset($builds[$machine][$builddate])) {
33                 $builds[$machine][$builddate] = $builds[$machine][$builddate] +1;
34         } else {
35                 $builds[$machine][$builddate]  = 1;
36         }
37         $total++;
38         if($lastdate < $timestamp) $lastdate = $timestamp;
39         if($firstdate > $timestamp) $firstdate = $timestamp;
40 }
41 fclose ($handle);
42
43 ksort($builds, SORT_STRING);
44
45 $timeframe = ( date("Y", $lastdate) - date("Y", $firstdate) ) * 365 +  date("z", $lastdate) - date("z",$firstdate);
46
47 if (isset($_GET["machine"])) {
48     $selectedmachine = $_GET["machine"];
49 }
50
51
52 if (isset($_GET["timeframe"])) {
53         $maxdays = $_GET["timeframe"] + 1;
54         if ($timeframe > $maxdays) $timeframe = $maxdays -1;
55 }
56
57 if ($timeframe < 80) {
58         $hfactor = 3.1;
59 } else {
60         $hfactor = 1;
61 }       
62
63 $modulovar = ceil($timeframe / 4) ;
64
65 for ($i = 0 ; $i <= $timeframe ; $i++) {
66     $statsdate = date("Ymd",$lastdate - ( ($timeframe - $i) * 86400 ) ) ;
67         if ( $i % $modulovar == 1 ) { 
68                 $xtick = date("d F Y", $lastdate - ( ($timeframe - $i) * 86400 )) ;
69         } else {
70                 $xtick = "";
71         }
72         $xticks .= "{v:$i, label:\"$xtick\"},\n";
73         foreach($builds as $machine => $foo) {
74                 if (isset($builds[$machine][$statsdate])) {
75                         $buildcount = $builds[$machine][$statsdate];
76                         $yvars[$machine] .= "[ $i, $buildcount ], \n";
77                         if($maxbuilds < $builds[$machine][$statsdate]) $maxbuilds = $builds[$machine][$statsdate];
78                 } else {
79                         $yvars[$machine] .= "[ $i, 0 ], \n";
80                 }
81         }
82 }       
83
84 ?>
85 <script language="javascript">
86 var options = {
87         "colorScheme": PlotKit.Base.palette(PlotKit.Base.baseColors()[0]),
88         "padding": {left: 0, right: 0, top: 10, bottom: 30},
89         "xTicks": [<? print $xticks; ?> ],
90         "drawYAxis": false,
91         "yAxis": [0, <?print $maxbuilds; ?>],
92         "yTickPrecision": 0
93 };
94
95 function drawGraph() {
96     if (parseInt(navigator.appVersion)>3) {
97         if (navigator.appName=='Netscape') {
98             winW = window.innerWidth - 30;
99             winH = (window.innerHeight - 30) * 0.9;
100         }
101         if (navigator.appName.indexOf('Microsoft')!=-1) {
102             winW = document.body.offsetWidth - 30;
103             winH = (document.body.offsetHeight - 30) * 0.9;
104         }
105     }
106         
107         <?
108
109         if(!isset($selectedmachine)) {
110         foreach($builds as $machine => $foo) {
111                 $machineyvars = $yvars[$machine];
112                 print("
113                           var layout = new PlotKit.Layout(\"bar\", options);
114                           layout.addDataset(\"$machine usage count\", [$machineyvars]);
115                           layout.evaluate();
116                           var canvas = MochiKit.DOM.getElement(\"graph-$machine\");
117                           
118                           canvas.setAttribute('width', winW/$hfactor);
119                           canvas.setAttribute('height', winH/5);
120                           var plotter = new PlotKit.SweetCanvasRenderer(canvas, layout, {});
121                           plotter.render();
122                           ");
123         }
124         } else {
125         $machine = $selectedmachine;
126                 $machineyvars = $yvars[$machine];
127         print("
128               var layout = new PlotKit.Layout(\"bar\", options);
129               layout.addDataset(\"$machine usage count\", [$machineyvars]);
130               layout.evaluate();
131               var canvas = MochiKit.DOM.getElement(\"graph-$machine\");
132               
133               canvas.setAttribute('width', winW/$hfactor);
134               canvas.setAttribute('height', winH/5);
135               var plotter = new PlotKit.SweetCanvasRenderer(canvas, layout, {});
136               plotter.render();
137               ");
138
139         }
140         ?>
141 }
142 MochiKit.DOM.addLoadEvent(drawGraph);
143
144 </script>
145 </head>
146 <body>
147 Statistics for the online image builder, number of builds per day<br>
148 <br>
149 <div id="container">
150 <?
151
152     if(!isset($selectedmachine)) {
153                 foreach ($builds as $machine => $foo) {
154                         print("<div class='item'><table align=left><td><br>$machine<br><div id='div-$machine'><canvas id='graph-$machine'></canvas></div></td></table></div>\n");
155                 }
156         } else {
157                 print("<div class='item'><table align=left><td><br>$selectedmachine<br><div id='div-$machine'><canvas id='graph-$selectedmachine'></canvas></div></td></table></div>\n");
158         }
159 ?>
160 </div>
161 <br clear=all><br>Total builds for all machines: <? print $total; ?>
162 </body>
163  <script>
164 $('#container').isotope({
165   // options
166   itemSelector : '.item',
167   //layoutMode : 'fitRows'
168 });
169 </script>
170 </html>