From ae2efec4fa83a3ff0ada436e70963cd9c17b1ad4 Mon Sep 17 00:00:00 2001 From: AswinT22 <42780141+AswinT22@users.noreply.github.com> Date: Mon, 27 Apr 2020 07:53:28 +0530 Subject: [PATCH] update --- utils/candlestickPatternUtils.js | 41 +++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/utils/candlestickPatternUtils.js b/utils/candlestickPatternUtils.js index bd91f7c..e80b7d9 100644 --- a/utils/candlestickPatternUtils.js +++ b/utils/candlestickPatternUtils.js @@ -1,4 +1,43 @@ -module.exports.isHammer= function (row) { +const fs = require('fs'); +const csv = require('csv-parser'); +const path = require('path'); +const csvWriter = require('csv-write-stream'); +const stringUtils = require(path.join(__dirname,"stringUtils")); +const chartUtils = require(path.join(__dirname,"chartUtils")); + +module.exports.filterHammerAndWrite = function (inputFilePath, outputFilePath, render) { + // using streams to handle large datasets + var writer = csvWriter(); + writer.pipe(fs.createWriteStream(outputFilePath, {flags: 'a'})); + + var map = {};// handle duplicates + console.log("Identifying hammer candlestick pattern....."); + fs.createReadStream(inputFilePath) + .on('error', (err) => { + console.log(err); + }) + .pipe(csv()) + .on('data', (row) => { + var hash = stringUtils.stringToHash(row.Date); + if (hash in map) { + // Duplicates + return + } + map[hash] = 1 + if(isHammer(row)) { + writer.write(row); + } + }) + .on('end', () => { + writer.end(); + console.log("Find the filtered csv at", outputFilePath); + if (render) { + chartUtils.renderChart(outputFilePath, "filtered-hammer-chart"); + } + }); +} + +function isHammer(row) { // defining these to perform checks later, if required any const close = parseFloat(row.close); const open = parseFloat(row.open);