bigly-chat/docs/stats.php
2025-01-25 09:46:02 -05:00

81 lines
1.8 KiB
PHP
Executable file

<?php
require(__DIR__ . "/../libs/page.php");
require(__DIR__ . "/../libs/form.php");
require(__DIR__ . "/../libs/comment.php");
page_header();
function get_handler() {
global $db;
$stmt = $db->prepare("SELECT * FROM main.auth"); //weirdly, this requires a schema name
$stmt->execute([]);
$result = $stmt->fetchAll(PDO::FETCH_DEFAULT);
$pr = array();
foreach ($result as $usern) {
$pr[$usern['username']] = 1;
}
for ($i = 0; $i < 10; $i++) {
foreach ($result as $usern) {
$theuser = $usern['username'];
$stmt = $db->prepare("SELECT * FROM main.follow WHERE username = ?");
$stmt->execute([$theuser]);
$followers = $stmt->fetchAll(PDO::FETCH_DEFAULT);
foreach ($followers as $follown) {
$fn = $follown['target'];
if ($usern['username'] == $fn) continue;
$stmt = $db->prepare("SELECT * FROM main.follow WHERE target = ? AND NOT username = ?");
$stmt->execute([$fn,$fn]);
$dst = count($stmt->fetchAll(PDO::FETCH_DEFAULT));
$pr[$usern['username']] += $pr[$fn] / ($dst + 5) / 2;
}
$h = $pr[$usern['username']];
}
}
function cmp($a, $b) {
if ($a == $b) {
return 0;
}
return ($a > $b) ? -1 : 1;
}
uasort($pr,'cmp');
$sum = array_sum($pr);
foreach ($pr as $usern => $rr) { ?>
<div class='comment'>
<div class="avatar">
<img src="/pfp/<?php echo $usern ?>.png" class="avatar-img">
<div>
<div><b>
<a class="link" href="/user.php?id=<?php echo $usern ?>">
<?php echo $usern ?>
</a>
</b>
</div>
</div>
</div>
<div><b>Power</b>: <?php echo (int)($rr * 10) ?></div>
<div><b>Distribution</b>: <?php echo ($rr / $sum * 100) . "%" ?></div>
</div>
<?php }
}
get_handler();
?>
<?php
page_footer();
?>