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

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