Published
Edited
Jan 26, 2021
1 fork
Insert cell
md `# Deprecated in favor of [this fork](https://observablehq.com/@sourcecred/the-definititive-sourcecred-observable-first-edition)`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// TODO credGraph
Insert cell
//failing due to missing CORS headers??
//weightedGraph = loadWeightedGraph(repoAndBranch);
Insert cell
Insert cell
Insert cell
// Get started here!
Insert cell
Insert cell
Insert cell
genericBoxInput = {return {"wow": "so generic"}}
Insert cell
Insert cell
Insert cell
ledgerViewerInput = humanReadableLedgerLog
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
humanReadableLedgerLog = JSON.parse(JSON.stringify(truncatedLedgerLog)).map(event => {
if (event.action.type === "TRANSFER_GRAIN") {
event.action.from = getAccountName(event.action.from);
event.action.to = getAccountName(event.action.to);
event.action.amount = g(event.action.amount);
}
if (event.action.type === "TOGGLE_ACTIVATION") {
event.action.identityId = getAccountName(event.action.identityId);
}
if (event.action.type === "MERGE_IDENTITIES") {
event.action.base = getAccountName(event.action.base);
}
if (event.action.type === "DISTRIBUTE_GRAIN") {
if (event.action.distribution) {
event.action.distribution.allocations.forEach(allocation => {
allocation.policy.budget = g(allocation.policy.budget);
allocation.receipts.sort((a, b) => BigInt(a.amount) < BigInt(b.amount) ? 1 : -1);
allocation.receipts.forEach(receipt => {
receipt.id = getAccountName(receipt.id);
receipt.amount = g(receipt.amount);
});
});
}
}
event.ledgerTimestamp = new Date(event.ledgerTimestamp).toLocaleString("en", {
month: "numeric",
day: "numeric",
hour: "numeric",
minute: "numeric",
year: "2-digit",
});
return event;
})
Insert cell
truncatedLedgerLog = ledger ? ledger.eventLog().slice(-100).reverse() : []
Insert cell
repoAndBranch = {
if (branchUrl && branchUrl.length > 0) {
const match = branchUrl.match(/.*github\.com\/(.*)tree\/(.*)(\/?)/);
if (match) return match[1] + match[2];
}
if (location.search.includes("?branchUrl=")) {
const match = location.search.match(/.*github\.com\/(.*)tree\/(.*)(\/?)/);
if (match) return match[1] + match[2];
}
if (location.search.includes("?repoAndBranch=")) {
const match = location.search.match(/\\?repoAndBranch=(.*)/);
if (match) if (match) match[1];
}
return null;
}
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 loadCredResult(repoAndBranch) {
if (!repoAndBranch) return null;
const file = `https://raw.githubusercontent.com/${repoAndBranch}/output/credResult.json`
const raw = await (await fetch(file)).text();
try {
return sc.analysis.credResult.fromJSON(JSON.parse(raw));
} catch {
return null;
}
}
Insert cell
async function loadWeightedGraph(repoAndBranch) {
if (!repoAndBranch) return null;
const weightedGraphs = [];
let raw = null;
try {
for (const file in weightedGraphFiles) {
raw = await fetch(file);
raw = await (raw).text();
weightedGraphs.push(sc.core.weightedGraph.fromJSON(JSON.parse(raw)));
}
return sc.core.weightedGraph.merge(weightedGraphs);
} catch (e) {
throw `${e}: ${weightedGraphFiles[weightedGraphs.length]} -- ${raw}`
}
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more