150 lines
3.2 KiB
PHP
Executable file
150 lines
3.2 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();
|
|
$fcount = array();
|
|
$frs = array();
|
|
$matrixe = array();
|
|
|
|
foreach ($result as $usern) {
|
|
$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));
|
|
|
|
$stmt = $db->prepare("SELECT * FROM main.follow WHERE username = ?");
|
|
$stmt->execute([$fn]);
|
|
|
|
$frs[$fn] = $stmt->fetchAll(PDO::FETCH_DEFAULT);
|
|
|
|
$matrixe[$fn] = array();
|
|
$matrixe[$fn][$fn] = 1;
|
|
}
|
|
|
|
$ch = 0;
|
|
foreach ($result as $usern) {
|
|
$theuser = $usern['username'];
|
|
|
|
$followers = $frs[$theuser];
|
|
|
|
if (count($followers) > 0) {
|
|
$ch++;
|
|
}
|
|
|
|
foreach ($followers as $follown) {
|
|
$fn = $follown['target'];
|
|
|
|
if ($usern['username'] == $fn) continue;
|
|
$dst = $fcount[$fn];
|
|
|
|
$matrixe[$usern['username']][$fn] = 1 + 1 / ($dst + 10) / 10;
|
|
|
|
///$pr[$usern['username']] += $pr[$fn] / ($dst + 10) / 10;
|
|
}
|
|
}
|
|
|
|
$msum = 1;
|
|
for ($i = 0; $i < 10; $i++) {
|
|
$prold = $pr;
|
|
$matrixf = $matrixe;
|
|
$msum_old = $msum;
|
|
$msum = 1;
|
|
|
|
$chh = 0;
|
|
foreach ($result as $usera) {
|
|
$una = $usera['username'];
|
|
if (count($frs[$una]) == 0) continue;
|
|
foreach ($result as $userb) {
|
|
$unb = $userb['username'];
|
|
$prb = $prold[$unb];
|
|
if ($prb < pow(0.1,1 - ($i / 50))) {
|
|
continue;
|
|
}
|
|
$chh += $ch;
|
|
}
|
|
}
|
|
|
|
foreach ($result as $usera) {
|
|
$una = $usera['username'];
|
|
$pr[$una] = 0.1;
|
|
if (count($frs[$una]) == 0) continue;
|
|
|
|
foreach ($result as $userb) {
|
|
$unb = $userb['username'];
|
|
$prb = $prold[$unb];
|
|
if ($prb < pow(0.1,1 - ($i / 50))) {
|
|
continue;
|
|
}
|
|
$matrixe[$una][$unb] = 0;
|
|
|
|
foreach ($result as $userc) {
|
|
$unc = $userc['username'];
|
|
$matrixe[$una][$unb] += $matrixf[$una][$unc] * $matrixf[$unc][$unb] / $msum_old * $chh;
|
|
}
|
|
|
|
$msum += $matrixe[$una][$unb];
|
|
$pr[$una] += $prb * $matrixe[$una][$unb];
|
|
}
|
|
}
|
|
|
|
$new_sum = array_sum($pr);
|
|
foreach ($result as $usern) {
|
|
$h = $pr[$usern['username']];
|
|
$pr[$usern['username']] /= $new_sum;
|
|
}
|
|
}
|
|
|
|
|
|
$new_sum = array_sum($pr);
|
|
foreach ($result as $usern) {
|
|
$pr[$usern['username']] = $pr[$usern['username']] * 100 / $new_sum;
|
|
}
|
|
|
|
function cmp($a, $b) {
|
|
if ($a == $b) {
|
|
return 0;
|
|
}
|
|
return ($a > $b) ? -1 : 1;
|
|
}
|
|
|
|
uasort($pr,'cmp');
|
|
|
|
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 $rr ?>%</div>
|
|
</div>
|
|
<?php }
|
|
}
|
|
|
|
get_handler();
|
|
?>
|
|
|
|
<?php
|
|
page_footer();
|
|
?>
|