Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/web-scripts/statistics.php
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2018-03-23 20:18:01 +0100
committerAndreas Baumann <mail@andreasbaumann.cc>2018-03-23 20:18:01 +0100
commitc30de005f885202f24929bd4e3d3f5c885efbc0a (patch)
tree44b512356b80d3adad6521ad74f38ff9271f6c0d /web-scripts/statistics.php
parentff768f012bfef1bf264d06214aead70a58c0ff90 (diff)
parent497779257683e1c4ee2f2bf4c25687b34323c6be (diff)
Merge branch 'master' into opcodes
Diffstat (limited to 'web-scripts/statistics.php')
-rw-r--r--web-scripts/statistics.php115
1 files changed, 54 insertions, 61 deletions
diff --git a/web-scripts/statistics.php b/web-scripts/statistics.php
index 279aa39..c919f93 100644
--- a/web-scripts/statistics.php
+++ b/web-scripts/statistics.php
@@ -1,54 +1,49 @@
<?php
-$columns = array(
- 'stable',
- 'tasks',
- 'pending_packages',
- 'staging',
- 'testing',
- 'broken',
- 'loops',
- 'looped_packages',
- 'locked',
- 'blocked',
- 'next_pending',
- 'tested'
-);
-
-$print_columns = array(
- 'tasks',
- 'pending_packages',
- 'staging',
- 'testing',
- 'tested',
- 'broken',
- 'loops',
- 'looped_packages',
- 'locked',
- 'blocked',
- 'next_pending'
-);
+if (isset($_GET["from"]))
+ $min_time="from_base64(\"" . base64_encode("-".$_GET["from"]) . "\")";
+else
+ $min_time="\"-7 00:00:00\"";
+
+$mysql = new mysqli("localhost", "webserver", "empty", "buildmaster");
+if ($mysql->connect_error) {
+ die("Connection failed: " . $mysql->connect_error);
+}
+if (! $result = $mysql -> query(
+ "SELECT DISTINCT ".
+ "UNIX_TIMESTAMP(`statistics`.`date`) AS `date`," .
+ "`statistics`.`pending_tasks_count`," .
+ "`statistics`.`pending_packages_count`," .
+ "`statistics`.`staging_packages_count`," .
+ "`statistics`.`testing_packages_count`," .
+ "`statistics`.`tested_packages_count`," .
+ "`statistics`.`broken_tasks_count`," .
+ "`statistics`.`dependency_loops_count`," .
+ "`statistics`.`dependency_looped_tasks_count`," .
+ "`statistics`.`locked_tasks_count`," .
+ "`statistics`.`blocked_tasks_count`," .
+ "`statistics`.`next_tasks_count`" .
+ "FROM `statistics` " .
+ "WHERE `statistics`.`date`>=ADDTIME(NOW()," . $min_time . ") " .
+ "ORDER BY `statistics`.`date`"
+ ))
+ die($mysql->error);
$t_min = -1;
$t_max = -1;
$val_max = -1;
-foreach (explode("\n",trim(file_get_contents('/srv/http/statistics'))) as $val) {
- $val = explode(" ",$val);
- if (($t_min == -1) || ($t_min > $val[0]))
- $t_min = $val[0];
- if (($t_max == -1) || ($t_max < $val[0]))
- $t_max = $val[0];
- foreach ($columns as $id => $column) {
- if (count($val) > $id+1)
- $values[$column][$val[0]] = $val[$id+1];
- };
- foreach ($print_columns as $column) {
- if (array_key_exists($column,$values))
- if (($val_max == -1) || ($val_max < $values[$column][$val[0]]))
- $val_max = $values[$column][$val[0]];
- }
+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) {
@@ -61,7 +56,7 @@ $width = 1600;
$height = 600;
$border = 5;
$legend_line_length = 10;
-$legend_height = 3 * ImageFontHeight(5) + $legend_line_length;
+$legend_height = 4 * 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");
@@ -69,18 +64,18 @@ $im = @ImageCreate ($width + $legend_line_length + $max_len * ImageFontWidth(5),
$background_color = ImageColorAllocate ($im, 255, 255, 255);
$foreground_color = ImageColorAllocate ($im, 0, 0, 0);
-$colors['stable'] = ImageColorAllocate ($im, 0, 0, 0);
-$colors['tasks'] = ImageColorAllocate ($im, 0, 0, 128);
-$colors['pending_packages'] = ImageColorAllocate ($im, 0, 0, 255);
-$colors['staging'] = ImageColorAllocate ($im, 0, 100, 0);
-$colors['testing'] = ImageColorAllocate ($im, 0, 200, 0);
-$colors['tested'] = ImageColorAllocate ($im, 100, 255, 0);
-$colors['broken'] = ImageColorAllocate ($im, 255, 0, 0);
-$colors['loops'] = ImageColorAllocate ($im, 128, 128, 0);
-$colors['looped_packages'] = ImageColorAllocate ($im, 255, 128, 128);
-$colors['locked'] = ImageColorAllocate ($im, 128, 128, 128);
-$colors['blocked'] = ImageColorAllocate ($im, 128, 0, 0);
-$colors['next_pending'] = ImageColorAllocate ($im, 0, 255, 255);
+$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) {
@@ -128,13 +123,13 @@ function print_graph($data, $color) {
ImageRectangle($im, $legend_line_length, 0, $width-1+$legend_line_length, $height-1, $foreground_color);
-ImageString($im, 5, $legend_line_length, $height + $legend_line_length + 2*ImageFontHeight(5), "( ".trim(shell_exec("uptime | sed 's|^.*\\s\\(load\\)|\\1|'"))." )", $foreground_color);
+ImageString($im, 5, $legend_line_length, $height + 2*$legend_line_length + 2*ImageFontHeight(5), "( ".trim(shell_exec("uptime | sed 's|^.*\\s\\(load\\)|\\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), $column, $colors[$column]);
- $xpos += (strlen($column) + 1.75) * ImageFontWidth(5);
+ 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);
@@ -174,6 +169,4 @@ header ("Content-type: image/png");
ImagePNG ($im);
-// passthru('wc -l /srv/http/statistics');
-
?>