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