From 85201f7de2d131aba3c4e10852aed3e11f39fa0a Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Tue, 20 Mar 2018 11:28:28 +0100 Subject: web-scripts/statistics.php: take info from database --- web-scripts/statistics.php | 100 ++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 55 deletions(-) (limited to 'web-scripts') diff --git a/web-scripts/statistics.php b/web-scripts/statistics.php index 279aa39..1e4d89b 100644 --- a/web-scripts/statistics.php +++ b/web-scripts/statistics.php @@ -1,54 +1,44 @@ 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(),\"-7 00:00:00\") " . + "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) { @@ -69,18 +59,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) { -- cgit v1.2.3-54-g00ecf