From 99d98b1089380f5e31876c2efb29325560e2ac29 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 7 Oct 2019 14:52:11 +0200 Subject: [PATCH] Session Concept Introduced --- src/DailyFiles.js | 6 +++--- src/FileCloud.js | 10 +++++++--- src/FileCursor.js | 9 ++++++--- src/FileSequence.js | 13 ++++++++----- src/MarketFiles.js | 9 ++++++--- src/SingleFile.js | 4 ++-- 6 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/DailyFiles.js b/src/DailyFiles.js index 8e58e1e52..e91ef8f04 100644 --- a/src/DailyFiles.js +++ b/src/DailyFiles.js @@ -45,7 +45,7 @@ function newDailyFiles () { } } - function initialize (pDevTeam, pBot, pProduct, pSet, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { + function initialize (pDevTeam, pBot, pSession, pProduct, pSet, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { try { callBackWhenFileReceived = callBackFunction @@ -60,7 +60,7 @@ function newDailyFiles () { /* First we will get the Data Range */ - fileCloud.getFile(pDevTeam, pBot, pSet, exchange, pMarket, undefined, undefined, undefined, true, onDataRangeReceived) + fileCloud.getFile(pDevTeam, pBot, pSession, pSet, exchange, pMarket, undefined, undefined, undefined, true, onDataRangeReceived) function onDataRangeReceived (err, pFile) { try { @@ -110,7 +110,7 @@ function newDailyFiles () { if (pSet.validPeriods.includes(periodName) === true) { let fileCursor = newFileCursor() fileCursor.eventHandler = thisObject.eventHandler // We share our event handler with each file cursor, so that they can raise events there when files are changed.s - fileCursor.initialize(fileCloud, pDevTeam, pBot, pProduct, pSet, exchange, pMarket, periodName, periodTime, pDatetime, pTimePeriod, beginDateRange, endDateRange, onInitialized) + fileCursor.initialize(fileCloud, pDevTeam, pBot, pSession, pProduct, pSet, exchange, pMarket, periodName, periodTime, pDatetime, pTimePeriod, beginDateRange, endDateRange, onInitialized) function onInitialized (err) { try { switch (err.result) { diff --git a/src/FileCloud.js b/src/FileCloud.js index e7330ff7b..b853661ab 100644 --- a/src/FileCloud.js +++ b/src/FileCloud.js @@ -46,15 +46,15 @@ function newFileCloud () { } } - function getFile (pDevTeam, pBot, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction) { + function getFile (pDevTeam, pBot, pSession, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction) { try { if (INFO_LOG === true) { logger.write('[INFO] getFile -> Entering function.') } const MAX_RETRIES = 3 - getFileRecursively(0, pDevTeam, pBot, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction) + getFileRecursively(0, pDevTeam, pBot, pSession, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction) - function getFileRecursively (pRetryCounter, pDevTeam, pBot, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction) { + function getFileRecursively (pRetryCounter, pDevTeam, pBot, pSession, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction) { try { if (INFO_LOG === true) { logger.write('[INFO] getFile -> getFileRecursively -> Entering function.') } if (INFO_LOG === true) { logger.write('[INFO] getFile -> getFileRecursively -> key = ' + pDevTeam.codeName + '-' + pBot.codeName + '-' + pSet.filePath + '-' + pSet.fileName) } @@ -112,6 +112,10 @@ function newFileCloud () { } } + if (pSession !== undefined) { + filePath = filePath.replace('@Session', pSession.name.replace(' ', '-')) + } + if (pExchange !== undefined) { filePath = filePath.replace('@Exchange', pExchange.name) } diff --git a/src/FileCursor.js b/src/FileCursor.js index e856afedd..9952a314b 100644 --- a/src/FileCursor.js +++ b/src/FileCursor.js @@ -27,6 +27,7 @@ function newFileCursor () { let fileCloud let devTeam let bot + let session let product let thisSet let periodName @@ -50,6 +51,7 @@ function newFileCursor () { fileCloud = undefined devTeam = undefined bot = undefined + session = undefined product = undefined thisSet = undefined periodName = undefined @@ -68,13 +70,14 @@ function newFileCursor () { } } - function initialize (pFileCloud, pDevTeam, pBot, pProduct, pSet, pExchange, pMarket, pPeriodName, pTimePeriod, pCursorDate, pCurrentTimePeriod, pBeginDateRange, pEndDateRange, callBackFunction) { + function initialize (pFileCloud, pDevTeam, pBot, pSession, pProduct, pSet, pExchange, pMarket, pPeriodName, pTimePeriod, pCursorDate, pCurrentTimePeriod, pBeginDateRange, pEndDateRange, callBackFunction) { try { market = pMarket exchange = pExchange fileCloud = pFileCloud devTeam = pDevTeam bot = pBot + session = pSession product = pProduct thisSet = pSet periodName = pPeriodName @@ -109,7 +112,7 @@ function newFileCursor () { dateString = targetDate.getUTCFullYear() + '-' + pad(targetDate.getUTCMonth() + 1, 2) + '-' + pad(targetDate.getUTCDate(), 2) - fileCloud.getFile(devTeam, bot, thisSet, exchange, market, periodName, targetDate, undefined, undefined, onFileReceived) + fileCloud.getFile(devTeam, bot, session, thisSet, exchange, market, periodName, targetDate, undefined, undefined, onFileReceived) function onFileReceived (err, file) { try { @@ -409,7 +412,7 @@ function newFileCursor () { if (thisObject.files.get(dateString) === undefined) { // We dont reload files we already have. - fileCloud.getFile(devTeam, bot, thisSet, exchange, market, periodName, targetDate, undefined, undefined, onFileReceived) + fileCloud.getFile(devTeam, bot, session, thisSet, exchange, market, periodName, targetDate, undefined, undefined, onFileReceived) } else { controlLoop() } diff --git a/src/FileSequence.js b/src/FileSequence.js index 8fffd7c03..40fa3eb46 100644 --- a/src/FileSequence.js +++ b/src/FileSequence.js @@ -22,6 +22,7 @@ function newFileSequence () { let market let devTeam let bot + let session let thisSet let product let finalized = false @@ -48,6 +49,7 @@ function newFileSequence () { market = undefined devTeam = undefined bot = undefined + session = undefined thisSet = undefined product = undefined @@ -57,7 +59,7 @@ function newFileSequence () { } } - function initialize (pDevTeam, pBot, pProduct, pSet, pExchange, pMarket, callBackFunction) { + function initialize (pDevTeam, pBot, pSession, pProduct, pSet, pExchange, pMarket, callBackFunction) { try { exchange = ecosystem.getExchange(pProduct, pExchange) @@ -68,6 +70,7 @@ function newFileSequence () { market = pMarket devTeam = pDevTeam bot = pBot + session = pSession thisSet = pSet product = pProduct @@ -85,7 +88,7 @@ function newFileSequence () { /* First we will get the sequence max number */ - fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, 'Sequence', undefined, onSequenceFileReceived) + fileCloud.getFile(devTeam, bot, session, thisSet, exchange, market, undefined, undefined, 'Sequence', undefined, onSequenceFileReceived) function onSequenceFileReceived (err, file) { try { @@ -130,7 +133,7 @@ function newFileSequence () { /* Now we will get the sequence of files */ for (let i = 0; i <= maxSequence; i++) { - fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, i, undefined, onFileReceived) + fileCloud.getFile(devTeam, bot, session, thisSet, exchange, market, undefined, undefined, i, undefined, onFileReceived) function onFileReceived (err, file) { try { @@ -195,7 +198,7 @@ function newFileSequence () { let currentMaxSequence = maxSequence - fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, 'Sequence', undefined, onSequenceFileReceived) + fileCloud.getFile(devTeam, bot, session, thisSet, exchange, market, undefined, undefined, 'Sequence', undefined, onSequenceFileReceived) function onSequenceFileReceived (err, sequenceFile) { try { @@ -231,7 +234,7 @@ function newFileSequence () { /* Now we will get the sequence of files, but in this case only from the currentMaxSequence and above. */ for (let i = currentMaxSequence; i <= maxSequence; i++) { - fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, i, undefined, onFileReceived) + fileCloud.getFile(devTeam, bot, session, thisSet, exchange, market, undefined, undefined, i, undefined, onFileReceived) function onFileReceived (err, file) { try { diff --git a/src/MarketFiles.js b/src/MarketFiles.js index 05aa887ba..717f0766d 100644 --- a/src/MarketFiles.js +++ b/src/MarketFiles.js @@ -26,6 +26,7 @@ function newMarketFiles () { let exchange let devTeam let bot + let session let thisSet let product let periodName @@ -53,6 +54,7 @@ function newMarketFiles () { exchange = undefined devTeam = undefined bot = undefined + session = undefined thisSet = undefined product = undefined periodName = undefined @@ -63,7 +65,7 @@ function newMarketFiles () { } } - function initialize (pDevTeam, pBot, pProduct, pSet, pExchange, pMarket, callBackFunction) { + function initialize (pDevTeam, pBot, pSession, pProduct, pSet, pExchange, pMarket, callBackFunction) { try { exchange = ecosystem.getExchange(pProduct, pExchange) @@ -74,6 +76,7 @@ function newMarketFiles () { market = pMarket devTeam = pDevTeam bot = pBot + session = pSession thisSet = pSet product = pProduct @@ -87,7 +90,7 @@ function newMarketFiles () { let periodName = marketFilesPeriods[i][1] if (thisSet.validPeriods.includes(periodName) === true) { - fileCloud.getFile(devTeam, bot, thisSet, exchange, market, periodName, undefined, undefined, undefined, onFileReceived) + fileCloud.getFile(devTeam, bot, session, thisSet, exchange, market, periodName, undefined, undefined, undefined, onFileReceived) function onFileReceived (err, file) { try { @@ -134,7 +137,7 @@ function newMarketFiles () { let periodName = marketFilesPeriods[i][1] if (thisSet.validPeriods.includes(periodName) === true) { - fileCloud.getFile(devTeam, bot, thisSet, exchange, market, periodName, undefined, undefined, undefined, onFileReceived) + fileCloud.getFile(devTeam, bot, session, thisSet, exchange, market, periodName, undefined, undefined, undefined, onFileReceived) function onFileReceived (err, file) { try { diff --git a/src/SingleFile.js b/src/SingleFile.js index af741c69a..b8d109aca 100644 --- a/src/SingleFile.js +++ b/src/SingleFile.js @@ -16,7 +16,7 @@ function newSingleFile () { return thisObject - function initialize (pDevTeam, pBot, pProduct, pSet, pExchange, pMarket, callBackFunction) { + function initialize (pDevTeam, pBot, pSession, pProduct, pSet, pExchange, pMarket, callBackFunction) { try { if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') } if (INFO_LOG === true) { logger.write('[INFO] initialize -> key = ' + pDevTeam.codeName + '-' + pBot.codeName + '-' + pProduct.codeName) } @@ -34,7 +34,7 @@ function newSingleFile () { /* Now we will get the file */ - fileCloud.getFile(pDevTeam, pBot, pSet, exchange, pMarket, undefined, undefined, undefined, undefined, onFileReceived) + fileCloud.getFile(pDevTeam, pBot, pSession, pSet, exchange, pMarket, undefined, undefined, undefined, undefined, onFileReceived) function onFileReceived (err, pFile) { try {