Published
Edited
Apr 12, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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
// 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
md`### CSV Download`
Insert cell
Insert cell
genericBoxInput
? DOM.download(
serialize(genericBoxInput),
"Output_" + repoAndBranch,
"Download CSV"
)
: md``
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) return 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 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
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

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