This commit is contained in:
biglyderv 2025-01-30 07:59:30 -05:00
parent bb09cb9258
commit a705ec79df
2 changed files with 68 additions and 44 deletions

55
darflen.js Normal file
View file

@ -0,0 +1,55 @@
import { writeFile } from "fs/promises";
import { rankCalc } from "./rank.js";
(async function () {
let users = [];
let i = 0;
while (true) {
let h1 = await fetch(`https://api.darflen.com/users/paradock/followers/${i}`)
let j1 = await h1.json();
let users2 = j1.followers.map(x => x.profile.username);
users = [...users, ...users2];
if (users2.length == 0) break;
i++;
}
let data = {};
let p = [];
for (let u of users) {
if (p.length >= 10) {
await Promise.all(p);
p = [];
}
p.push((async function () {
let h1 = await fetch(`https://api.darflen.com/users/${u}/followers`)
let j1 = await h1.json();
let h2 = await fetch(`https://api.darflen.com/users/${u}/following`)
let j2 = await h2.json();
data[u] = {
followers: j1.followers.map(x => x.profile.username),
following: j2.following.map(x => x.profile.username)
}
console.log(`User ${u} calculated`);
})())
}
await Promise.all(p);
let dat = Object.entries(rankCalc(data, 100));
dat = dat.sort((a, b) => a[1] - b[1]);
let dat2 = {};
for (let d of dat) {
dat2[d[0]] = d[1] * 100 + "%";
}
let srz = JSON.stringify(dat2);
await writeFile(`./users.json`, srz, 'utf8');
})()

57
rank.js
View file

@ -1,4 +1,3 @@
import { writeFile } from "fs/promises";
// derived from https://git.dervland.net/biglyderv/new-bigly-chat/src/branch/master/docs/stats.php
function rankCalc(result, iterations = 10) {
@ -14,7 +13,7 @@ function rankCalc(result, iterations = 10) {
matrixe[unn][unn] = 1;
frs[unn] = result[unn].followers;
fng[unn] = result[unn].following;
fnc[unn] = fng[unn].length;
fnc[unn] = Object.keys(fng[unn]).length;
pr[unn] = 1;
}
@ -35,29 +34,32 @@ function rankCalc(result, iterations = 10) {
for (let i = 0; i < iterations; i++) {
let prold = structuredClone(pr);
let matrixf = structuredClone(matrixe);
let prold = pr;
let matrixf = matrixe;
pr = [];
matrixe = [];
let msum = 1;
for (let una in result) {
pr[una] = 0;
matrixe[una] = [];
if (frs[una].length == 0) continue;
for (let unb in result) {
let prb = prold[unb];
if (prb < 1 / 1e4 || Object.keys(fng[unb]).length == 0) {
if (prb < 1 / 1e4 || fnc[unb] == 0) {
//msum += matrixe[una][unb];
continue;
}
matrixe[una][unb] = 0.03;
for (let unc in result) {
matrixe[una][unb] += matrixf[una][unc] * matrixf[unc][unb];
}
msum += matrixe[una][unb];
pr[una] += prb * matrixe[una][unb];
pr[una] += prb * msum;
}
}
@ -75,6 +77,7 @@ function rankCalc(result, iterations = 10) {
for (let unn in result) {
pr[unn] /= new_sum;
}
console.log(`Iteration ${i} calculated`);
}
@ -82,40 +85,6 @@ function rankCalc(result, iterations = 10) {
}
(async function () {
let users = [];
let i = 0;
while (true) {
let h1 = await fetch(`https://api.darflen.com/users/paradock/followers/${i}`)
let j1 = await h1.json();
let users2 = j1.followers.map(x => x.profile.username);
users = [...users, ...users2];
if (users2.length == 0) break;
i++;
}
let data = {};
for (let u of users) {
let h1 = await fetch(`https://api.darflen.com/users/${u}/followers`)
let j1 = await h1.json();
let h2 = await fetch(`https://api.darflen.com/users/${u}/following`)
let j2 = await h2.json();
data[u] = {
followers: j1.followers.map(x => x.profile.username),
following: j2.following.map(x => x.profile.username)
}
console.log(`User ${u} calculated`);
}
let dat = Object.entries(rankCalc(data, 100));
dat = dat.sort((a, b) => a[1] - b[1])
let srz = JSON.stringify(dat);
await writeFile(`./users.json`,srz,'utf8');
})()
export {
rankCalc
}