Skip to content

Commit e602810

Browse files
wraithgarvmx
authored andcommitted
feat: add ledger.debtRatio()
1 parent 2bc5600 commit e602810

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/decision-engine/ledger.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ class Ledger {
3939
wantlistContains (cid) {
4040
return this.wantlist.contains(cid)
4141
}
42+
43+
debtRatio () {
44+
return (this.accounting.bytesSent / (this.accounting.bytesRecv + 1)) // +1 is to prevent division by zero
45+
}
4246
}
4347

4448
module.exports = Ledger

test/decision-engine/ledger.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,7 @@ describe('Ledger', () => {
3838
bytesSent: 100 + 12000,
3939
bytesRecv: 223432 + 2333
4040
})
41+
expect(ledger.debtRatio())
42+
.to.eql((100 + 12000) / (223432 + 2333 + 1))
4143
})
4244
})

0 commit comments

Comments
 (0)