Completed the assignment

This commit is contained in:
Jyotirmoy Bandyopadhayaya 2022-11-28 13:06:05 +05:30
parent 79e11d88ad
commit b7c73fc964
Signed by: bravo68web
GPG Key ID: F5671FD7BCB9917A
1 changed files with 14 additions and 7 deletions

View File

@ -9,12 +9,9 @@ const {
const results = [], amountStore = {};
async function calculate(file, tokens, date) {
let tokenArr = tokens.split(',')
const USDConvStore = await getRates(tokenArr);
function USDConvStoreFn(parentCurreny, value){
const ans = value / USDConvStore[parentCurreny]
return ans.toFixed(2)
let tokenArr
if(tokens) {
tokenArr = tokens.split(',')
}
let dateToEpoch
@ -25,6 +22,7 @@ async function calculate(file, tokens, date) {
fs.createReadStream(file)
.pipe(csv())
.on('data', (data) => {
if(dateToEpoch){
if(data.timestamp > dateToEpoch){
results.push(data);
@ -36,8 +34,17 @@ async function calculate(file, tokens, date) {
results.push(data);
}
})
.on('end', () => {
.on('end', async () => {
const uniqueCoins = [...new Set(results.map(item => item.token))];
if(!tokens){
tokenArr = uniqueCoins
}
const USDConvStore = await getRates(tokenArr);
function USDConvStoreFn(parentCurreny, value){
const ans = value / USDConvStore[parentCurreny]
return ans.toFixed(2)
}
uniqueCoins.forEach(coin => {
amountStore[coin] = 0