From 24a297d52441aa71307dc4517c0d1e8a257a1950 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=B8nstantine=20Kovalensky?=
<45331093+kovalensky@users.noreply.github.com>
Date: Wed, 8 Nov 2023 11:06:36 +0400
Subject: [PATCH] Show user clients percentage in tracker statistics (#1057)
---
admin/stats/tracker.php | 28 ++++++++++++++++++++++++++--
library/includes/functions.php | 12 +++++++++---
2 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/admin/stats/tracker.php b/admin/stats/tracker.php
index 1573029ff..dab598150 100644
--- a/admin/stats/tracker.php
+++ b/admin/stats/tracker.php
@@ -30,14 +30,16 @@ DB()->query('
CREATE TEMPORARY TABLE ' . TMP_TRACKER_TABLE . " (
`topic_id` mediumint(8) unsigned NOT NULL default '0',
`user_id` mediumint(9) NOT NULL default '0',
- `ip` char(8) binary NOT NULL default '0',
+ `ip` char(42) binary default '0',
+ `ipv6` char(42) binary default '0',
+ `peer_id` char(20) binary default '0',
`seeder` tinyint(1) NOT NULL default '0',
`speed_up` mediumint(8) unsigned NOT NULL default '0',
`speed_down` mediumint(8) unsigned NOT NULL default '0',
`update_time` int(11) NOT NULL default '0'
)
SELECT
- topic_id, user_id, ip, seeder, speed_up, speed_down, update_time
+ topic_id, user_id, ip, ipv6, peer_id, seeder, speed_up, speed_down, update_time
FROM " . BB_BT_TRACKER . '
');
@@ -73,6 +75,21 @@ foreach ($rowset as $cnt => $row) {
$peers_in_last_sec[] = sprintf('%3s', $row['peers']) . (($cnt && !(++$cnt % 15)) ? " \n" : '');
}
+$clients = [];
+$rowset = DB()->fetch_rowset('SELECT peer_id AS client FROM ' . TMP_TRACKER_TABLE);
+foreach ($rowset as $cnt => $row) {
+ $clients[] = get_user_torrent_client(substr($row['client'], 0, 3), true);
+}
+
+$client_count = count($clients);
+$client_values = array_count_values($clients);
+
+foreach ($client_values as $value => $count) {
+ $percentage = ($count / $client_count) * 100;
+ $clients_percentage[] ="$value ($count) => $percentage%";
+}
+$clients = implode('
', $clients_percentage);
+
function commify_callback($matches)
{
return commify($matches[0]);
@@ -112,6 +129,13 @@ echo "\n
' . implode(' ', $peers_in_last_sec) . "
'; diff --git a/library/includes/functions.php b/library/includes/functions.php index 4ba569caa..358aea4f9 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -1179,7 +1179,7 @@ function bb_date($gmepoch, $format = false, $friendly_date = true) * @param string $peer_id * @return mixed|string */ -function get_user_torrent_client(string $peer_id): mixed +function get_user_torrent_client(string $peer_id, bool $nameOnly = false): mixed { static $icons_extension = '.png'; static $clients = [ @@ -1231,12 +1231,18 @@ function get_user_torrent_client(string $peer_id): mixed } } - if (!empty($bestMatch)) { + if ($nameOnly) { + if (!empty($bestMatchLength)) { + return $bestMatch; + } + return $peer_id; + } + + if (!empty($bestMatchLength)) { return ''; } return $peer_id; - } function birthday_age($date)