Published
Edited
Feb 4, 2022
1 fork
Importers
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
G = sc.ledger.grain
Insert cell
Insert cell
scVersions = [
await require("sourcecred@latest"),
await require("sourcecred@0.9.3"),
await require("sourcecred@0.8.5")
]
Insert cell
Insert cell
Insert cell
Insert cell
md`# Output Modules`
Insert cell
buildCsvDownload = (array, name = "ObservableCsv", header = true) => {
function serialize(data) {
let parser = new json2csv.Parser({ header });
let csv = parser.parse(data);
return new Blob([csv], { type: "text/csv" });
}
return DOM.download(serialize(array), name, "Download " + name + ".csv");
}
Insert cell
credGrainViewCredTable = (credGrainView, minCred = 0, weeksLookBack = 0) => {
let cgv = credGrainView;
const two = cgv
.withTimeScopeFromLookback(Date.now(), 2)
.participants()
.slice()
.sort((a, b) => b.cred - a.cred);
const four = cgv
.withTimeScopeFromLookback(Date.now(), 4)
.participants()
.slice()
.sort((a, b) => b.cred - a.cred);
if (weeksLookBack)
cgv = cgv.withTimeScopeFromLookback(Date.now(), weeksLookBack);
const table = cgv
.participants()
.slice()
.filter((p) => p.cred > minCred)
.sort((a, b) => b.cred - a.cred)
.map(
(p, index) =>
`|${p.identity.name}` +
`|${p.cred.toFixed(0)}` +
`|` +
`|${two[index].identity.name}` +
`|${two[index].cred.toFixed(0)}` +
`|` +
`|${four[index].identity.name}` +
`|${four[index].cred.toFixed(0)}|`
);
return md`|Total|Cred|-|Last 2 weeks||-| Last 4 weeks ||\n|---|---|---|---|---|---|---|\n${table.join(
"\n"
)}`;
}
Insert cell
credGrainViewCredTable(credGrainView)
Insert cell
md`# Misc.`
Insert cell
spacer = () => html`<br><br><br><br><br><br><br><br><br><br>`
Insert cell
nodeModule = sc.core.address.makeAddressModule({
name: "NodeAddress",
nonce: "N",
otherNonces: new Map().set("E", "EdgeAddress")
})
Insert cell
edgeModule = sc.core.address.makeAddressModule({
name: "EdgeAddress",
nonce: "E",
otherNonces: new Map().set("N", "NodeAddress")
})
Insert cell
Insert cell
json2csv = require("json2csv")
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