better calculations

This commit is contained in:
onezplpl 2024-08-04 18:04:17 -04:00
parent 4beeb3cbf3
commit c79764b523
No known key found for this signature in database
GPG key ID: 7EC026A136F9EEC3

View file

@ -3,19 +3,24 @@ let entries = [];
let users = {}; let users = {};
let fetchData; let fetchData;
let sum = 0;
async function genTree(treeId) { async function genTree(treeId) {
let entry = treeId;
entries.push(treeId) while (true) {
let entry = fetchData[treeId];
while (entry) {
entry = entry.parent_id;
entries.push(entry);
let entryDat = fetchData[entry]; let entryDat = fetchData[entry];
if (!entryDat) continue; if (!entryDat) break;
entries.push(entry);
let us = users[entryDat.username]; let us = users[entryDat.username];
users[entryDat.username] = (us ? us : 0) + 1 / entries.length;
entry = entryDat; let s = 1 / (entries.length+10);
sum += s;
users[entryDat.username] = (us ? us : 0) + s;
entry = entryDat.parent_id;
} }
return entry; return entry;
@ -39,7 +44,7 @@ async function main() {
doThings = true; doThings = true;
document.querySelector('.contributors').innerHTML = Object.keys(users) document.querySelector('.contributors').innerHTML = Object.keys(users)
.sort((x, y) => users[y] - users[x]) .sort((x, y) => users[y] - users[x])
.map(x => `<a href='https://scratch.mit.edu/users/${x}'>${x}</a> <sub>${Math.trunc(users[x] / Math.log(entries.length) * 100000) / 1000}%</sub>`) .map(x => `<a href='https://scratch.mit.edu/users/${x}'>${x}</a> <sub>${Math.trunc(users[x] / sum * 100000) / 1000}%</sub>`)
.join(', '); // Doesn't need to be sanitized (hopefully) .join(', '); // Doesn't need to be sanitized (hopefully)
} }