-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats-meta.php
59 lines (47 loc) · 1.45 KB
/
stats-meta.php
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
<?php
use MathPHP\Statistics\Descriptive;
require('functions.php');
$address = upstreamAddress();
$handle = FALSE;
$handle = fopen($address, 'r');
if ( !$handle ) {
http_response_code(500);
echo 'Error';
} else {
$torrents = handleGetFormatted($handle);
$stale = array_filter ($torrents, function($t) {
return ($t->scraped_date + 10800) < time();
});
$now = time();
$ages = array_map(function($t) {
return $t->scraped_date;
}, $torrents);
$oldest = min($ages);
$percentile_age = intval(Descriptive::percentile($ages, 5));
$noseeds = array_filter($torrents, function($t) {
return $t->seeders === 0 ;
});
$noleechers = array_filter($torrents, function($t) {
return $t->leechers === 0 ;
});
$weaklyseeded = array_filter($torrents, function($t) {
return $t->seeders < 3 ;
});
?>
<!DOCTYPE html>
<html lang="en">
<?php require('head.php'); ?>
<body>
<h1>Torrent Health Tracker</h1>
<h2>Updated: <?= (new \DateTime())->format('Y-m-d H:i:s e'); ?></h2>
<p>Stale count: <?= count($stale); ?></p>
<p>Oldest: <?= secondsToTime($now - $oldest); ?></p>
<p>(95% Age): <?= secondsToTime($now - $percentile_age); ?></p>
<p>No seeders: <?= count($noseeds); ?></p>
<p>No leechers: <?= count($noleechers); ?></p>
<p>Weakly seeded (< 3 seeds): <?= count($weaklyseeded); ?></p>
</body>
</html>
<?php
}
?>