From 9dc4f972e772529d72957e875c78b97463c5d2e9 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 1 Sep 2020 14:32:11 +0200 Subject: [PATCH] Backtesting working again --- Commons.js | 21 ++++++++++++------- IndicatorOutput.js | 7 +++++-- ProcessOutput.js | 52 ++++++++++++++++++++++++++++++---------------- server.js | 6 ++++-- 4 files changed, 56 insertions(+), 30 deletions(-) diff --git a/Commons.js b/Commons.js index 3f5642205..a93cd8d85 100644 --- a/Commons.js +++ b/Commons.js @@ -95,26 +95,31 @@ return } - if (outputDatasetNode.referenceParent.parentNode.parentNode === undefined) { - logger.write(MODULE_NAME, "[ERROR] start -> Product Definition not attached to a Bot. Product Definition = " + JSON.stringify(outputDatasetNode.referenceParent.parentNode)); + let botNode = global.FIND_NODE_IN_NODE_MESH(outputDatasetNode, 'Indicator Bot') + if (botNode === undefined) { + botNode = global.FIND_NODE_IN_NODE_MESH(outputDatasetNode, 'Trading Bot') + } + if (botNode === undefined) { + logger.write(MODULE_NAME, "[ERROR] start -> Product Definition not attached to a Bot. Product Definition = " ); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return } - if (outputDatasetNode.referenceParent.parentNode.parentNode.config.codeName === undefined) { - logger.write(MODULE_NAME, "[ERROR] start -> Bot witn no codeName defined. Bot = " + JSON.stringify(outputDatasetNode.referenceParent.parentNode.parentNode)); + if (botNode.config.codeName === undefined) { + logger.write(MODULE_NAME, "[ERROR] start -> Bot witn no codeName defined." ); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return } - if (outputDatasetNode.referenceParent.parentNode.parentNode.parentNode === undefined) { - logger.write(MODULE_NAME, "[ERROR] start -> Bot not attached to a Data Mine. Bot = " + JSON.stringify(outputDatasetNode.referenceParent.parentNode.parentNode)); + let dataMineNode = global.FIND_NODE_IN_NODE_MESH(outputDatasetNode, 'Data Mine') + if (dataMineNode === undefined) { + logger.write(MODULE_NAME, "[ERROR] start -> Bot not attached to a Data Mine."); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return } - if (outputDatasetNode.referenceParent.parentNode.parentNode.parentNode.config.codeName === undefined) { - logger.write(MODULE_NAME, "[ERROR] start -> Data Mine witn no codeName defined. Data Mine = " + JSON.stringify(outputDatasetNode.referenceParent.parentNode.parentNode.parentNode)); + if (dataMineNode.config.codeName === undefined) { + logger.write(MODULE_NAME, "[ERROR] start -> Data Mine witn no codeName defined." ); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return } diff --git a/IndicatorOutput.js b/IndicatorOutput.js index 988acda77..1f8d20691 100644 --- a/IndicatorOutput.js +++ b/IndicatorOutput.js @@ -130,8 +130,11 @@ contextSummary.dataset = outputDatasetNode.referenceParent.config.codeName contextSummary.product = outputDatasetNode.referenceParent.parentNode.config.codeName - contextSummary.bot = outputDatasetNode.referenceParent.parentNode.parentNode.config.codeName - contextSummary.dataMine = outputDatasetNode.referenceParent.parentNode.parentNode.parentNode.config.codeName + + let botNode = global.FIND_NODE_IN_NODE_MESH(outputDatasetNode, 'Indicator Bot') + contextSummary.bot = botNode.config.codeName + let dataMineNode = global.FIND_NODE_IN_NODE_MESH(outputDatasetNode, 'Data Mine') + contextSummary.dataMine = dataMineNode.config.codeName let fileContent = commons.generateFileContent(outputData, outputDatasetNode.referenceParent.parentNode.record, resultsWithIrregularPeriods, processingDailyFiles, currentDay, callBackFunction) commons.writeFile(contextSummary, fileContent, anotherFileWritten, processingDailyFiles, timeFrameLabel, currentDay, callBackFunction) diff --git a/ProcessOutput.js b/ProcessOutput.js index 3496ffe15..5ac15c864 100644 --- a/ProcessOutput.js +++ b/ProcessOutput.js @@ -25,6 +25,14 @@ for (let j = 0; j < outputDatasets.length; j++) { let outputDataset = outputDatasets[j] + let botNode = global.FIND_NODE_IN_NODE_MESH(outputDataset, 'Indicator Bot') + if (botNode === undefined) { + botNode = global.FIND_NODE_IN_NODE_MESH(outputDataset, 'Trading Bot') + } + if (botNode === undefined) { + botNode = global.FIND_NODE_IN_NODE_MESH(outputDataset, 'Sensor Bot') + } + /* Some validations to verify that everything is in place. */ if (outputDataset.referenceParent !== undefined) { if (outputDataset.referenceParent.config.codeName === undefined) { @@ -38,20 +46,20 @@ callBackFunction(global.DEFAULT_FAIL_RESPONSE); return } - if (outputDataset.referenceParent.parentNode.parentNode !== undefined) { - if (outputDataset.referenceParent.parentNode.parentNode.config.codeName === undefined) { - logger.write(MODULE_NAME, "[ERROR] raiseEvents -> codeName at Bot not defined. Bot = " + JSON.stringify(outputDataset.referenceParent.parentNode.parentNode)); + if (botNode !== undefined) { + if (botNode.config.codeName === undefined) { + logger.write(MODULE_NAME, "[ERROR] raiseEvents -> codeName at Bot not defined. Bot = " + JSON.stringify(botNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return } - if (outputDataset.referenceParent.parentNode.parentNode.parentNode !== undefined) { - if (outputDataset.referenceParent.parentNode.parentNode.parentNode.config.codeName === undefined) { - logger.write(MODULE_NAME, "[ERROR] raiseEvents -> codeName at Data Mine not defined. Data Mine = " + JSON.stringify(outputDataset.referenceParent.parentNode.parentNode.parentNode)); + if (botNode.parentNode !== undefined) { + if (botNode.parentNode.config.codeName === undefined) { + logger.write(MODULE_NAME, "[ERROR] raiseEvents -> codeName at Data Mine not defined. Data Mine = " + JSON.stringify(botNode.parentNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return } } else { - logger.write(MODULE_NAME, "[ERROR] raiseEvents -> Bot not attached to a Data Mine. Bot = " + JSON.stringify(outputDataset.referenceParent.parentNode.parentNode)); + logger.write(MODULE_NAME, "[ERROR] raiseEvents -> Bot not attached to a Data Mine. Bot = " + JSON.stringify(botNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return } @@ -73,8 +81,8 @@ /* All good, lets emit the event. */ - let dataMine = outputDataset.referenceParent.parentNode.parentNode.parentNode.config.codeName - let botName = outputDataset.referenceParent.parentNode.parentNode.config.codeName + let dataMine = botNode.parentNode.config.codeName + let botName = botNode.config.codeName let product = outputDataset.referenceParent.parentNode.config.codeName let dataset = outputDataset.referenceParent.config.codeName @@ -104,6 +112,14 @@ for (let j = 0; j < outputDatasets.length; j++) { let outputDataset = outputDatasets[j] + let botNode = global.FIND_NODE_IN_NODE_MESH(outputDataset, 'Indicator Bot') + if (botNode === undefined) { + botNode = global.FIND_NODE_IN_NODE_MESH(outputDataset, 'Trading Bot') + } + if (botNode === undefined) { + botNode = global.FIND_NODE_IN_NODE_MESH(outputDataset, 'Sensor Bot') + } + /* Some validations to verify that everything is in place. */ if (outputDataset.referenceParent !== undefined) { if (outputDataset.referenceParent.config.codeName === undefined) { @@ -115,18 +131,18 @@ logger.write(MODULE_NAME, "[ERROR] raiseEvents -> codeName at Product not defined. Product = " + JSON.stringify(outputDataset.referenceParent.parentNode)); throw (global.DEFAULT_FAIL_RESPONSE); } - if (outputDataset.referenceParent.parentNode.parentNode !== undefined) { - if (outputDataset.referenceParent.parentNode.parentNode.config.codeName === undefined) { - logger.write(MODULE_NAME, "[ERROR] raiseEvents -> codeName at Bot not defined. Bot = " + JSON.stringify(outputDataset.referenceParent.parentNode.parentNode)); + if (botNode !== undefined) { + if (botNode.config.codeName === undefined) { + logger.write(MODULE_NAME, "[ERROR] raiseEvents -> codeName at Bot not defined. Bot = " + JSON.stringify(botNode)); throw (global.DEFAULT_FAIL_RESPONSE); } - if (outputDataset.referenceParent.parentNode.parentNode.parentNode !== undefined) { - if (outputDataset.referenceParent.parentNode.parentNode.parentNode.config.codeName === undefined) { - logger.write(MODULE_NAME, "[ERROR] raiseEvents -> codeName at Data Mine not defined. Data Mine = " + JSON.stringify(outputDataset.referenceParent.parentNode.parentNode.parentNode)); + if (botNode.parentNode !== undefined) { + if (botNode.parentNode.config.codeName === undefined) { + logger.write(MODULE_NAME, "[ERROR] raiseEvents -> codeName at Data Mine not defined. Data Mine = " + JSON.stringify(botNode.parentNode)); throw (global.DEFAULT_FAIL_RESPONSE); } } else { - logger.write(MODULE_NAME, "[ERROR] raiseEvents -> Bot not attached to a Data Mine. Bot = " + JSON.stringify(outputDataset.referenceParent.parentNode.parentNode)); + logger.write(MODULE_NAME, "[ERROR] raiseEvents -> Bot not attached to a Data Mine. Bot = " + JSON.stringify(botNode)); throw (global.DEFAULT_FAIL_RESPONSE); } } else { @@ -144,8 +160,8 @@ /* All good, lets emit the event. */ - let dataMine = outputDataset.referenceParent.parentNode.parentNode.parentNode.config.codeName - let botName = outputDataset.referenceParent.parentNode.parentNode.config.codeName + let dataMine = botNode.parentNode.config.codeName + let botName = botNode.config.codeName let product = outputDataset.referenceParent.parentNode.config.codeName let dataset = outputDataset.referenceParent.config.codeName diff --git a/server.js b/server.js index 0b014d460..b72ed1361 100644 --- a/server.js +++ b/server.js @@ -127,8 +127,10 @@ global.NODE_BRANCH_TO_ARRAY = function (node, nodeType) { break case 'array': { let startingNodePropertyArray = startingNode[property.name] - for (let m = 0; m < startingNodePropertyArray.length; m++) { - scanNodeBranch(startingNodePropertyArray[m]) + if (startingNodePropertyArray !== undefined) { + for (let m = 0; m < startingNodePropertyArray.length; m++) { + scanNodeBranch(startingNodePropertyArray[m]) + } } break }