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

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