test on darflen data
This commit is contained in:
parent
48b59c5493
commit
c120d5e0f1
2 changed files with 47 additions and 22 deletions
3
package.json
Normal file
3
package.json
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"type": "module"
|
||||||
|
}
|
66
rank.js
66
rank.js
|
@ -1,22 +1,24 @@
|
||||||
|
import { writeFile } from "fs/promises";
|
||||||
|
|
||||||
// derived from https://git.dervland.net/biglyderv/new-bigly-chat/src/branch/master/docs/stats.php
|
// derived from https://git.dervland.net/biglyderv/new-bigly-chat/src/branch/master/docs/stats.php
|
||||||
function rankCalc(result, iterations = 10) {
|
function rankCalc(result, iterations = 10) {
|
||||||
let matrixe = {}
|
let matrixe = {}
|
||||||
let fng = {};
|
let fng = {};
|
||||||
let fnc ={};
|
let fnc = {};
|
||||||
let frs = {};
|
let frs = {};
|
||||||
let msum_old = 0;
|
let msum_old = 0;
|
||||||
let pr = {};
|
let pr = {};
|
||||||
|
|
||||||
for (let unn in result) {
|
for (let unn in result) {
|
||||||
matrixe[unn] = {};
|
matrixe[unn] = {};
|
||||||
matrixe[unn][unn] =1;
|
matrixe[unn][unn] = 1;
|
||||||
frs[unn] = result[unn].followers;
|
frs[unn] = result[unn].followers;
|
||||||
fng[unn] = result[unn].following;
|
fng[unn] = result[unn].following;
|
||||||
fnc[unn] = fng[unn].length;
|
fnc[unn] = fng[unn].length;
|
||||||
pr[unn] = 1;
|
pr[unn] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let unn in result ) {
|
for (let unn in result) {
|
||||||
let fnu = frs[unn];
|
let fnu = frs[unn];
|
||||||
for (let follow of fnu) {
|
for (let follow of fnu) {
|
||||||
if (follow == unn) continue;
|
if (follow == unn) continue;
|
||||||
|
@ -31,7 +33,7 @@ function rankCalc(result, iterations = 10) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (let i = 0; i < iterations; i++) {
|
for (let i = 0; i < iterations; i++) {
|
||||||
let prold = structuredClone(pr);
|
let prold = structuredClone(pr);
|
||||||
let matrixf = structuredClone(matrixe);
|
let matrixf = structuredClone(matrixe);
|
||||||
|
@ -43,7 +45,7 @@ function rankCalc(result, iterations = 10) {
|
||||||
|
|
||||||
for (let unb in result) {
|
for (let unb in result) {
|
||||||
prb = prold[unb];
|
prb = prold[unb];
|
||||||
if (prb < 1 / 1e6 || Object.keys(fng[unb]).length == 0) {
|
if (prb < 1 / 1e4 || Object.keys(fng[unb]).length == 0) {
|
||||||
//msum += matrixe[una][unb];
|
//msum += matrixe[una][unb];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -56,8 +58,6 @@ function rankCalc(result, iterations = 10) {
|
||||||
|
|
||||||
msum += matrixe[una][unb];
|
msum += matrixe[una][unb];
|
||||||
pr[una] += prb * matrixe[una][unb];
|
pr[una] += prb * matrixe[una][unb];
|
||||||
|
|
||||||
console.log(msum_old)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,31 +70,53 @@ function rankCalc(result, iterations = 10) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new_sum = Object.values(pr).reduce((a,b) => a+b, 0)
|
new_sum = Object.values(pr).reduce((a, b) => a + b, 0)
|
||||||
|
|
||||||
for (let unn in result) {
|
for (let unn in result) {
|
||||||
h = pr[unn];
|
h = pr[unn];
|
||||||
pr[unn] /= new_sum;
|
pr[unn] /= new_sum;
|
||||||
}
|
}
|
||||||
|
console.log(`Iteration ${i} calculated`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pr;
|
return pr;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(rankCalc({
|
(async function () {
|
||||||
'david': {
|
let users = [];
|
||||||
'following': [],
|
|
||||||
'followers': ['davis','david','bob']
|
|
||||||
},
|
|
||||||
|
|
||||||
'bob': {
|
let i = 0;
|
||||||
'following': ['davis','david','bob'],
|
|
||||||
'followers': ['davis','david','bob']
|
|
||||||
},
|
|
||||||
|
|
||||||
'davis': {
|
while (true) {
|
||||||
'following': ['davis','david','bob'],
|
let h1 = await fetch(`https://api.darflen.com/users/paradock/followers/${i}`)
|
||||||
'followers': ['davis','david','bob']
|
let j1 = await h1.json();
|
||||||
|
|
||||||
|
let users2 = j1.followers.map(x => x.profile.username);
|
||||||
|
|
||||||
|
users = [...users, ...users2];
|
||||||
|
|
||||||
|
if (users2.length == 0) break;
|
||||||
|
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
},100));
|
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);
|
||||||
|
writeFile(`./users.json`,'utf8',srz);
|
||||||
|
})()
|
||||||
|
|
Loading…
Reference in a new issue