Function to find the networkNode for a Dataset reimplemented
This commit is contained in:
1 parent
ea092fa6e5
commit
f630ecf212
7 files changed
+289
-83
No files matched your search
@@ -328,7 +328,7 @@
|
||||
dependencyLoopBody()
|
||||
|
||||
function dependencyLoopBody() {
|
||||
let dependency = dataDependenciesModule.curatedNodeArray[dependencyIndex]
|
||||
let dependency = dataDependenciesModule.curatedDependencyNodeArray[dependencyIndex]
|
||||
if (dependency === undefined) {
|
||||
|
||||
TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME,
|
||||
@@ -453,7 +453,7 @@
|
||||
|
||||
function dependencyControlLoop() {
|
||||
dependencyIndex++;
|
||||
if (dependencyIndex < dataDependenciesModule.curatedNodeArray.length) {
|
||||
if (dependencyIndex < dataDependenciesModule.curatedDependencyNodeArray.length) {
|
||||
dependencyLoopBody()
|
||||
} else {
|
||||
generateOutput()
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
dependencyLoopBody()
|
||||
|
||||
function dependencyLoopBody() {
|
||||
let dependency = dataDependenciesModule.curatedNodeArray[dependencyIndex]
|
||||
let dependency = dataDependenciesModule.curatedDependencyNodeArray[dependencyIndex]
|
||||
let datasetModule = dataDependenciesModule.dataSetsModulesArray[dependencyIndex]
|
||||
|
||||
getFile()
|
||||
@@ -96,7 +96,7 @@
|
||||
|
||||
function dependencyControlLoop() {
|
||||
dependencyIndex++;
|
||||
if (dependencyIndex < dataDependenciesModule.curatedNodeArray.length) {
|
||||
if (dependencyIndex < dataDependenciesModule.curatedDependencyNodeArray.length) {
|
||||
dependencyLoopBody()
|
||||
} else {
|
||||
generateOutput()
|
||||
|
||||
+9
-9
@@ -332,15 +332,15 @@
|
||||
async function processSingleFiles() {
|
||||
dataFiles = new Map()
|
||||
|
||||
for (let dependencyIndex = 0; dependencyIndex < dataDependenciesModule.curatedNodeArray.length; dependencyIndex++) {
|
||||
let dependency = dataDependenciesModule.curatedNodeArray[dependencyIndex]
|
||||
for (let dependencyIndex = 0; dependencyIndex < dataDependenciesModule.curatedDependencyNodeArray.length; dependencyIndex++) {
|
||||
let dependency = dataDependenciesModule.curatedDependencyNodeArray[dependencyIndex]
|
||||
let datasetModule = dataDependenciesModule.dataSetsModulesArray[dependencyIndex]
|
||||
|
||||
if (datasetModule.node.config.codeName !== "Single-File") {
|
||||
continue
|
||||
}
|
||||
|
||||
if (dataDependenciesModule.isItADepenency('atAnyTimeFrame', datasetModule.node.parentNode.config.singularVariableName) !== true) {
|
||||
if (dataDependenciesModule.isItAChartDepenency('atAnyTimeFrame', datasetModule.node.parentNode.config.singularVariableName) !== true) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -392,15 +392,15 @@
|
||||
}
|
||||
|
||||
/* Loop across the list of curated dependencies */
|
||||
for (let dependencyIndex = 0; dependencyIndex < dataDependenciesModule.curatedNodeArray.length; dependencyIndex++) {
|
||||
let dependency = dataDependenciesModule.curatedNodeArray[dependencyIndex]
|
||||
for (let dependencyIndex = 0; dependencyIndex < dataDependenciesModule.curatedDependencyNodeArray.length; dependencyIndex++) {
|
||||
let dependency = dataDependenciesModule.curatedDependencyNodeArray[dependencyIndex]
|
||||
let datasetModule = dataDependenciesModule.dataSetsModulesArray[dependencyIndex]
|
||||
|
||||
if (dependency.referenceParent.config.codeName !== "Multi-Period-Market") {
|
||||
continue
|
||||
}
|
||||
|
||||
if (dataDependenciesModule.isItADepenency(timeFrameLabel, datasetModule.node.parentNode.config.singularVariableName) !== true) {
|
||||
if (dataDependenciesModule.isItAChartDepenency(timeFrameLabel, datasetModule.node.parentNode.config.singularVariableName) !== true) {
|
||||
if (!(TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_NODE.tradingParameters.timeFrame.config.label === timeFrameLabel && datasetModule.node.parentNode.config.pluralVariableName === 'candles')) {
|
||||
continue
|
||||
}
|
||||
@@ -502,8 +502,8 @@
|
||||
We will iterate through all dependencies, in order to load the
|
||||
files that later will end up at the chart data structure.
|
||||
*/
|
||||
for (let dependencyIndex = 0; dependencyIndex < dataDependenciesModule.curatedNodeArray.length; dependencyIndex++) {
|
||||
let dependency = dataDependenciesModule.curatedNodeArray[dependencyIndex]
|
||||
for (let dependencyIndex = 0; dependencyIndex < dataDependenciesModule.curatedDependencyNodeArray.length; dependencyIndex++) {
|
||||
let dependency = dataDependenciesModule.curatedDependencyNodeArray[dependencyIndex]
|
||||
let datasetModule = dataDependenciesModule.dataSetsModulesArray[dependencyIndex]
|
||||
|
||||
if (dependency.referenceParent.config.codeName !== "Multi-Period-Daily") {
|
||||
@@ -513,7 +513,7 @@
|
||||
/*
|
||||
If it is not a dependency then we pass..
|
||||
*/
|
||||
if (dataDependenciesModule.isItADepenency(timeFrameLabel, datasetModule.node.parentNode.config.singularVariableName) !== true) {
|
||||
if (dataDependenciesModule.isItAChartDepenency(timeFrameLabel, datasetModule.node.parentNode.config.singularVariableName) !== true) {
|
||||
if (!(TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_NODE.tradingParameters.timeFrame.config.label === timeFrameLabel && datasetModule.node.parentNode.config.pluralVariableName === 'candles')) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -17,16 +17,16 @@
|
||||
to filter out data dependencies based on the code written by users
|
||||
at the Javascript Code and Formula nodes.
|
||||
*/
|
||||
const MODULE_NAME = "Data Dependencies";
|
||||
const MODULE_NAME = "Data Dependencies"
|
||||
|
||||
let thisObject = {
|
||||
filters: undefined,
|
||||
curatedNodeArray: undefined,
|
||||
curatedDependencyNodeArray: undefined,
|
||||
dataSetsModulesArray: [],
|
||||
isItADepenency: isItADepenency,
|
||||
isItAChartDepenency: isItAChartDepenency,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
};
|
||||
}
|
||||
|
||||
thisObject.filters = {
|
||||
chart: {
|
||||
@@ -39,11 +39,12 @@
|
||||
},
|
||||
exchange: {
|
||||
list: new Map(),
|
||||
markets: new Map(),
|
||||
products: new Map()
|
||||
}
|
||||
}
|
||||
|
||||
return thisObject;
|
||||
return thisObject
|
||||
|
||||
function initialize(callBackFunction) {
|
||||
try {
|
||||
@@ -52,9 +53,9 @@
|
||||
/*
|
||||
First we will get all the data dependencies of the bot, as defined at the Trading Mine.
|
||||
*/
|
||||
thisObject.curatedNodeArray = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processDependencies, 'Data Dependency')
|
||||
if (thisObject.curatedNodeArray.length === 0) {
|
||||
TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, "[ERROR] initialize -> onInitilized -> It is not possible to not have data dependencies at all.");
|
||||
thisObject.curatedDependencyNodeArray = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processDependencies, 'Data Dependency')
|
||||
if (thisObject.curatedDependencyNodeArray.length === 0) {
|
||||
TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, "[ERROR] initialize -> onInitilized -> It is not possible to not have data dependencies at all.")
|
||||
callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_FAIL_RESPONSE)
|
||||
return
|
||||
}
|
||||
@@ -63,38 +64,39 @@
|
||||
This will allow the user to have less Data Mines loaded at the workspace
|
||||
that the ones that a Trading Mine depends on.
|
||||
*/
|
||||
thisObject.curatedNodeArray = TS.projects.superalgos.utilities.nodeFunctions.filterOutNodeWihtoutReferenceParentFromNodeArray(thisObject.curatedNodeArray)
|
||||
thisObject.curatedDependencyNodeArray = TS.projects.superalgos.utilities.nodeFunctions.filterOutNodeWihtoutReferenceParentFromNodeArray(thisObject.curatedDependencyNodeArray)
|
||||
|
||||
} else {
|
||||
TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, "[ERROR] initialize -> onInitilized -> It is not possible not to have process dependencies, which means not data dependencies.");
|
||||
TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, "[ERROR] initialize -> onInitilized -> It is not possible not to have process dependencies, which means not data dependencies.")
|
||||
callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE)
|
||||
return
|
||||
}
|
||||
|
||||
if (thisObject.curatedNodeArray.length === 0) {
|
||||
if (thisObject.curatedDependencyNodeArray.length === 0) {
|
||||
|
||||
// We allow old indicators not to declare their data dependencies.
|
||||
callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE);
|
||||
return;
|
||||
callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE)
|
||||
return
|
||||
}
|
||||
|
||||
/* Session based dependency thisObject.filters */
|
||||
let dependencyFilter = TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).DEPENDENCY_FILTER
|
||||
if (dependencyFilter !== undefined) {
|
||||
let receivedDependencyFilters = TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).DEPENDENCY_FILTER
|
||||
if (receivedDependencyFilters !== undefined) {
|
||||
|
||||
/*
|
||||
Javascript Maps can not travel stringified at ta JSON object, so we receive
|
||||
these maps in an Array format, and here we will just convert them to Maps,
|
||||
that is how we need them.
|
||||
*/
|
||||
arrayToMap(dependencyFilter.chart.list, thisObject.filters.chart.list)
|
||||
arrayToMap(dependencyFilter.chart.products, thisObject.filters.chart.products)
|
||||
arrayToMap(receivedDependencyFilters.chart.list, thisObject.filters.chart.list)
|
||||
arrayToMap(receivedDependencyFilters.chart.products, thisObject.filters.chart.products)
|
||||
|
||||
arrayToMap(dependencyFilter.market.list, thisObject.filters.market.list)
|
||||
arrayToMap(dependencyFilter.market.products, thisObject.filters.market.products)
|
||||
arrayToMap(receivedDependencyFilters.market.list, thisObject.filters.market.list)
|
||||
arrayToMap(receivedDependencyFilters.market.products, thisObject.filters.market.products)
|
||||
|
||||
arrayToMap(dependencyFilter.exchange.list, thisObject.filters.exchange.list)
|
||||
arrayToMap(dependencyFilter.exchange.products, thisObject.filters.exchange.products)
|
||||
arrayToMap(receivedDependencyFilters.exchange.list, thisObject.filters.exchange.list)
|
||||
arrayToMap(receivedDependencyFilters.exchange.markets, thisObject.filters.exchange.markets)
|
||||
arrayToMap(receivedDependencyFilters.exchange.products, thisObject.filters.exchange.products)
|
||||
|
||||
function arrayToMap(array, map) {
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
@@ -107,23 +109,23 @@
|
||||
At our filter structure, we will add the Task default exchange and market.
|
||||
This will help us lateer to build other structures in a generic way.
|
||||
*/
|
||||
thisObject.filters.exchange.list.set(
|
||||
TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.parentNode.parentNode.config.codeName
|
||||
)
|
||||
thisObject.filters.market.list.set(
|
||||
let defaultExchange = TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.parentNode.parentNode.config.codeName
|
||||
let defautMarket =
|
||||
TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.baseAsset.referenceParent.config.codeName +
|
||||
"-" +
|
||||
TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.quotedAsset.referenceParent.config.codeName
|
||||
)
|
||||
thisObject.filters.exchange.list.set(defaultExchange, true)
|
||||
thisObject.filters.exchange.markets.set(defaultExchange + '-' + defautMarket, true)
|
||||
thisObject.filters.market.list.set(true)
|
||||
/*
|
||||
For each dependency declared at the curatedNodeArray, we will initialize a DataSet as part of this initialization process.
|
||||
For each dependency declared at the curatedDependencyNodeArray, we will initialize a DataSet as part of this initialization process.
|
||||
*/
|
||||
let alreadyCalledBack = false
|
||||
let addCount = 0
|
||||
let skipCount = 0
|
||||
|
||||
/*
|
||||
The current curatedNodeArray that we have includes all the dependencies daclared in the Data Mine | Trading Mine | Learning Mine
|
||||
The current curatedDependencyNodeArray that we have includes all the dependencies daclared in the Data Mine | Trading Mine | Learning Mine
|
||||
process dependencies, minus the ones without reference parent, meaning that references Data Mines that are
|
||||
not present at the workspace. From all the remaining dependencies there will be others that we need to
|
||||
filter out, and they are the ones which the user does not have a data product anywhere on the network where
|
||||
@@ -134,41 +136,97 @@
|
||||
*/
|
||||
let newNodeArray = []
|
||||
|
||||
for (let i = 0; i < thisObject.curatedNodeArray.length; i++) {
|
||||
let dataSetModule = TS.projects.superalgos.processModules.dataset.newSuperalgosProcessModulesDataset(processIndex);
|
||||
dataSetModule.initialize(thisObject.curatedNodeArray[i], onInitilized);
|
||||
let exchangeList = Array.from(thisObject.filters.exchange.list.keys())
|
||||
let marketList = Array.from(thisObject.filters.market.list.keys())
|
||||
|
||||
function onInitilized(err, wasInitialized) {
|
||||
|
||||
if (err.result !== TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE.result) {
|
||||
TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, "[ERROR] initialize -> onInitilized -> err = " + JSON.stringify(err));
|
||||
|
||||
alreadyCalledBack = true;
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wasInitialized === true) {
|
||||
addCount++;
|
||||
newNodeArray.push(thisObject.curatedNodeArray[i])
|
||||
addDataSet()
|
||||
/*
|
||||
For each Exchange / Market we will add the datasets objects to our collection.
|
||||
*/
|
||||
for (let e = 0; e < exchangeList.length; e++) {
|
||||
let exchange = exchangeList[e]
|
||||
for (let m = 0; m < marketList.length; m++) {
|
||||
let market = marketList[m]
|
||||
if (receivedDependencyFilters !== undefined) {
|
||||
/*
|
||||
If we received a Dependency Filter from the UI, we will apply it here so
|
||||
as not to add DataSets that we wont actually need.
|
||||
*/
|
||||
if (thisObject.filters.exchange.markets.get(exchange + '-' + market) === true) {
|
||||
addDataSets(exchange, market)
|
||||
}
|
||||
} else {
|
||||
skipCount++
|
||||
/*
|
||||
If we did not received these dependency filters, like when we are processing
|
||||
Indicators, we will just add all datasets from exchange / market combination
|
||||
because it will only be one combination: the default exchange and the default market.
|
||||
*/
|
||||
addDataSets(exchange, market)
|
||||
}
|
||||
checkIfWeAreDone()
|
||||
}
|
||||
}
|
||||
|
||||
function addDataSet() {
|
||||
thisObject.dataSetsModulesArray.push(dataSetModule);
|
||||
}
|
||||
function addDataSets(exchange, market) {
|
||||
for (let i = 0; i < thisObject.curatedDependencyNodeArray.length; i++) {
|
||||
|
||||
if (receivedDependencyFilters !== undefined) {
|
||||
/*
|
||||
If we received a Dependency Filter from the UI, we will make these excta checks
|
||||
before instantiating a Data Set Module.
|
||||
*/
|
||||
if (exchange === defaultExchange && market === defautMarket) {
|
||||
|
||||
}
|
||||
|
||||
// Validaciones para llegar hasta el producto: datasetModule.node.parentNode.config.singularVariableName
|
||||
// Que el producto este en el filtro
|
||||
// Necesito un filtro exchange mercado producto que venga desde la UI
|
||||
// Para eso la funcion que los arma tiene que saber cual es el default Exchange y el Defautl market.
|
||||
// Quizas vuele el concepto de filtro de chart , de market y de exchange separados
|
||||
|
||||
// dentro del dataset que se valide que el network node que llega hasta el producto pase por el market y exchange
|
||||
|
||||
if (thisObject.filters.exchange.markets.get(exchange + '-' + market) === true) {
|
||||
addDataSets(exchange, market)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
let dataSetModule = TS.projects.superalgos.processModules.dataset.newSuperalgosProcessModulesDataset(processIndex)
|
||||
dataSetModule.initialize(exchange, market, thisObject.curatedDependencyNodeArray[i], onInitilized)
|
||||
|
||||
function onInitilized(err, wasInitialized) {
|
||||
|
||||
if (err.result !== TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE.result) {
|
||||
TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, "[ERROR] initialize -> onInitilized -> err = " + JSON.stringify(err))
|
||||
|
||||
function checkIfWeAreDone() {
|
||||
if (addCount + skipCount === thisObject.curatedNodeArray.length) {
|
||||
if (alreadyCalledBack === false) {
|
||||
alreadyCalledBack = true
|
||||
thisObject.curatedNodeArray = newNodeArray
|
||||
callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE);
|
||||
return;
|
||||
callBackFunction(err)
|
||||
return
|
||||
}
|
||||
|
||||
if (wasInitialized === true) {
|
||||
addCount++
|
||||
newNodeArray.push(thisObject.curatedDependencyNodeArray[i])
|
||||
addDataSet()
|
||||
} else {
|
||||
skipCount++
|
||||
}
|
||||
checkIfWeAreDone()
|
||||
}
|
||||
|
||||
function addDataSet() {
|
||||
thisObject.dataSetsModulesArray.push(dataSetModule)
|
||||
}
|
||||
|
||||
function checkIfWeAreDone() {
|
||||
if (addCount + skipCount === thisObject.curatedDependencyNodeArray.length) {
|
||||
if (alreadyCalledBack === false) {
|
||||
alreadyCalledBack = true
|
||||
thisObject.curatedDependencyNodeArray = newNodeArray
|
||||
callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -176,8 +234,8 @@
|
||||
|
||||
} catch (err) {
|
||||
TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).UNEXPECTED_ERROR = err
|
||||
TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, "[ERROR] initialize -> err = " + err.stack);
|
||||
callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_FAIL_RESPONSE);
|
||||
TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, "[ERROR] initialize -> err = " + err.stack)
|
||||
callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_FAIL_RESPONSE)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,14 +245,14 @@
|
||||
dataSetModule.finalize()
|
||||
}
|
||||
thisObject.dataSetsModulesArray = undefined
|
||||
thisObject.curatedNodeArray = undefined
|
||||
thisObject.curatedDependencyNodeArray = undefined
|
||||
thisObject.filters = undefined
|
||||
bot = undefined
|
||||
}
|
||||
|
||||
function isItADepenency(timeFrame, product) {
|
||||
function isItAChartDepenency(timeFrame, product) {
|
||||
let key = timeFrame + '-' + product
|
||||
|
||||
return thisObject.filters.get(key)
|
||||
return thisObject.filters.chart.products.get(key)
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -9,6 +9,8 @@ exports.newSuperalgosProcessModulesDataset = function (processIndex) {
|
||||
let thisObject = {
|
||||
node: undefined,
|
||||
networkNode: undefined,
|
||||
exchange: undefined,
|
||||
market: undefined,
|
||||
initialize: initialize,
|
||||
finalize: finalize,
|
||||
getTextFile: getTextFile,
|
||||
@@ -20,10 +22,12 @@ exports.newSuperalgosProcessModulesDataset = function (processIndex) {
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(dataDependency, callBackFunction) {
|
||||
function initialize(exchange, market, dataDependency, callBackFunction) {
|
||||
|
||||
try {
|
||||
thisObject.node = dataDependency.referenceParent;
|
||||
thisObject.exchange = exchange
|
||||
thisObject.market = market
|
||||
|
||||
/* Some very basic validations that we have all the information needed. */
|
||||
if (thisObject.node === undefined) {
|
||||
@@ -76,15 +80,18 @@ exports.newSuperalgosProcessModulesDataset = function (processIndex) {
|
||||
|
||||
/* Now we will see where do we need to fetch this data from. */
|
||||
let network = TS.projects.superalgos.globals.taskConstants.NETWORK_NODE
|
||||
let datasetProductDefinition = thisObject.node.parentNode
|
||||
let productDefinition = thisObject.node.parentNode
|
||||
|
||||
let nodeArray = TS.projects.superalgos.utilities.nodeFunctions.nodeMeshToPathArray(network, datasetProductDefinition.id)
|
||||
let networkNode = TS.projects.superalgos.utilities.nodeFunctions.findNodeInNodeArray(nodeArray, 'Network Node')
|
||||
/*
|
||||
We will find the networkNode that leads to this Product Definition
|
||||
and is related to this exchange and market.
|
||||
*/
|
||||
let networkNode = fincNetworkNode(network, productDefinition, thisObject.exchange, thisObject.market)
|
||||
|
||||
if (networkNode === undefined) {
|
||||
TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, "[WARN] initialize -> Network Node not found.")
|
||||
TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, "[WARN] initialize -> Initialization Failed because we could not find where the data of this dataset is located within the network. Check the logs for more info.");
|
||||
TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, "[WARN] initialize -> Could not find where " + datasetProductDefinition.name + " for " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.parentNode.parentNode.name + " " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.baseAsset.referenceParent.config.codeName + "/" + TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.quotedAsset.referenceParent.config.codeName + " is stored within the network.");
|
||||
TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, "[WARN] initialize -> Could not find where " + productDefinition.name + " for " + thisObject.exchange + " " + thisObject.market + " is stored within the network.");
|
||||
callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE, false);
|
||||
return
|
||||
}
|
||||
@@ -105,6 +112,8 @@ exports.newSuperalgosProcessModulesDataset = function (processIndex) {
|
||||
function finalize() {
|
||||
fileStorage = undefined
|
||||
thisObject.networkNode = undefined
|
||||
thisObject.exchange = undefined
|
||||
thisObject.market = undefined
|
||||
bot = undefined
|
||||
thisObject = undefined
|
||||
}
|
||||
@@ -117,7 +126,7 @@ exports.newSuperalgosProcessModulesDataset = function (processIndex) {
|
||||
let project = thisObject.node.parentNode.parentNode.parentNode.project
|
||||
let botCodeName = thisObject.node.parentNode.parentNode.config.codeName
|
||||
|
||||
let filePathRoot = 'Project/' + project + "/" + mineType + "/" + mine + "/" + botCodeName + '/' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.parentNode.parentNode.name + "/" + TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.baseAsset.referenceParent.config.codeName + "-" + TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.quotedAsset.referenceParent.config.codeName
|
||||
let filePathRoot = 'Project/' + project + "/" + mineType + "/" + mine + "/" + botCodeName + '/' + thisObject.exchange + "/" + thisObject.market
|
||||
let filePath = filePathRoot + "/Output/" + pFolderPath;
|
||||
filePath += '/' + pFileName
|
||||
|
||||
@@ -155,7 +164,7 @@ exports.newSuperalgosProcessModulesDataset = function (processIndex) {
|
||||
return;
|
||||
}
|
||||
|
||||
let filePathRoot = 'Project/' + thisObject.node.project + "/" + thisObject.node.mineType + "/" + thisObject.node.dataMine + "/" + thisObject.node.bot + '/' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.parentNode.parentNode.name + "/" + TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.baseAsset.referenceParent.config.codeName + "-" + TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.quotedAsset.referenceParent.config.codeName
|
||||
let filePathRoot = 'Project/' + thisObject.node.project + "/" + thisObject.node.mineType + "/" + thisObject.node.dataMine + "/" + thisObject.node.bot + '/' + thisObject.exchange + "/" + thisObject.market
|
||||
let filePath = filePathRoot + "/Output/" + pFolderPath + '/' + pFileName;
|
||||
|
||||
fileStorage.createTextFile(filePath, pFileContent, onFileCreated);
|
||||
@@ -170,4 +179,140 @@ exports.newSuperalgosProcessModulesDataset = function (processIndex) {
|
||||
callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function fincNetworkNode(network, productDefinition, exchange, market) {
|
||||
/*
|
||||
|
||||
The problem that we need to solve here is the following:
|
||||
|
||||
A. We are interested in a particular Exchange and Market.
|
||||
B. We have the Network we received from the UI whe the user ran the Task.
|
||||
C. We have the Product Definition that is the parent node of the Data Set represented by this object.
|
||||
D. This Product Definition is referenced by one or more Data Products nodes at some branch of the Network Hirierchy.
|
||||
E. We need to find the right Data Product node, the one who is itself a descendent of the Market Data Products
|
||||
node that is referencing the market and exchange that we have as a parameter of this function.
|
||||
|
||||
So, the strategy we will implement is the following:
|
||||
|
||||
1. We will scan all the branches of the Network received from the UI.
|
||||
2. Once we find a Market Data Products, Market Trading Products o Market Learning Products we will check
|
||||
that they are referencing the market and exchange we need, other wise we ignore them and continue
|
||||
with the scanning.
|
||||
3. Once found, we will go into their own branches and find a path until the Product Definition we need to reach.
|
||||
4. Once reached, we will know which Network Node is on the full path from the Network to the Product Definition and
|
||||
we solved the problem.
|
||||
|
||||
*/
|
||||
let found = false
|
||||
let networkNode
|
||||
let splittedMarket = market.split('-')
|
||||
let baseAsset = splittedMarket[0]
|
||||
let quotedAsset = splittedMarket[1]
|
||||
|
||||
scanNodeMesh(network)
|
||||
|
||||
if (found === true) {
|
||||
return networkNode
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
function scanNodeMesh(startingNode) {
|
||||
if (startingNode === undefined) { return }
|
||||
|
||||
let schemaDocument = TS.projects.superalgos.globals.taskConstants.APP_SCHEMA_MAP.get(startingNode.project + '-' + startingNode.type)
|
||||
if (schemaDocument === undefined) { return }
|
||||
|
||||
if (startingNode.id === productDefinition.id) {
|
||||
/*
|
||||
We reached the point that we found a path to the Product Definition.
|
||||
Now we know that the last netwrokNode is the node that has the correct
|
||||
path.
|
||||
*/
|
||||
found = true
|
||||
return
|
||||
}
|
||||
|
||||
if (startingNode.type === 'Network Node') {
|
||||
/*
|
||||
We will store the Network Node here so that if we find the rignt path
|
||||
we can know from which Netwrok Node it going through.
|
||||
*/
|
||||
networkNode = startingNode
|
||||
}
|
||||
|
||||
if (
|
||||
startingNode.type === 'Market Data Products' ||
|
||||
startingNode.type === 'Market Trading Products' ||
|
||||
startingNode.type === 'Market Learning Products'
|
||||
) {
|
||||
/*
|
||||
We will check that this guy is referencing the right market and the
|
||||
market is a descendant of the right exchange. Otherwise we wont process
|
||||
their children.
|
||||
*/
|
||||
if (startingNode.referenceParent === undefined) {
|
||||
return
|
||||
}
|
||||
if (startingNode.referenceParent.baseAsset === undefined) {
|
||||
return
|
||||
}
|
||||
if (startingNode.referenceParent.quotedAsset === undefined) {
|
||||
return
|
||||
}
|
||||
if (startingNode.referenceParent.baseAsset.referenceParent === undefined) {
|
||||
return
|
||||
}
|
||||
if (startingNode.referenceParent.quotedAsset.referenceParent === undefined) {
|
||||
return
|
||||
}
|
||||
if (startingNode.referenceParent.baseAsset.referenceParent.config.codeName !== baseAsset) {
|
||||
return
|
||||
}
|
||||
if (startingNode.referenceParent.quotedAsset.referenceParent.config.codeName !== quotedAsset) {
|
||||
return
|
||||
}
|
||||
if (startingNode.referenceParent.parentNode === undefined) {
|
||||
return
|
||||
}
|
||||
if (startingNode.referenceParent.parentNode.parentNode === undefined) {
|
||||
return
|
||||
}
|
||||
if (startingNode.referenceParent.parentNode.parentNode.codeName !== exchange) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
/* We scan through this node children */
|
||||
if (schemaDocument.childrenNodesProperties !== undefined) {
|
||||
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[i]
|
||||
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
scanNodeMesh(startingNode[property.name])
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
let startingNodePropertyArray = startingNode[property.name]
|
||||
if (startingNodePropertyArray !== undefined) {
|
||||
for (let m = 0; m < startingNodePropertyArray.length; m++) {
|
||||
scanNodeMesh(startingNodePropertyArray[m])
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* We scan parents nodes. */
|
||||
if (startingNode.parentNode !== undefined) {
|
||||
scanNodeMesh(startingNode.parentNode)
|
||||
}
|
||||
/* We scan reference parents too. */
|
||||
if (startingNode.referenceParent !== undefined) {
|
||||
scanNodeMesh(startingNode.referenceParent)
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -103,7 +103,7 @@ exports.newSuperalgosUtilitiesNodeFunctions = function () {
|
||||
|
||||
function nodeMeshToPathArray (node, nodeId) {
|
||||
/*
|
||||
This function scans a node mesh for a certain node if and
|
||||
This function scans a node mesh for a certain node id and
|
||||
returns an array with the path within that mesh to the
|
||||
requested node.
|
||||
*/
|
||||
|
||||
@@ -30,6 +30,7 @@ function newSuperalgosFunctionLibraryDependenciesFilter() {
|
||||
},
|
||||
exchange: {
|
||||
list: new Map(),
|
||||
markets: new Map(),
|
||||
products: new Map()
|
||||
}
|
||||
}
|
||||
@@ -43,6 +44,7 @@ function newSuperalgosFunctionLibraryDependenciesFilter() {
|
||||
filters.market.products = Array.from(filters.market.products.keys())
|
||||
|
||||
filters.exchange.list = Array.from(filters.exchange.list.keys())
|
||||
filters.exchange.markets = Array.from(filters.exchange.markets.keys())
|
||||
filters.exchange.products = Array.from(filters.exchange.products.keys())
|
||||
|
||||
return filters
|
||||
@@ -164,6 +166,7 @@ function newSuperalgosFunctionLibraryDependenciesFilter() {
|
||||
timeFrame = timeFrame.substring(2, 4) + '-' + timeFrame.substring(4, 7)
|
||||
}
|
||||
filters.exchange.products.set(exchange + '-' + baseAsset + '-' + quotedAsset + '-' + timeFrame + '-' + product, true)
|
||||
filters.exchange.markets.set(exchange + '-' + baseAsset + '-' + quotedAsset, true)
|
||||
filters.exchange.list.set(exchange, true)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user