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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
<?php
require_once "../init.php";
require_once BASE . "/lib/mysql.php";
if (array_key_exists("from",$_GET))
$min_time="from_base64(\"" . base64_encode("-".$_GET["from"]) . "\")";
else
$min_time="\"-7 00:00:00\"";
if (array_key_exists("arch",$_GET)) {
$arch_filter="`architectures`.`name` IN (\"\"";
foreach (explode("&",$_SERVER["QUERY_STRING"]) as $param) {
if (strpos($param,"arch=")!==0)
continue;
$arch_filter .= ",from_base64(\"" . base64_encode(substr($param,5)) . "\")";
}
$arch_filter .= ")";
$combiner_left="";
$combiner_right="";
$grouper="";
$joiner=" JOIN `architectures` ON `statistics`.`architecture`=`architectures`.`id`";
} else {
$arch_filter="1";
$combiner_left="SUM(";
$combiner_right=")";
$grouper=" GROUP BY `statistics`.`date`";
$joiner="";
};
$column_list = array(
"pending_tasks_count",
"pending_packages_count",
"staging_packages_count",
"testing_packages_count",
"tested_packages_count",
"broken_tasks_count",
"dependency_loops_count",
"dependency_looped_tasks_count",
"locked_tasks_count",
"blocked_tasks_count",
"next_tasks_count"
);
function combine_column($name) {
global $combiner_left;
global $combiner_right;
return $combiner_left . "`statistics`.`" . $name . "`" . $combiner_right . " AS `" . $name . "`";
}
$result = mysql_run_query(
"SELECT DISTINCT ".
"UNIX_TIMESTAMP(`statistics`.`date`) AS `date`," .
implode(",",array_map("combine_column",$column_list)) .
"FROM `statistics` " .
$joiner .
"WHERE `statistics`.`date`>=ADDDATE(NOW()," . $min_time . ") " .
"AND " . $arch_filter .
$grouper .
"ORDER BY `statistics`.`date`"
);
$t_min = -1;
$t_max = -1;
$val_max = -1;
while($vals = $result->fetch_assoc()) {
if ($t_min == -1)
$t_min = $vals["date"];
$t_max = $vals["date"];
foreach ($vals as $column => $val)
if ($column != "date") {
$values[$column][$vals["date"]] = $val;
$val_max = max($val_max,$val);
}
};
$print_columns = array_keys($values);
$max_len = 0;
foreach ($print_columns as $column) {
$len = strlen($values[$column][$t_max])+1;
if ($len > $max_len)
$max_len = $len;
}
$width = 1600;
$height = 600;
$border = 5;
$legend_line_length = 10;
$legend_height = 2 * ImageFontHeight(5) + $legend_line_length;
$im = @ImageCreate ($width + $legend_line_length + $max_len * ImageFontWidth(5), $height + $legend_height)
or die ("Cannot create new gd-image-stream");
$background_color = ImageColorAllocate ($im, 255, 255, 255);
$foreground_color = ImageColorAllocate ($im, 0, 0, 0);
$colors['stable_packages_count'] = ImageColorAllocate ($im, 0, 0, 0);
$colors['pending_tasks_count'] = ImageColorAllocate ($im, 0, 0, 128);
$colors['pending_packages_count'] = ImageColorAllocate ($im, 0, 0, 255);
$colors['staging_packages_count'] = ImageColorAllocate ($im, 0, 100, 0);
$colors['testing_packages_count'] = ImageColorAllocate ($im, 0, 200, 0);
$colors['tested_packages_count'] = ImageColorAllocate ($im, 100, 255, 0);
$colors['broken_tasks_count'] = ImageColorAllocate ($im, 255, 0, 0);
$colors['dependency_loops_count'] = ImageColorAllocate ($im, 128, 128, 0);
$colors['dependency_looped_tasks_count'] = ImageColorAllocate ($im, 255, 128, 128);
$colors['locked_tasks_count'] = ImageColorAllocate ($im, 128, 128, 128);
$colors['blocked_tasks_count'] = ImageColorAllocate ($im, 128, 0, 0);
$colors['next_tasks_count'] = ImageColorAllocate ($im, 0, 255, 255);
function scale($x, $x_min, $x_max, $scale, $log) {
if ($log) {
$x = log($x + 10);
$x_min = log($x_min + 10);
$x_max = log($x_max + 10);
};
if ($x_max == $x_min)
$frac = 0;
else
$frac = ($x - $x_min)/($x_max - $x_min);
if ($scale < 0)
return ($frac-1) * $scale;
else
return $frac * $scale;
};
function print_graph($data, $color) {
global $width, $height, $im, $t_min, $t_max, $val_max, $border, $legend_line_length;
ksort($data);
$last_t = -1;
$last_val = -1;
foreach ($data as $t => $val) {
if ($last_t != -1)
ImageLine(
$im,
scale($last_t,$t_min,$t_max,$width-2*$border,false)+$border+$legend_line_length,
scale($last_val,0,$val_max,-$height+2*$border,array_key_exists("log", $_GET))+$border,
scale($t,$t_min,$t_max,$width-2*$border,false)+$border+$legend_line_length,
scale($val,0,$val_max,-$height+2*$border,array_key_exists("log", $_GET))+$border,
$color
);
$last_t = $t;
$last_val = $val;
}
ImageString(
$im,
5,
$width+$legend_line_length,
scale($last_val,0,$val_max,-$height+2*$border,array_key_exists("log", $_GET))+$border - ImageFontHeight(5)/2,
" ".$data[$t_max],
$color
);
};
ImageRectangle($im, $legend_line_length, 0, $width-1+$legend_line_length, $height-1, $foreground_color);
$xpos = $legend_line_length;
foreach ($print_columns as $column) {
print_graph($values[$column], $colors[$column]);
ImageString($im, 5, $xpos, $height + $legend_line_length + ImageFontHeight(5), substr($column,0,-strlen("_count")), $colors[$column]);
$xpos += (strlen($column) - strlen("_count") + 1.75) * ImageFontWidth(5);
}
ImageString($im, 5, $legend_line_length, $height + $legend_line_length, date('Y-m-d H:i', $t_min), $foreground_color);
$s = date('Y-m-d H:i', $t_max);
ImageString($im, 5, $width+$legend_line_length - strlen($s)*ImageFontWidth(5), $height + $legend_line_length, $s, $foreground_color);
for ($t=ceil($t_min/24/60/60); $t<=floor($t_max/24/60/60); $t++)
ImageLine(
$im,
scale($t*24*60*60,$t_min,$t_max,$width-2*$border,false)+$border+$legend_line_length,
$height,
scale($t*24*60*60,$t_min,$t_max,$width-2*$border,false)+$border+$legend_line_length,
$height+$legend_line_length,
$foreground_color
);
for ($val=0; $val<=$val_max;) {
ImageLine(
$im,
0,
scale($val,0,$val_max,-$height+2*$border,array_key_exists("log", $_GET))+$border,
$legend_line_length,
scale($val,0,$val_max,-$height+2*$border,array_key_exists("log", $_GET))+$border,
$foreground_color
);
if (! array_key_exists("log", $_GET))
$val+=pow(10,round(log($val_max)/log(10))-1);
elseif ($val==0)
$val++;
else
$val=$val*10;
}
// ImageString ($im, 1, 5, 5, "Test-String ".rand(), $foreground_color);
header ("Content-type: image/png");
ImagePNG ($im);
?>
|