summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain d'Alverny <rda@mageia.org>2012-09-04 13:42:17 +0000
committerRomain d'Alverny <rda@mageia.org>2012-09-04 13:42:17 +0000
commit0dfb3886cbc45c3733b2b79c5449c789372b65b1 (patch)
tree3554462c40109538d8faf7b9d57303b37ddeac73
parent5c426d34bcddc9ef198f8da968ac34ae16692776 (diff)
downloadpkgsubmit-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.php47
-rw-r--r--test_index.php28
2 files changed, 48 insertions, 27 deletions
diff --git a/lib.php b/lib.php
index 1b870ae..a4eb8e8 100644
--- a/lib.php
+++ b/lib.php
@@ -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();