summaryrefslogtreecommitdiff
path: root/web/lib/stats.inc.php
blob: 2c26d43ebd8fa819374f28e1125608481041efd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php

include_once('aur.inc.php');

function updates_table($dbh) {
	$key = 'recent_updates';
	if(!($newest_packages = get_cache_value($key))) {
		$q = 'SELECT * FROM Packages ORDER BY ModifiedTS DESC LIMIT 10';
		$result = $dbh->query($q);

		$newest_packages = new ArrayObject();
		while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
			$newest_packages->append($row);
		}
		set_cache_value($key, $newest_packages);
	}
	include('stats/updates_table.php');
}

function user_table($userid, $dbh) {
	$base_q = "SELECT count(*) FROM Packages WHERE Packages.MaintainerUID = " . $userid;

	$maintainer_unsupported_count = db_cache_value($base_q, $dbh,
		'user_unsupported_count:' . $userid);

	$q = "SELECT count(*) FROM Packages WHERE Packages.OutOfDateTS IS NOT NULL AND Packages.MaintainerUID = " . $userid;

	$flagged_outdated = db_cache_value($q, $dbh,
		'user_flagged_outdated:' . $userid);

	# If the user is a TU calculate the number of the packages
	$atype = account_from_sid($_COOKIE["AURSID"]);

	include('stats/user_table.php');
}

function general_stats_table($dbh) {
	# AUR statistics
	$q = "SELECT count(*) FROM Packages";
	$unsupported_count = db_cache_value($q, $dbh, 'unsupported_count');

	$q = "SELECT count(*) FROM Packages WHERE MaintainerUID IS NULL";
	$orphan_count = db_cache_value($q, $dbh, 'orphan_count');

	$q = "SELECT count(*) FROM Users";
	$user_count = db_cache_value($q, $dbh, 'user_count');

	$q = "SELECT count(*) FROM Users,AccountTypes WHERE Users.AccountTypeID = AccountTypes.ID AND AccountTypes.AccountType = 'Trusted User'";
	$tu_count = db_cache_value($q, $dbh, 'tu_count');

	$targstamp = intval(strtotime("-7 days"));
	$yearstamp = intval(strtotime("-1 year"));

	$q = "SELECT count(*) FROM Packages WHERE Packages.ModifiedTS >= $targstamp AND Packages.ModifiedTS = Packages.SubmittedTS";
	$add_count = db_cache_value($q, $dbh, 'add_count');

	$q = "SELECT count(*) FROM Packages WHERE Packages.ModifiedTS >= $targstamp AND Packages.ModifiedTS != Packages.SubmittedTS";
	$update_count = db_cache_value($q, $dbh, 'update_count');

	$q = "SELECT count(*) FROM Packages WHERE Packages.ModifiedTS >= $yearstamp AND Packages.ModifiedTS != Packages.SubmittedTS";
	$update_year_count = db_cache_value($q, $dbh, 'update_year_count');

	$q = "SELECT count(*) FROM Packages WHERE Packages.ModifiedTS = Packages.SubmittedTS";
	$never_update_count = db_cache_value($q, $dbh, 'never_update_count');

	include('stats/general_stats_table.php');
}