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 /lib.php | |
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()
Diffstat (limited to 'lib.php')
-rw-r--r-- | lib.php | 47 |
1 files changed, 47 insertions, 0 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 + ); +} |