Published
Edited
Apr 26, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
credData = {
if (!credGraph) return;
const intervals = credGraph
.intervals()
.map(i => new Date(i.startTimeMs).toDateString())
.reverse();
return Array.from(credGraph.participants())
.map(p => {
const result = {
id: p.id,
name: p.description,
totalCred: p.cred
};
p.credPerInterval
.reverse()
.forEach((c, i) => (result[intervals[i]] = c.toFixed(4)));
return result;
})
.sort((a, b) => b.totalCred - a.totalCred);
}
Insert cell
grainData = {
if (!ledger || !credGraph) return;
const intervals = credGraph
.intervals()
.map(i => new Date(i.endTimeMs).toDateString())
.reverse();
return ledger
.accounts()
.map(a => {
const result = {
id: a.identity.id,
name: a.identity.name,
totalGrainPaid: a.paid / 1000000000000000000
};
const gpi = _calculateGrainEarnedPerInterval(a, credGraph.intervals())
.reverse()
.forEach((g, i) => (result[intervals[i]] = g / 1000000000000000000));
return result;
})
.sort((a, b) => b.totalGrainPaid - a.totalGrainPaid);
}
Insert cell
_calculateGrainEarnedPerInterval = (account, intervals) => {
let allocationIndex = 0;
return intervals.map(interval => {
let grain = sc.ledger.grain.ZERO;
while (
account.allocationHistory.length - 1 >= allocationIndex &&
interval.startTimeMs <
account.allocationHistory[allocationIndex].credTimestampMs &&
account.allocationHistory[allocationIndex].credTimestampMs <=
interval.endTimeMs
) {
grain = sc.ledger.grain.add(
grain,
account.allocationHistory[allocationIndex].grainReceipt.amount
);
allocationIndex++;
}
return grain;
});
}
Insert cell
import { serialize } from "@palewire/saving-csv"
Insert cell
Insert cell
//failing due to missing CORS headers??
//weightedGraph = loadWeightedGraph(repoAndBranch);
Insert cell
credGraph = loadCredGraph(repoAndBranch)
Insert cell
ledger = loadLedger(repoAndBranch)
Insert cell
Insert cell
Insert cell
Insert cell
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