From 28f5f1793c2cbee6d67680679e0b06c3a85e1ea4 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 20 Nov 2019 18:35:00 +0100 Subject: [PATCH] Inter Process Memory Implementation at Indicators Variables --- Commons.js | 54 +++++++++++++++++++++++++++++++++++++++++++++++-- IndicatorBot.js | 13 +++++++++++- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/Commons.js b/Commons.js index bf9d4dde4..1bf0d83dd 100644 --- a/Commons.js +++ b/Commons.js @@ -258,7 +258,18 @@ return results } - function dataBuildingProcedure(products, mainDependency, recordDefinition, dataBuildingProcedure, variableName, timePeriod, resultsWithIrregularPeriods) { + function dataBuildingProcedure( + products, + mainDependency, + recordDefinition, + dataBuildingProcedure, + variableName, + timePeriod, + resultsWithIrregularPeriods, + interExecutionMemory, + processingDailyFiles, + currentDay + ) { /* This function has as an input the products object, with all the information @@ -267,6 +278,8 @@ a new set of information. */ + let lastInstantOfTheDay + let yesterday = {} let system = { // These are the available system variables to be used in User Code and Formulas timePeriod: timePeriod, ONE_DAY_IN_MILISECONDS: ONE_DAY_IN_MILISECONDS @@ -287,9 +300,24 @@ } } + if (processingDailyFiles) { + /* Initialization of Last Instance */ + lastInstantOfTheDay = currentDay.valueOf() + ONE_DAY_IN_MILISECONDS - 1; + + if (interExecutionMemory.variable === undefined) { + /* The first time the intialization variables goes to the Inter Execution Memory. */ + interExecutionMemory.variable = JSON.parse(JSON.stringify(variable)) + } + else { + /* We override the initialization, since the valid stuff is already at the Inter Execution Memory */ + variable = JSON.parse(JSON.stringify(interExecutionMemory.variable)) + } + } + /* This is Initialization Code */ if (dataBuildingProcedure.loop !== undefined) { if (dataBuildingProcedure.loop.code !== undefined) { + let lastRecord for (let index = 0; index < mainDependency.records.length; index++) { let record = { @@ -297,10 +325,16 @@ current: mainDependency.records[index], next: mainDependency.records[index + 1] } - + lastRecord = record let product = {} product[variableName] = {} + /* Here is how we know if we are processing Yesterday. */ + let positionedAtYesterday = false + if (processingDailyFiles) { + positionedAtYesterday = (record.current.end < currentDay.valueOf()) + } + /* This is Loop Code */ try { eval(dataBuildingProcedure.loop.code.code) @@ -337,6 +371,22 @@ /* Adding the new element to the resulting array */ results.push(product[variableName]); } + + /* While we are positioned at Yesterday, we keey updating this data structure. */ + if (processingDailyFiles) { + if (positionedAtYesterday) { + yesterday.variable = JSON.parse(JSON.stringify(variable)) + } + } + } + /* + Before returning we need to see if we have to record some of our counters at the interExecutionMemory. + To do that, the condition to be met is that this execution must include all candles of the current day. + */ + if (processingDailyFiles) { + if (lastRecord.current.end === lastInstantOfTheDay) { + interExecutionMemory.variable = JSON.parse(JSON.stringify(yesterday.variable)) + } } } } diff --git a/IndicatorBot.js b/IndicatorBot.js index 74a547e44..ba8ed9690 100644 --- a/IndicatorBot.js +++ b/IndicatorBot.js @@ -94,7 +94,18 @@ } /* Build the data */ - jsonData = commons.dataBuildingProcedure(products, mainDependency, recordDefinition, outputDatasetNode.referenceParent.parentNode.dataBuilding, singularVariableName, timePeriod, resultsWithIrregularPeriods) + jsonData = commons.dataBuildingProcedure( + products, + mainDependency, + recordDefinition, + outputDatasetNode.referenceParent.parentNode.dataBuilding, + singularVariableName, + timePeriod, + resultsWithIrregularPeriods, + interExecutionMemory, + processingDailyFiles, + currentDay + ) /* Add the calculated properties */ if (outputDatasetNode.referenceParent.parentNode.calculations !== undefined) {