bigly-chat/docs/stats.php

157 lines
3.4 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-28 20:36:01 -05:00
$msum_old = 0;
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-28 20:36:01 -05:00
$msum_old++;
2025-01-23 20:00:36 -05:00
}
2025-01-28 18:53:38 -05:00
$ch = 0;
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:53:38 -05:00
if (count($followers) > 0) {
$ch++;
}
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 20:36:01 -05:00
$msum_old += $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 20:11:54 -05:00
for ($i = 0; $i < 10; $i++) {
2025-01-28 18:07:44 -05:00
$prold = $pr;
$matrixf = $matrixe;
2025-01-28 20:36:01 -05:00
$msum = 0;
2025-01-28 18:53:38 -05:00
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: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'];
2025-01-28 20:00:57 -05:00
$prb = $prold[$unb];
2025-01-28 20:37:44 -05:00
if ($prb < 1 /1e6) {
2025-01-28 20:00:57 -05:00
continue;
}
2025-01-28 20:10:24 -05:00
}
}
2025-01-28 20:00:57 -05:00
2025-01-28 20:10:24 -05:00
foreach ($result as $usera) {
$una = $usera['username'];
2025-01-28 20:15:01 -05:00
$pr[$una] = 0.1;
2025-01-28 20:10:24 -05:00
if (count($frs[$una]) == 0) continue;
foreach ($result as $userb) {
$unb = $userb['username'];
$prb = $prold[$unb];
2025-01-28 20:14:25 -05:00
if ($prb < 1 / 1e6) {
2025-01-28 20:16:20 -05:00
$msum += $matrixe[$una][$unb];
2025-01-28 20:10:24 -05:00
continue;
}
$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 20:36:01 -05:00
$matrixe[$una][$unb] += $matrixf[$una][$unc] * $matrixf[$unc][$unb];
2025-01-28 18:07:44 -05:00
}
2025-01-28 20:10:24 -05:00
2025-01-28 18:43:53 -05:00
$msum += $matrixe[$una][$unb];
2025-01-28 20:00:57 -05:00
$pr[$una] += $prb * $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-28 20:36:01 -05:00
foreach ($result as $usera) {
$una = $usera['username'];
foreach ($result as $userb) {
$unb = $userb['username'];
$matrixe[$una][$unb] *= $msum_old / $msum;
}
}
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 20:10:24 -05:00
$pr[$usern['username']] /= $new_sum;
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();
?>