Platform
Resources
Pricing
Sign in
Get started
sourcecred
Workspace
Fork
Published
By
Dandelion Mané
Edited
Jun 29, 2021
GNU GPLv3
Fork of
Participant Grain Earnings Calculator
Insert cell
Insert cell
DOM
.
download
(
serialize
(
processedRedemptions
)
,
"redemptions.csv"
,
"Download Redemption Data"
)
Insert cell
DOM
.
download
(
serialize
(
processedDistributions
)
,
"distributions.csv"
,
"Download Distribution Data"
)
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
transfers
=
{
const
logs
=
ledger
.
eventLog
(
)
;
return
(
logs
//.filter(x => x.ledgerTimestamp < END_TS && x.ledgerTimestamp > START_TS)
.
filter
(
(
x
)
=>
x
.
action
.
type
===
"TRANSFER_GRAIN"
)
)
;
}
Insert cell
redemptions
=
transfers
.
filter
(
(
x
)
=>
x
.
action
.
to
===
sourcecredId
||
(
x
.
action
.
to
===
protocolId
&&
x
.
action
.
from
!==
sourcecredId
)
)
Insert cell
processedRedemptions
=
redemptions
.
map
(
(
x
)
=>
(
{
timestamp
:
x
.
ledgerTimestamp
,
date
:
new
Date
(
x
.
ledgerTimestamp
)
,
amount
:
G
.
format
(
x
.
action
.
amount
,
2
,
""
)
,
redeemer
:
idToName
.
get
(
x
.
action
.
from
)
,
buyer
:
idToName
.
get
(
x
.
action
.
to
)
}
)
)
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
participantDistributions
=
{
const
results
=
[
]
;
for
(
const
{
action
,
ledgerTimestamp
}
of
distributions
)
{
for
(
const
{
receipts
}
of
action
.
distribution
.
allocations
)
{
for
(
const
{
id
,
amount
}
of
receipts
)
{
if
(
amount
===
"0"
)
continue
;
results
.
push
(
{
id
,
amount
,
ledgerTimestamp
}
)
;
}
}
}
return
results
;
}
Insert cell
processedDistributions
=
participantDistributions
.
map
(
(
x
)
=>
(
{
id
:
x
.
id
,
name
:
idToName
.
get
(
x
.
id
)
,
amount
:
G
.
format
(
x
.
amount
,
2
,
""
)
,
date
:
new
Date
(
x
.
ledgerTimestamp
)
,
timestamp
:
x
.
ledgerTimestamp
}
)
)
Insert cell
distributions
[
0
]
.
action
.
distribution
Insert cell
ledger
.
accounts
(
)
Insert cell
participantList
=
ledger
.
accounts
(
)
.
map
(
a
=>
a
.
identity
.
name
)
Insert cell
nameToId
=
{
const
m
=
new
Map
(
)
;
for
(
const
{
identity
}
of
ledger
.
accounts
(
)
)
{
m
.
set
(
identity
.
name
,
identity
.
id
)
;
}
return
m
;
}
Insert cell
idToName
=
{
const
m
=
new
Map
(
)
;
for
(
const
{
identity
}
of
ledger
.
accounts
(
)
)
{
m
.
set
(
identity
.
id
,
identity
.
name
)
;
}
return
m
;
}
Insert cell
sourcecredId
=
nameToId
.
get
(
"sourcecred"
)
Insert cell
protocolId
=
nameToId
.
get
(
"protocol"
)
Insert cell
json2csv
=
require
(
"json2csv"
)
Insert cell
function
serialize
(
data
)
{
let
parser
=
new
json2csv
.
Parser
(
)
;
let
csv
=
parser
.
parse
(
data
)
;
return
new
Blob
(
[
csv
]
,
{
type
:
"text/csv"
}
)
}
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.
Try it for free
Learn more
Compare fork
Fork
View
Export
title
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
BN
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
sc
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
loadCredView
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
loadLedger
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
ledger
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
G
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
totalGrain
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
activeContributors
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
transfers
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
redemptions
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
processedRedemptions
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
distributions
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
participantDistributions
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
processedDistributions
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
participantList
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
nameToId
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
idToName
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
sourcecredId
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
protocolId
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
json2csv
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
serialize
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML