switch to NodeJS api

This commit is contained in:
biglyderv 2025-02-03 07:13:47 -05:00
parent 4562f56993
commit aaa6cb0845

View file

@ -13,110 +13,9 @@
page_header();
function get_handler() {
// this does a ton of weird matrix math
global $db;
$stmt = $db->prepare("SELECT * FROM main.auth");
$stmt->execute([]);
$result = $stmt->fetchAll(PDO::FETCH_DEFAULT);
$result = array_reverse($result,true);
$pr = array();
$fcount = array();
$frs = array();
$fng = array();
$matrixe = array();
$msum_old = 0;
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]);
$fng[$fn] = $stmt->fetchAll(PDO::FETCH_DEFAULT);
$fcount[$fn] = count($fng[$fn]);
$stmt = $db->prepare("SELECT * FROM main.follow WHERE username = ? AND NOT target = ?");
$stmt->execute([$fn,$fn]);
$frs[$fn] = $stmt->fetchAll(PDO::FETCH_DEFAULT);
$matrixe[$fn] = array();
$matrixe[$fn][$fn] = 1;
$msum_old++;
}
$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];
$msum_old += $matrixe[$usern['username']][$fn] = 1 + 1 / ($dst + 10) / 10;
}
}
for ($i = 0; $i < 10; $i++) {
$prold = $pr;
$matrixf = $matrixe;
$msum = 0;
foreach ($result as $usera) {
$una = $usera['username'];
$pr[$una] = 0;
if (count($frs[$una]) == 0) continue;
foreach ($result as $userb) {
$unb = $userb['username'];
$prb = $prold[$unb];
if ($prb < 1 / 1e3 || count($fng[$unb]) == 0) {
//$msum += $matrixe[$una][$unb];
continue;
}
$matrixe[$una][$unb] = 0.03;
foreach ($result as $userc) {
$unc = $userc['username'];
$matrixe[$una][$unb] += $matrixf[$una][$unc] * $matrixf[$unc][$unb];
}
$msum += $matrixe[$una][$unb];
$pr[$una] += $prb * $matrixe[$una][$unb];
}
}
foreach ($result as $usera) {
$una = $usera['username'];
if (count($frs[$una]) == 0) continue;
foreach ($result as $userb) {
$unb = $userb['username'];
$matrixe[$una][$unb] *= $msum_old / $msum;
}
}
$new_sum = array_sum($pr);
foreach ($result as $usern) {
$h = $pr[$usern['username']];
$pr[$usern['username']] /= $new_sum;
}
}
uasort($pr,'cmp');
$api = file_get_contents("https://nbg.dervland.net/node/top");
$pr = json_decode($api);
foreach ($pr as $usern => $rr) { ?>
<div class='comment'>
<div class="avatar">
@ -130,7 +29,7 @@
</div>
</div>
</div>
<div><b>Power</b>: <?php echo $rr * 100 ?>%</div>
<div><b>Power</b>: <?php echo $rr ?></div>
</div>
<?php }
}