diff --git a/js/app.js b/js/app.js index 8582baf..c2dd604 100644 --- a/js/app.js +++ b/js/app.js @@ -3,19 +3,24 @@ let entries = []; let users = {}; let fetchData; + +let sum = 0; + async function genTree(treeId) { + let entry = treeId; - entries.push(treeId) - let entry = fetchData[treeId]; - - while (entry) { - entry = entry.parent_id; - entries.push(entry); + while (true) { let entryDat = fetchData[entry]; - if (!entryDat) continue; + if (!entryDat) break; + + entries.push(entry); + 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; @@ -39,7 +44,7 @@ async function main() { doThings = true; document.querySelector('.contributors').innerHTML = Object.keys(users) .sort((x, y) => users[y] - users[x]) - .map(x => `${x} ${Math.trunc(users[x] / Math.log(entries.length) * 100000) / 1000}%`) + .map(x => `${x} ${Math.trunc(users[x] / sum * 100000) / 1000}%`) .join(', '); // Doesn't need to be sanitized (hopefully) }