Completed the assignment
This commit is contained in:
parent
79e11d88ad
commit
b7c73fc964
|
@ -9,12 +9,9 @@ const {
|
||||||
const results = [], amountStore = {};
|
const results = [], amountStore = {};
|
||||||
|
|
||||||
async function calculate(file, tokens, date) {
|
async function calculate(file, tokens, date) {
|
||||||
let tokenArr = tokens.split(',')
|
let tokenArr
|
||||||
const USDConvStore = await getRates(tokenArr);
|
if(tokens) {
|
||||||
|
tokenArr = tokens.split(',')
|
||||||
function USDConvStoreFn(parentCurreny, value){
|
|
||||||
const ans = value / USDConvStore[parentCurreny]
|
|
||||||
return ans.toFixed(2)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let dateToEpoch
|
let dateToEpoch
|
||||||
|
@ -25,6 +22,7 @@ async function calculate(file, tokens, date) {
|
||||||
fs.createReadStream(file)
|
fs.createReadStream(file)
|
||||||
.pipe(csv())
|
.pipe(csv())
|
||||||
.on('data', (data) => {
|
.on('data', (data) => {
|
||||||
|
|
||||||
if(dateToEpoch){
|
if(dateToEpoch){
|
||||||
if(data.timestamp > dateToEpoch){
|
if(data.timestamp > dateToEpoch){
|
||||||
results.push(data);
|
results.push(data);
|
||||||
|
@ -36,8 +34,17 @@ async function calculate(file, tokens, date) {
|
||||||
results.push(data);
|
results.push(data);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.on('end', () => {
|
.on('end', async () => {
|
||||||
const uniqueCoins = [...new Set(results.map(item => item.token))];
|
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 => {
|
uniqueCoins.forEach(coin => {
|
||||||
amountStore[coin] = 0
|
amountStore[coin] = 0
|
||||||
|
|
Loading…
Reference in New Issue