From 0fb685a34ff073569833e283396e05e44b43d175 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 20 Nov 2019 09:47:48 +0100 Subject: [PATCH] Ready to Import Run Simulation --- Commons.js | 35 ++++++++++++++++++----------------- MultiPeriod.js | 10 +++++----- MultiPeriodDaily.js | 6 +++--- MultiPeriodMarket.js | 6 +++--- 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/Commons.js b/Commons.js index 2a52f8c6f..706409c71 100644 --- a/Commons.js +++ b/Commons.js @@ -24,21 +24,21 @@ function validateDataDependencies(dataDependencies, callBackFunction) { for (let i = 0; i < dataDependencies.length; i++) { - let dataDependencyNode = dataDependencies[i].referenceParent + let dataDependencyNode = dataDependencies[i] /* Basic validations to see if we have everything we need. */ - if (dataDependencyNode.parentNode.code.singularVariableName === undefined) { - logger.write(MODULE_NAME, "[ERROR] start -> Product Definition without a Single Variable Name defined. Product Definition = " + JSON.stringify(dataDependencyNode.parentNode)); + if (dataDependencyNode.referenceParent.parentNode.code.singularVariableName === undefined) { + logger.write(MODULE_NAME, "[ERROR] start -> Product Definition without a Single Variable Name defined. Product Definition = " + JSON.stringify(dataDependencyNode.referenceParent.parentNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return } - if (dataDependencyNode.parentNode.code.pluralVariableName === undefined) { - logger.write(MODULE_NAME, "[ERROR] start -> Product Definition without a Plural Variable Name defined. Product Definition = " + JSON.stringify(dataDependencyNode.parentNode)); + if (dataDependencyNode.referenceParent.parentNode.code.pluralVariableName === undefined) { + logger.write(MODULE_NAME, "[ERROR] start -> Product Definition without a Plural Variable Name defined. Product Definition = " + JSON.stringify(dataDependencyNode.referenceParent.parentNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return } - if (dataDependencyNode.parentNode.record === undefined) { - logger.write(MODULE_NAME, "[ERROR] start -> Product Definition without a Record Definition. Product Definition = " + JSON.stringify(dataDependencyNode.parentNode)); + if (dataDependencyNode.referenceParent.parentNode.record === undefined) { + logger.write(MODULE_NAME, "[ERROR] start -> Product Definition without a Record Definition. Product Definition = " + JSON.stringify(dataDependencyNode.referenceParent.parentNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return } @@ -71,9 +71,7 @@ return } if (outputDatasetNode.referenceParent.parentNode.dataBuilding === undefined) { - logger.write(MODULE_NAME, "[ERROR] start -> Product Definition without a Data Building Procedure. Product Definition = " + JSON.stringify(outputDatasetNode.referenceParent.parentNode)); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return + logger.write(MODULE_NAME, "[WARN] start -> Product Definition without a Data Building Procedure. Product Definition = " + JSON.stringify(outputDatasetNode.referenceParent.parentNode)); } if (outputDatasetNode.referenceParent.code.codeName === undefined) { logger.write(MODULE_NAME, "[ERROR] start -> Dataset witn no codeName defined. Product Dataset = " + JSON.stringify(outputDatasetNode.referenceParent)); @@ -128,25 +126,28 @@ */ for (let i = 0; i < dataDependencies.length; i++) { - let dataFile = dataFiles[i] + let dataFile let jsonData // Datafile converted into Json objects let inputData // Includes calculated properties let singularVariableName // name of the variable for this product let recordDefinition - let dataDependencyNode = dataDependencies[i].referenceParent + let dataDependencyNode = dataDependencies[i] + dataFile = dataFiles.get(dataDependencyNode.id) - recordDefinition = dataDependencyNode.parentNode.record - singularVariableName = dataDependencyNode.parentNode.code.singularVariableName + if (dataFile === undefined) { continue } // When a datafile is not found it might be because we are processing market or daily and at the dependency array there are both types mixed up. + + recordDefinition = dataDependencyNode.referenceParent.parentNode.record + singularVariableName = dataDependencyNode.referenceParent.parentNode.code.singularVariableName /* Transform the raw data into JSON objects */ jsonData = jsonifyDataFile(dataFile, recordDefinition) /* Add the calculated properties */ - if (dataDependencyNode.parentNode.calculations !== undefined) { - inputData = calculationsProcedure(jsonData, recordDefinition, dataDependencyNode.parentNode.calculations, singularVariableName, timePeriod) + if (dataDependencyNode.referenceParent.parentNode.calculations !== undefined) { + inputData = calculationsProcedure(jsonData, recordDefinition, dataDependencyNode.referenceParent.parentNode.calculations, singularVariableName, timePeriod) } else { inputData = jsonData } - products[dataDependencyNode.parentNode.code.pluralVariableName] = inputData + products[dataDependencyNode.referenceParent.parentNode.code.pluralVariableName] = inputData /* The main dependency is defined as the first dependency processed. */ if (mainDependency.records === undefined) { diff --git a/MultiPeriod.js b/MultiPeriod.js index f2aeb825d..e877b2286 100644 --- a/MultiPeriod.js +++ b/MultiPeriod.js @@ -17,7 +17,7 @@ let statusDependencies; let dataDependencies; let datasets = []; - let dataFiles = []; + let dataFiles = new Map(); let multiPeriodDataFiles = new Map(); let botInstance; @@ -287,7 +287,7 @@ const outputPeriodLabel = global.marketFilesPeriods[n][1]; let dependencyIndex = 0; - dataFiles = []; + dataFiles = new Map(); if (bot.VALUES_TO_USE.timePeriod === outputPeriodLabel) { currentTimePeriod = global.marketFilesPeriods[n][0]; @@ -339,7 +339,7 @@ } let dataFile = JSON.parse(text); - dataFiles.push(dataFile); + dataFiles.set(dependency.id, dataFile); dependencyControlLoop(); @@ -596,7 +596,7 @@ } let dependencyIndex = 0; - dataFiles = []; + dataFiles = new Map(); dependencyLoopBody(); function dependencyLoopBody() { @@ -748,7 +748,7 @@ let dataFile = previousFile.concat(currentFile); - dataFiles.push(dataFile); + dataFiles.set(dependency.id, dataFile); dependencyControlLoop(); diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index ea4a030f9..f11198fa7 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -17,7 +17,7 @@ let statusDependencies; let dataDependencies; let datasets = []; - let dataFiles = []; + let dataFiles = new Map; let botInstance; @@ -386,7 +386,7 @@ } let dependencyIndex = 0; - dataFiles = []; + dataFiles = new Map(); dependencyLoopBody(); @@ -533,7 +533,7 @@ let dataFile = previousFile.concat(currentFile); - dataFiles.push(dataFile); + dataFiles.set(dependency.id, dataFile); dependencyControlLoop(); } diff --git a/MultiPeriodMarket.js b/MultiPeriodMarket.js index 11dadbe2a..37311cef4 100644 --- a/MultiPeriodMarket.js +++ b/MultiPeriodMarket.js @@ -15,7 +15,7 @@ let statusDependencies; let dataDependencies; let datasets = []; - let dataFiles = []; + let dataFiles = new Map(); let botInstance; @@ -151,7 +151,7 @@ const outputPeriodLabel = global.marketFilesPeriods[n][1]; let dependencyIndex = 0; - dataFiles = []; + dataFiles = new Map; dependencyLoopBody(); @@ -198,7 +198,7 @@ } let dataFile = JSON.parse(text); - dataFiles.push(dataFile); + dataFiles.set(dependency.id, dataFile); dependencyControlLoop();