diff options
author | Romain d'Alverny <rda@mageia.org> | 2012-09-04 13:42:17 +0000 |
---|---|---|
committer | Romain d'Alverny <rda@mageia.org> | 2012-09-04 13:42:17 +0000 |
commit | 0dfb3886cbc45c3733b2b79c5449c789372b65b1 (patch) | |
tree | 3554462c40109538d8faf7b9d57303b37ddeac73 | |
parent | 5c426d34bcddc9ef198f8da968ac34ae16692776 (diff) | |
download | pkgsubmit-0dfb3886cbc45c3733b2b79c5449c789372b65b1.tar pkgsubmit-0dfb3886cbc45c3733b2b79c5449c789372b65b1.tar.gz pkgsubmit-0dfb3886cbc45c3733b2b79c5449c789372b65b1.tar.bz2 pkgsubmit-0dfb3886cbc45c3733b2b79c5449c789372b65b1.tar.xz pkgsubmit-0dfb3886cbc45c3733b2b79c5449c789372b65b1.zip |
new function build_stats()
-rw-r--r-- | lib.php | 47 | ||||
-rw-r--r-- | test_index.php | 28 |
2 files changed, 48 insertions, 27 deletions
@@ -187,3 +187,50 @@ function get_upload_time() return null; } + +/** + * Build and return stats about all packages. + * + * @todo should not alter/return $pkgs + * + * @param array $pkgs + * + * @return array (array, array, integer, array) +*/ +function build_stats($pkgs) +{ + // count all packages statuses + $stats = array( + 'todo' => 0, + 'building' => 0, + 'partial' => 0, + 'uploaded' => 0, + 'rejected' => 0, + 'failure' => 0 + ); + $total = count($pkgs); + + // count users' packages + $users = array(); + + if ($total > 0) { + foreach ($pkgs as $key => $p) { + $pkgs[$key]['type'] = pkg_gettype($p); + + $stats[$pkgs[$key]['type']] += 1; + + if (!array_key_exists($p['user'], $users)) { + $users[$p['user']] = 1; + } else { + $users[$p['user']] += 1; + } + } + } + + return array( + $stats, + $users, + $total, + $pkgs + ); +} diff --git a/test_index.php b/test_index.php index 2382330..b8c3716 100644 --- a/test_index.php +++ b/test_index.php @@ -142,33 +142,7 @@ ksort($build_dates); $build_count = count($buildtime_total); $buildtime_total = array_sum($buildtime_total); -// count all packages statuses -$stats = array( - 'todo' => 0, - 'building' => 0, - 'partial' => 0, - 'uploaded' => 0, - 'rejected' => 0, - 'failure' => 0 -); -$total = count($pkgs); - -// count users' packages -$users = array(); - -if ($total > 0) { - foreach ($pkgs as $key => $p) { - $pkgs[$key]['type'] = pkg_gettype($p); - - $stats[$pkgs[$key]['type']] += 1; - - if (!array_key_exists($p['user'], $users)) { - $users[$p['user']] = 1; - } else { - $users[$p['user']] += 1; - } - } -} +list($stats, $users, $total, $pkgs) = build_stats($pkgs); $upload_time = get_upload_time(); |