This repository has been archived by the owner on Jul 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add portfolio-new mod * [WIP] getCurrencyPortfolio * [WIP] test * add test for getBalanceHistoryWithCountervalue * fix * [WIP] getPortfolio test * small fix * fix getCurrencyPortfolio * mv portfolio-new to portfolio/v2 * remove memo * fix all time count * fix count and flow * Add benchmark-portfolio * fixes tests * rm log Co-authored-by: Gaëtan Renaudeau <[email protected]>
- Loading branch information
1 parent
3857781
commit 145cd83
Showing
14 changed files
with
2,632 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* eslint-disable no-console */ | ||
var Benchmark = require("benchmark"); | ||
var { reduce } = require("rxjs/operators"); | ||
var { BigNumber } = require("bignumber.js"); | ||
var { getFiatCurrencyByTicker } = require("../lib/currencies"); | ||
var { fromAccountRaw } = require("../lib/account"); | ||
var portfolioV1 = require("../lib/portfolio"); | ||
var portfolioV2 = require("../lib/portfolio/v2"); | ||
var { | ||
initialState, | ||
calculate, | ||
loadCountervalues, | ||
inferTrackingPairForAccounts, | ||
} = require("../lib/countervalues/logic"); | ||
var { jsonFromFile } = require("../cli/lib/stream"); | ||
|
||
const cvCurrency = getFiatCurrencyByTicker("USD"); | ||
|
||
async function main() { | ||
const accountsRaw = await jsonFromFile("test-data/mere-denis.json") | ||
.pipe(reduce((acc, a) => acc.concat(a), [])) | ||
.toPromise(); | ||
const accounts = accountsRaw.map(fromAccountRaw); | ||
|
||
const cvState = await loadCountervalues(initialState, { | ||
trackingPairs: inferTrackingPairForAccounts(accounts, cvCurrency), | ||
autofillGaps: true, | ||
}); | ||
|
||
const calc = (c, v, date) => | ||
BigNumber( | ||
calculate(cvState, { | ||
date, | ||
value: v.toNumber(), | ||
from: c, | ||
to: cvCurrency, | ||
}) || 0 | ||
); | ||
|
||
new Benchmark.Suite() | ||
.on("cycle", function (event) { | ||
console.log(String(event.target)); | ||
}) | ||
.on("complete", function () { | ||
console.log("Fastest is " + this.filter("fastest").map("name")); | ||
}) | ||
.add("V1: getPortfolio", function () { | ||
portfolioV1.getPortfolio(accounts, "year", calc); | ||
}) | ||
.add("V2: getPortfolio", function () { | ||
portfolioV2.getPortfolio(accounts, "year", cvState, cvCurrency); | ||
}) | ||
.run(); | ||
|
||
new Benchmark.Suite() | ||
.on("cycle", function (event) { | ||
console.log(String(event.target)); | ||
}) | ||
.on("complete", function () { | ||
console.log("Fastest is " + this.filter("fastest").map("name")); | ||
}) | ||
.add("V1: getAssetsDistribution", function () { | ||
portfolioV1.getAssetsDistribution(accounts, calc); | ||
}) | ||
.add("V2: getAssetsDistribution", function () { | ||
portfolioV2.getAssetsDistribution(accounts, cvState, cvCurrency); | ||
}) | ||
.run(); | ||
} | ||
|
||
main(); |
Oops, something went wrong.
145cd83
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: