Published
Edited
Apr 21, 2021
1 star
Insert cell
Insert cell
Insert cell
Insert cell
BN = await require('bignumber.js')
Insert cell
sc = await require("sourcecred@latest")
Insert cell
async function loadCredView(repo) {
const credResultFile = `https://raw.githubusercontent.com/${repo}/gh-pages/output/credResult.json`;
const credResultRaw = await (await fetch(credResultFile)).json()
const credResult = sc.analysis.credResult.fromJSON(credResultRaw)
const credView = new sc.analysis.credView.CredView(credResult)
return credView;
}
Insert cell
async function loadLedger(repo) {
const ledgerFile = `https://raw.githubusercontent.com/${repo}/gh-pages/data/ledger.json`;
const ledgerRaw = await (await fetch(ledgerFile)).text();
return sc.ledger.ledger.Ledger.parse(ledgerRaw);
}
Insert cell
ledger = loadLedger("sourcecred/cred")
Insert cell
G = sc.ledger.grain
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
distributions = {
const logs = ledger.eventLog();
return (
logs
//.filter(x => x.ledgerTimestamp < END_TS && x.ledgerTimestamp > START_TS)
.filter(x => x.action.type === "DISTRIBUTE_GRAIN")
);
}
Insert cell
lastDistribution = distributions[distributions.length - 1]
Insert cell
lastDistributionInput = Intl.DateTimeFormat(["se-SE"], {
dateStyle: "short"
}).format(
new Date(lastDistribution.action.distribution.credTimestamp + 86400000)
)
Insert cell
distributionPriorDayInput = Intl.DateTimeFormat(["se-SE"], {
dateStyle: "short"
}).format(new Date(lastDistribution.action.distribution.credTimestamp))
Insert cell
firstDistribution = distributions[distributions.length - 2]
Insert cell
firstDistributionInput = Intl.DateTimeFormat(["se-SE"], {
dateStyle: "short"
}).format(new Date(firstDistribution.action.distribution.credTimestamp))
Insert cell
readableLastDistributionTime = Intl.DateTimeFormat([], {
dateStyle: "full",
timeStyle: "short"
}).format(new Date(lastDistribution.ledgerTimestamp))
Insert cell
readableDistributionRange = Intl.DateTimeFormat([], {
dateStyle: "full"
}).format(new Date(lastDistribution.ledgerTimestamp))
Insert cell
ledger.accounts()
Insert cell
allocations = {
const allocs = [];
for (const { action } of distributions) {
const distribution = action.distribution;
for (const alloc of distribution.allocations) {
allocs.push(alloc);
}
}
return allocs;
}
Insert cell
participantList = ledger.accounts().map(a => a.identity.name)
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