Published
Edited
Dec 3, 2021
2 forks
Insert cell
Insert cell
Insert cell
grainConfig1 = ({
// set the current values in the instance https://github.com/sourcecred/cred/blob/master/config/grain.json
allocationPolicies: [
{
policyType: "BALANCED",
budget: G.fromInteger(5000),
numIntervalsLookback: 0
},
{
policyType: "RECENT",
budget: G.fromInteger(20000),
discount: 0.16,
exclusions: []
}
],
maxSimultaneousDistributions: 1
})
Insert cell
grainConfig2 = ({
allocationPolicies: [
{
policyType: "BALANCED",
budget: G.fromInteger(5000),
numIntervalsLookback: 0
},
{
policyType: "RECENT",
budget: G.fromInteger(20000),
discount: 0.16,
exclusions: []
}
],
maxSimultaneousDistributions: 1
})
Insert cell
ignoreAccountsBelow = 5
Insert cell
Insert cell
Insert cell
md`<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
# Behind the Scenes`
Insert cell
diff = (grain1, grain2) => {
return (
((G.toFloatRatio(grain2, G.ONE) - G.toFloatRatio(grain1, G.ONE)) /
G.toFloatRatio(grain1, G.ONE)) *
100
);
}
Insert cell
currencyDetails = ({ name: "Grain", suffix: " g", decimals: 2 })
Insert cell
flatEarnings1 = {
const map = new Map();
grainOutput1.distributions.forEach(x => {
x.allocations.forEach(a => {
a.receipts.forEach(r => {
const name = ledger.account(r.id).identity.name;
map.set(name, G.add(map.get(name) || G.ZERO, r.amount));
});
});
});
return map;
}
Insert cell
flatEarnings2 = {
const map = new Map();
grainOutput2.distributions.forEach(x => {
x.allocations.forEach(a => {
a.receipts.forEach(r => {
const name = ledger.account(r.id).identity.name;
map.set(name, G.add(map.get(name) || G.ZERO, r.amount));
});
});
});
return map;
}
Insert cell
G = sc.ledger.grain
Insert cell
grainOutput1 = sc.api.grain.grain({
credGraph,
ledger: sc.ledger.ledger.Ledger.fromEventLog(ledger.eventLog()),
grainConfig: grainConfig1,
currencyDetails,
allowMultipleDistributionsPerInterval: true
})
Insert cell
grainOutput2 = sc.api.grain.grain({
credGraph,
ledger: sc.ledger.ledger.Ledger.fromEventLog(ledger.eventLog()),
grainConfig: grainConfig2,
currencyDetails,
allowMultipleDistributionsPerInterval: true
})
Insert cell
import {
// Our Instance Data
credGraph, // The real CredGraph from "sourcecred/cred/gh-pages"
ledger, // The real Ledger from "sourcecred/cred/gh-pages"
// Instance Data Getters
loadLedger, // Function for getting a ledger using a repo/branch string
loadCredGraph, // Function for getting a ledger using a repo/branch string
// Libraries
sc, // The SourceCred API Library
// Input Modules. Example usage: viewof repoAndBranch = html`${repoAndBranchInput}`
repoAndBranchInput // A URL query string parser and input box combo for user-provided repo/branch string
} from "@sourcecred/quick-imports"
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