Skip to content

Commit

Permalink
batch sizes are implemented on input csv file
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramon committed May 2, 2024
1 parent 49ab2e9 commit a60fcee
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions adapters/secta/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export const getUserTVLByBlock = async (blocks: BlockData) => {
return csvRows;
};

/*readBlocksFromCSV(path.resolve(__dirname, "../block_numbers_secta.tsv"))
readBlocksFromCSV(path.resolve(__dirname, "../block_numbers_secta.tsv"))
.then(async (blocks) => {
console.log(blocks);
const allCsvRows: any[] = []; // Array to accumulate CSV rows for all blocks
Expand All @@ -168,31 +168,21 @@ export const getUserTVLByBlock = async (blocks: BlockData) => {

i++;
console.log(`Processed block ${i}`);
// Write to file when batch size is reached or at the end of loop
if (i % batchSize === 0 || i === blocks.length) {
const ws = fs.createWriteStream(`outputData.csv`, {
flags: i === batchSize ? "w" : "a",
});
write(allCsvRows, {
headers: i === batchSize ? true : false,
})
.pipe(ws)
.on("finish", () => {
console.log(`CSV file has been written.`);
});
// Clear the accumulated CSV rows
allCsvRows.length = 0;
}
} catch (error) {
console.error(`An error occurred for block ${block}:`, error);
}
}
const ws = fs.createWriteStream(`outputData.csv`, {
flags: "w",
});
write(allCsvRows, {headers: true})
.pipe(ws).on("finish", () => {
console.log(`CSV file has been written.`);
});
})
.catch((err) => {
console.error("Error reading CSV file:", err);
});*/
});

// main().then(() => {
// console.log("Done");
Expand Down

0 comments on commit a60fcee

Please sign in to comment.