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(); 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); } for ($i = 0; $i < 20; $i++) { foreach ($result as $usern) { $theuser = $usern['username']; $followers = $frs[$theuser]; foreach ($followers as $follown) { $fn = $follown['target']; if ($usern['username'] == $fn) continue; $dst = $fcount[$fn]; $pr[$usern['username']] += $pr[$fn] / ($dst + 10) / 10; } } $dist = 1 - ($i / 20); $dist = pow($dist,0.3); $new_sum = array_sum($pr); foreach ($result as $usern) { $h = $pr[$usern['username']]; $pr[$usern['username']] = (pow($h / $new_sum,1.1) * 100) * $dist + ($h * (1 - $dist)); } } $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) { ?>
Power: %