Published
Edited
Sep 17, 2021
Insert cell
Insert cell
Insert cell
Insert cell
credTable = {
let wrapper = {};
const generate = nodeA => {
let node = edgeMapAndUpgradedNodes.upgradedNodes.get(
nodeModule.fromParts(JSON.parse(nodeA))
);
console.log(nodeA);
let totalIn = 0;
let input = inEdges(node).map(e => {
totalIn += e.incomingCred;
return rowFromEdge(e);
});
let totalOut = 0;
let output = outEdges(node).map(e => {
totalOut += e.incomingCred;
return rowFromEdge(e);
});
let currentNode = html`<table><tr><td>${
nodeModule.toParts(node.address)[0]
}</td><td>${
nodeModule.toParts(node.address)[1]
}</td><td>${formatDescription(node.description)}</td></tr></table>`;
const headers =
"<tr><th>Focus</th><th>Cred</th><th>Type</th><th>Subtype</th><th>Description</th></tr>";
const form = html`<form>
<style>table, th, td {
border: 1px solid black;
padding: 0px 5px 0px 5px;
}
input[type='checkbox'] {
-webkit-appearance:none;
width:20px;
height:20px;
background:white;
border-radius:1px;
border:2px solid #555;
}
input[type='checkbox']:checked {
background: #abd;
}</style>
<h2>Current node</h2>
${currentNode}
<h2>Incoming Cred</h2>
Total: ${totalIn.toFixed(2)}
<table>
${headers}
${input}
</table>
<br/><br/><br/>
<h2>Outgoing Cred</h2>
Total: ${totalOut.toFixed(2)}
<table>
${headers}
${output}
</table>
<br/>
</form>`;
form.oninput = e => (form.innerHTML = generate(e.target.value).innerHTML);
return form;
};
if (!participantNode) return html``;
return generate(JSON.stringify(nodeModule.toParts(participantNode.address)));
}
Insert cell
repoAndBranch = "sourcecred/cred/gh-pages"
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
//failing due to missing CORS headers??
//weightedGraph = loadWeightedGraph(repoAndBranch);
Insert cell
Insert cell
Insert cell
nodes = credGraph ? Array.from(credGraph.nodes()) : null
Insert cell
edges = credGraph ? Array.from(credGraph.edges()) : null
Insert cell
Insert cell
Insert cell
Insert cell
formatDescription = str =>
md`${str
// .replaceAll(/\[(.*)\](?<!\(http.*)\((\S*)\)/g, (a, b, c) => {
// console.log(c);
// return `<a href="${c}">${b}</a>`;
// })
.replaceAll('\n', ' ')
.replace(
/Participant epoch for (.*) starting (.*) ms past epoch/,
(a, b, c) => {
return `Participant Week for **${
ledger.account(b).identity.name
}** starting **${new Date(parseInt(c)).toDateString()}**`;
}
)
.replace(/Epoch accumulator starting (.*)/, (a, b) => {
return `Week Accumulator **(aka Cred Earned)** starting starting **${new Date(
parseInt(b)
).toDateString()}**`;
})
.replace(/^🌱$/, (a, b) => {
return `🌱 (aka Seed Node)`;
})}`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
rowFromEdge = e => {
const parts = nodeModule.toParts(e.node.address);
return html`<tr><td><input type="checkbox" value=${JSON.stringify(
parts
)}></td><td><strong>${e.incomingCred.toFixed(2)}</strong></td><td>${
parts[1]
}</td><td>${parts[2]}</td><td>${formatDescription(
e.node.description
)}</td></tr>\n`;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
nodeModule = sc.core.address.makeAddressModule({
name: "NodeAddress",
nonce: "N",
otherNonces: new Map().set("E", "EdgeAddress")
})
Insert cell
edgeModule = sc.core.address.makeAddressModule({
name: "EdgeAddress",
nonce: "E",
otherNonces: new Map().set("N", "NodeAddress"),
})
Insert cell
Insert cell
Insert cell
async function loadLedger(repoAndBranch) {
if (!repoAndBranch) return null;
const ledgerFile = `https://raw.githubusercontent.com/${repoAndBranch}/data/ledger.json`;
const ledgerRaw = await (await fetch(ledgerFile)).text();
try {
return sc.ledger.ledger.Ledger.parse(ledgerRaw);
} catch {
return null;
}
}
Insert cell
async function loadCredGraph(repoAndBranch) {
if (!repoAndBranch) return null;
const base = `https://raw.githubusercontent.com/${repoAndBranch}/`;
const instance = sc.instance.readInstance.getNetworkReadInstance(base);
try {
return instance.readCredGraph();
} catch (e) {
return e;
}
}
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more