bigly-chat/docs/stats.php

125 lines
2.8 KiB
PHP
Raw Normal View History

2025-01-23 20:00:36 -05:00
<?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();
2025-01-27 17:32:35 -05:00
$fcount = array();
2025-01-27 18:09:40 -05:00
$frs = array();
2025-01-28 18:07:44 -05:00
$matrixe = array();
2025-01-27 18:09:40 -05:00
2025-01-23 20:00:36 -05:00
foreach ($result as $usern) {
2025-01-27 17:32:35 -05:00
$fn = $usern['username'];
$pr[$fn] = 1;
$stmt = $db->prepare("SELECT * FROM main.follow WHERE target = ? AND NOT username = ?");
$stmt->execute([$fn,$fn]);
$fcount[$fn] = count($stmt->fetchAll(PDO::FETCH_DEFAULT));
2025-01-27 18:09:40 -05:00
$stmt = $db->prepare("SELECT * FROM main.follow WHERE username = ?");
$stmt->execute([$fn]);
$frs[$fn] = $stmt->fetchAll(PDO::FETCH_DEFAULT);
2025-01-28 18:07:44 -05:00
$matrixe[$fn] = array();
$matrixe[$fn][$fn] = 1;
2025-01-23 20:00:36 -05:00
}
2025-01-28 18:07:44 -05:00
foreach ($result as $usern) {
$theuser = $usern['username'];
2025-01-28 18:33:16 -05:00
$followers = $frs[$theuser];
2025-01-28 18:07:44 -05:00
foreach ($followers as $follown) {
$fn = $follown['target'];
2025-01-28 18:07:44 -05:00
if ($usern['username'] == $fn) continue;
$dst = $fcount[$fn];
2025-01-28 18:07:44 -05:00
$matrixe[$usern['username']][$fn] = 1 + 1 / ($dst + 10) / 10;
2025-01-28 18:07:44 -05:00
///$pr[$usern['username']] += $pr[$fn] / ($dst + 10) / 10;
}
}
2025-01-28 18:43:53 -05:00
$msum = 1;
2025-01-28 18:07:44 -05:00
2025-01-28 18:24:26 -05:00
for ($i = 0; $i < 4; $i++) {
2025-01-28 18:07:44 -05:00
$prold = $pr;
$matrixf = $matrixe;
2025-01-28 18:43:53 -05:00
$msum_old = $msum;
$msum = 1;
2025-01-28 18:07:44 -05:00
foreach ($result as $usera) {
2025-01-28 18:24:26 -05:00
$una = $usera['username'];
2025-01-28 18:49:49 -05:00
$pr[$una] = 0;
2025-01-28 18:33:16 -05:00
if (count($frs[$una]) == 0) continue;
2025-01-28 18:07:44 -05:00
foreach ($result as $userb) {
2025-01-28 18:24:26 -05:00
$unb = $userb['username'];
$matrixe[$una][$unb] = 0;
2025-01-28 18:07:44 -05:00
foreach ($result as $userc) {
2025-01-28 18:24:26 -05:00
$unc = $userc['username'];
2025-01-28 18:49:49 -05:00
$matrixe[$una][$unb] += 0.1 + $matrixf[$una][$unc] * $matrixf[$unc][$unb] / $msum_old * pow(count($result),3);
2025-01-28 18:07:44 -05:00
}
2025-01-28 18:43:53 -05:00
$msum += $matrixe[$una][$unb];
2025-01-28 18:24:26 -05:00
$pr[$una] += $prold[$unb] * $matrixe[$una][$unb];
2025-01-23 20:00:36 -05:00
}
2025-01-25 09:57:59 -05:00
}
2025-01-24 02:52:28 -05:00
2025-01-25 09:57:59 -05:00
$new_sum = array_sum($pr);
foreach ($result as $usern) {
2025-01-25 10:17:16 -05:00
$h = $pr[$usern['username']];
2025-01-28 18:41:46 -05:00
$pr[$usern['username']] /= $new_sum / 100;
2025-01-24 02:52:28 -05:00
}
2025-01-23 20:00:36 -05:00
}
2025-01-23 20:04:50 -05:00
2025-01-25 10:14:32 -05:00
$new_sum = array_sum($pr);
foreach ($result as $usern) {
2025-01-27 17:08:30 -05:00
$pr[$usern['username']] = $pr[$usern['username']] * 100 / $new_sum;
2025-01-25 10:14:32 -05:00
}
2025-01-23 20:04:50 -05:00
function cmp($a, $b) {
if ($a == $b) {
return 0;
}
return ($a > $b) ? -1 : 1;
}
uasort($pr,'cmp');
foreach ($pr as $usern => $rr) { ?>
2025-01-23 20:00:36 -05:00
<div class='comment'>
2025-01-24 02:52:28 -05:00
<div class="avatar">
<img src="/pfp/<?php echo $usern ?>.png" class="avatar-img">
<div>
<div><b>
2025-01-24 02:53:22 -05:00
<a class="link" href="/user.php?id=<?php echo $usern ?>">
2025-01-24 02:52:28 -05:00
<?php echo $usern ?>
</a>
</b>
</div>
</div>
</div>
2025-01-27 17:08:30 -05:00
<div><b>Power</b>: <?php echo $rr ?>%</div>
2025-01-23 20:00:36 -05:00
</div>
<?php }
}
get_handler();
?>
<?php
page_footer();
?>