From 541a269f8073fc1aedeb8a8f8146a0a20211786b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 24 Nov 2021 19:41:10 +0100 Subject: [PATCH] Network Node Running Again --- .../Low-Frequency-Trading/Snapshots.js | 2 +- .../Low-Frequency-Trading/TradingEngine.js | 6 +- .../Low-Frequency-Trading/TradingOutput.js | 2 +- .../Low-Frequency-Trading/TradingRecords.js | 2 +- .../TradingSimulation.js | 4 +- .../Low-Frequency-Trading/TradingSystem.js | 2 +- .../API-Data-Fetcher-Bot/FetchingProcess.js | 2 +- .../Indicator-Bot/IndicatorOutput.js | 8 +- .../Indicator-Bot/MultiTimeFrameDaily.js | 2 +- .../Indicator-Bot/MultiTimeFrameMarket.js | 2 +- Projects/Foundations/SA/Globals/Schemas.js | 8 + .../DataDependenciesFunctions.js | 6 +- .../FromOneMinToMultiTimeFrameFunctions.js | 2 +- .../ProcessFilesFunctions.js | 2 +- .../SingleMarketFunctions.js | 12 +- .../Foundations/TS/Globals/TaskConstants.js | 1 - .../TS/Process-Modules/DataDependencies.js | 4 +- .../Foundations/TS/Process-Modules/Dataset.js | 2 +- .../TS/Process-Modules/ProcessOutput.js | 24 +- .../Low-Frequency-Learning/LearningEngine.js | 6 +- .../Low-Frequency-Learning/LearningOutput.js | 2 +- .../Low-Frequency-Learning/LearningRecords.js | 2 +- .../LearningSimulation.js | 4 +- .../Low-Frequency-Learning/LearningSystem.js | 2 +- Projects/Network/SA/Modules/UserProfiles.js | 219 ++++++++++++------ Projects/ProjectsSchema.json | 8 +- .../{TS => SA}/Utilities/NodeFunctions.js | 10 +- TaskServer/TaskServer.js | 4 +- 28 files changed, 220 insertions(+), 130 deletions(-) create mode 100644 Projects/Foundations/SA/Globals/Schemas.js rename Projects/Visual-Scripting/{TS => SA}/Utilities/NodeFunctions.js (93%) diff --git a/Projects/Algorithmic-Trading/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/Snapshots.js b/Projects/Algorithmic-Trading/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/Snapshots.js index a0c7e9de4..db324af90 100644 --- a/Projects/Algorithmic-Trading/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/Snapshots.js +++ b/Projects/Algorithmic-Trading/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/Snapshots.js @@ -150,7 +150,7 @@ exports.newAlgorithmicTradingBotModulesSnapshots = function(processIndex) { } /* Now we go down through all this node children */ - let schemaDocument = TS.projects.foundations.globals.taskConstants.APP_SCHEMA_MAP.get(node.project + '-' + node.type) + let schemaDocument = SA.projects.foundations.globals.schemas.APP_SCHEMA_MAP.get(node.project + '-' + node.type) if (schemaDocument === undefined) { return } if (schemaDocument.childrenNodesProperties !== undefined) { diff --git a/Projects/Algorithmic-Trading/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingEngine.js b/Projects/Algorithmic-Trading/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingEngine.js index ff2312b66..59f511acc 100644 --- a/Projects/Algorithmic-Trading/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingEngine.js +++ b/Projects/Algorithmic-Trading/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingEngine.js @@ -112,7 +112,7 @@ exports.newAlgorithmicTradingBotModulesTradingEngine = function (processIndex) { destinationNode.value = originNode.value /* Now we go down through all the children of the origin node, assuming the destination node has the same children structure*/ - let schemaDocument = TS.projects.foundations.globals.taskConstants.APP_SCHEMA_MAP.get(originNode.project + '-' + originNode.type) + let schemaDocument = SA.projects.foundations.globals.schemas.APP_SCHEMA_MAP.get(originNode.project + '-' + originNode.type) if (schemaDocument === undefined) { return } if (schemaDocument.childrenNodesProperties !== undefined) { @@ -151,7 +151,7 @@ exports.newAlgorithmicTradingBotModulesTradingEngine = function (processIndex) { nodesMap.set(node.id, node) /* Now we go down through all this node children */ - let schemaDocument = TS.projects.foundations.globals.taskConstants.APP_SCHEMA_MAP.get(node.project + '-' + node.type) + let schemaDocument = SA.projects.foundations.globals.schemas.APP_SCHEMA_MAP.get(node.project + '-' + node.type) if (schemaDocument === undefined) { return } if (schemaDocument.childrenNodesProperties !== undefined) { @@ -194,7 +194,7 @@ exports.newAlgorithmicTradingBotModulesTradingEngine = function (processIndex) { } /* Now we go down through all this node children */ - let schemaDocument = TS.projects.foundations.globals.taskConstants.APP_SCHEMA_MAP.get(node.project + '-' + node.type) + let schemaDocument = SA.projects.foundations.globals.schemas.APP_SCHEMA_MAP.get(node.project + '-' + node.type) if (schemaDocument === undefined) { return } if (schemaDocument.childrenNodesProperties !== undefined) { diff --git a/Projects/Algorithmic-Trading/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingOutput.js b/Projects/Algorithmic-Trading/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingOutput.js index 115f3d9b0..71628a8c0 100644 --- a/Projects/Algorithmic-Trading/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingOutput.js +++ b/Projects/Algorithmic-Trading/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingOutput.js @@ -31,7 +31,7 @@ exports.newAlgorithmicTradingBotModulesTradingOutput = function (processIndex) { /* Preparing everything for the Simulation */ let tradingSimulationModuleObject = TS.projects.algorithmicTrading.botModules.tradingSimulation.newAlgorithmicTradingBotModulesTradingSimulation(processIndex) - let outputDatasets = TS.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') + let outputDatasets = SA.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') let outputDatasetsMap = new Map() await TS.projects.foundations.functionLibraries.outputManagementFunctions.readFiles( diff --git a/Projects/Algorithmic-Trading/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingRecords.js b/Projects/Algorithmic-Trading/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingRecords.js index 8c8e4877c..fed2368bc 100644 --- a/Projects/Algorithmic-Trading/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingRecords.js +++ b/Projects/Algorithmic-Trading/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingRecords.js @@ -37,7 +37,7 @@ exports.newAlgorithmicTradingBotModulesTradingRecords = function (processIndex) we have a pointer to the node that have the information we need to extract. Later, based on the product record definition we will extract each individual value. */ - let outputDatasets = TS.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') + let outputDatasets = SA.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') for (let i = 0; i < outputDatasets.length; i++) { let outputDatasetNode = outputDatasets[i] diff --git a/Projects/Algorithmic-Trading/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSimulation.js b/Projects/Algorithmic-Trading/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSimulation.js index 837fdcd0c..83e4c1a30 100644 --- a/Projects/Algorithmic-Trading/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSimulation.js +++ b/Projects/Algorithmic-Trading/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSimulation.js @@ -372,8 +372,8 @@ exports.newAlgorithmicTradingBotModulesTradingSimulation = function (processInde } function positionChart(chart) { - let dataDependencies = TS.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processDependencies, 'Data Dependency') - dataDependencies = TS.projects.visualScripting.utilities.nodeFunctions.filterOutNodeWihtoutReferenceParentFromNodeArray(dataDependencies) + let dataDependencies = SA.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processDependencies, 'Data Dependency') + dataDependencies = SA.projects.visualScripting.utilities.nodeFunctions.filterOutNodeWihtoutReferenceParentFromNodeArray(dataDependencies) /* Finding the Current Element on Daily Files */ if (TS.projects.foundations.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).TRADING_PROCESSING_DAILY_FILES) { diff --git a/Projects/Algorithmic-Trading/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSystem.js b/Projects/Algorithmic-Trading/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSystem.js index c451d7d02..606af9450 100644 --- a/Projects/Algorithmic-Trading/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSystem.js +++ b/Projects/Algorithmic-Trading/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSystem.js @@ -272,7 +272,7 @@ exports.newAlgorithmicTradingBotModulesTradingSystem = function (processIndex) { } /* Now we go down through all this node children */ - let schemaDocument = TS.projects.foundations.globals.taskConstants.APP_SCHEMA_MAP.get(node.project + '-' + node.type) + let schemaDocument = SA.projects.foundations.globals.schemas.APP_SCHEMA_MAP.get(node.project + '-' + node.type) if (schemaDocument === undefined) { return } if (schemaDocument.childrenNodesProperties !== undefined) { diff --git a/Projects/Data-Mining/TS/Bot-Modules/API-Data-Fetcher-Bot/FetchingProcess.js b/Projects/Data-Mining/TS/Bot-Modules/API-Data-Fetcher-Bot/FetchingProcess.js index 13d8bb576..0489a27fe 100644 --- a/Projects/Data-Mining/TS/Bot-Modules/API-Data-Fetcher-Bot/FetchingProcess.js +++ b/Projects/Data-Mining/TS/Bot-Modules/API-Data-Fetcher-Bot/FetchingProcess.js @@ -201,7 +201,7 @@ exports.newDataMiningBotModulesFetchingProcess = function (processIndex) { if (recordProperty.apiResponseFieldReference !== undefined) { if (recordProperty.apiResponseFieldReference.referenceParent !== undefined) { let apiResponseField = recordProperty.apiResponseFieldReference.referenceParent - let endpointNodeFound = TS.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(apiResponseField, 'API Endpoint') + let endpointNodeFound = SA.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(apiResponseField, 'API Endpoint') /* Every Record Property with an apiResponseFieldReference must be on the path to a certain endpoint. diff --git a/Projects/Data-Mining/TS/Bot-Modules/Indicator-Bot/IndicatorOutput.js b/Projects/Data-Mining/TS/Bot-Modules/Indicator-Bot/IndicatorOutput.js index 6e93538bd..a24c8b723 100644 --- a/Projects/Data-Mining/TS/Bot-Modules/Indicator-Bot/IndicatorOutput.js +++ b/Projects/Data-Mining/TS/Bot-Modules/Indicator-Bot/IndicatorOutput.js @@ -52,13 +52,13 @@ } /* The first phase here is about checking that we have everything we need at the definition level. */ - let dataDependencies = TS.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray( + let dataDependencies = SA.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray( TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processDependencies, 'Data Dependency' ) if (TS.projects.foundations.functionLibraries.singleMarketFunctions.validateDataDependencies(processIndex, dataDependencies, callBackFunction) !== true) { return } - let outputDatasets = TS.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray( + let outputDatasets = SA.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray( TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset' ) if (TS.projects.foundations.functionLibraries.singleMarketFunctions.validateOutputDatasets(processIndex, outputDatasets, callBackFunction) !== true) { return } @@ -138,9 +138,9 @@ contextSummary.dataset = outputDatasetNode.referenceParent.config.codeName contextSummary.product = outputDatasetNode.referenceParent.parentNode.config.codeName - let botNode = TS.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDatasetNode, 'Indicator Bot') + let botNode = SA.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDatasetNode, 'Indicator Bot') contextSummary.bot = botNode.config.codeName - let dataMineNode = TS.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDatasetNode, 'Data Mine') + let dataMineNode = SA.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDatasetNode, 'Data Mine') contextSummary.dataMine = dataMineNode.config.codeName contextSummary.mineType = dataMineNode.type.replace(' ', '-') contextSummary.project = dataMineNode.project diff --git a/Projects/Data-Mining/TS/Bot-Modules/Indicator-Bot/MultiTimeFrameDaily.js b/Projects/Data-Mining/TS/Bot-Modules/Indicator-Bot/MultiTimeFrameDaily.js index f0b3d0d0f..207f3ff2f 100644 --- a/Projects/Data-Mining/TS/Bot-Modules/Indicator-Bot/MultiTimeFrameDaily.js +++ b/Projects/Data-Mining/TS/Bot-Modules/Indicator-Bot/MultiTimeFrameDaily.js @@ -513,7 +513,7 @@ } function writeDataRanges(callBack) { - let outputDatasets = TS.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray( + let outputDatasets = SA.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray( TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') let outputDatasetIndex = -1; controlLoop() diff --git a/Projects/Data-Mining/TS/Bot-Modules/Indicator-Bot/MultiTimeFrameMarket.js b/Projects/Data-Mining/TS/Bot-Modules/Indicator-Bot/MultiTimeFrameMarket.js index 9fb933475..254a43563 100644 --- a/Projects/Data-Mining/TS/Bot-Modules/Indicator-Bot/MultiTimeFrameMarket.js +++ b/Projects/Data-Mining/TS/Bot-Modules/Indicator-Bot/MultiTimeFrameMarket.js @@ -151,7 +151,7 @@ function writeTimeFramesFiles(callBack) { let outputDatasets = - TS.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') + SA.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') let outputDatasetIndex = -1; controlLoop() diff --git a/Projects/Foundations/SA/Globals/Schemas.js b/Projects/Foundations/SA/Globals/Schemas.js new file mode 100644 index 000000000..6fb91b966 --- /dev/null +++ b/Projects/Foundations/SA/Globals/Schemas.js @@ -0,0 +1,8 @@ +exports.newFoundationsGlobalsSchemas = function () { + + let thisObject = { + APP_SCHEMA_MAP: new Map() + } + + return thisObject +} \ No newline at end of file diff --git a/Projects/Foundations/TS/Function-Libraries/DataDependenciesFunctions.js b/Projects/Foundations/TS/Function-Libraries/DataDependenciesFunctions.js index 41b6192a4..7ac10f433 100644 --- a/Projects/Foundations/TS/Function-Libraries/DataDependenciesFunctions.js +++ b/Projects/Foundations/TS/Function-Libraries/DataDependenciesFunctions.js @@ -375,14 +375,14 @@ exports.newFoundationsFunctionLibrariesDataDependenciesFunctions = function () { THe first thing we do is to build an array of all the declared dependencies of the Bot Process. */ - let dataDependencies = TS.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processDependencies, 'Data Dependency') + let dataDependencies = SA.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processDependencies, 'Data Dependency') /* Then we will filter out declared dependencies that are not referencing nodes currently present at the workspace. This will allow the user to have less Data Mines loaded at the workspace that the ones that a the Bot process depends on. */ - dataDependencies = TS.projects.visualScripting.utilities.nodeFunctions.filterOutNodeWihtoutReferenceParentFromNodeArray(dataDependencies) + dataDependencies = SA.projects.visualScripting.utilities.nodeFunctions.filterOutNodeWihtoutReferenceParentFromNodeArray(dataDependencies) /* We will run some validations to prevent starting the process if all needed config and nodes are not present. @@ -394,7 +394,7 @@ exports.newFoundationsFunctionLibrariesDataDependenciesFunctions = function () { we do it just to be able to validate that all nodes and config are ok before letting this process run too far. */ - let outputDatasets = TS.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') + let outputDatasets = SA.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') /* Here we check that all output datasets configs are ok. */ diff --git a/Projects/Foundations/TS/Function-Libraries/FromOneMinToMultiTimeFrameFunctions.js b/Projects/Foundations/TS/Function-Libraries/FromOneMinToMultiTimeFrameFunctions.js index 8ed254b7d..1713b694a 100644 --- a/Projects/Foundations/TS/Function-Libraries/FromOneMinToMultiTimeFrameFunctions.js +++ b/Projects/Foundations/TS/Function-Libraries/FromOneMinToMultiTimeFrameFunctions.js @@ -48,7 +48,7 @@ exports.newFoundationsFunctionLibrariesFromOneMinToMultiTimeFrameFunctions = fun node.dataDependency = dataDependenciesModule.curatedDependencyNodeArray[0] } - let outputDatasets = TS.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray( + let outputDatasets = SA.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray( TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset' ) diff --git a/Projects/Foundations/TS/Function-Libraries/ProcessFilesFunctions.js b/Projects/Foundations/TS/Function-Libraries/ProcessFilesFunctions.js index 81dfc978d..8fdc4e16c 100644 --- a/Projects/Foundations/TS/Function-Libraries/ProcessFilesFunctions.js +++ b/Projects/Foundations/TS/Function-Libraries/ProcessFilesFunctions.js @@ -123,7 +123,7 @@ exports.newFoundationsFunctionLibrariesProcessFilesFunctions = function () { async function writeProcessFiles(processIndex, contextVariables, currentTimeFrame, processDate, statusDependencies) { let fileStorage = TS.projects.foundations.taskModules.fileStorage.newFileStorage(processIndex) - let outputDatasets = TS.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') + let outputDatasets = SA.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') await writeTimeFramesFiles() await writeDataRanges() diff --git a/Projects/Foundations/TS/Function-Libraries/SingleMarketFunctions.js b/Projects/Foundations/TS/Function-Libraries/SingleMarketFunctions.js index 11dc25fbf..fa73c9078 100644 --- a/Projects/Foundations/TS/Function-Libraries/SingleMarketFunctions.js +++ b/Projects/Foundations/TS/Function-Libraries/SingleMarketFunctions.js @@ -91,12 +91,12 @@ return } - let botNode = TS.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDatasetNode, 'Indicator Bot') + let botNode = SA.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDatasetNode, 'Indicator Bot') if (botNode === undefined) { - botNode = TS.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDatasetNode, 'Trading Bot') + botNode = SA.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDatasetNode, 'Trading Bot') } if (botNode === undefined) { - botNode = TS.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDatasetNode, 'Learning Bot') + botNode = SA.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDatasetNode, 'Learning Bot') } if (botNode === undefined) { TS.projects.foundations.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, "[ERROR] start -> Product Definition not attached to a Bot. "); @@ -110,11 +110,11 @@ return } - let dataMineNode = TS.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDatasetNode, 'Data Mine') + let dataMineNode = SA.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDatasetNode, 'Data Mine') if (dataMineNode === undefined) { - let tradingMineNode = TS.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDatasetNode, 'Trading Mine') + let tradingMineNode = SA.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDatasetNode, 'Trading Mine') if (tradingMineNode === undefined) { - let learningMineNode = TS.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDatasetNode, 'Learning Mine') + let learningMineNode = SA.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDatasetNode, 'Learning Mine') if (learningMineNode === undefined) { TS.projects.foundations.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, "[ERROR] start -> Bot not attached to a Data Mine, Trading Mine or Learning Mine."); callBackFunction(TS.projects.foundations.globals.standardResponses.DEFAULT_FAIL_RESPONSE); diff --git a/Projects/Foundations/TS/Globals/TaskConstants.js b/Projects/Foundations/TS/Globals/TaskConstants.js index 114787146..a3c8e5cc9 100644 --- a/Projects/Foundations/TS/Globals/TaskConstants.js +++ b/Projects/Foundations/TS/Globals/TaskConstants.js @@ -8,7 +8,6 @@ exports.newFoundationsGlobalsTaskConstants = function () { NETWORK_NODE: undefined, PROJECT_DEFINITION_NODE: undefined, PROJECTS_SCHEMA: undefined, - APP_SCHEMA_MAP: new Map(), EVENT_SERVER_CLIENT_MODULE_OBJECT: undefined, // This is an instance of the Event Server Client pointing to the localhost server TASK_HEARTBEAT_INTERVAL_HANDLER: undefined } diff --git a/Projects/Foundations/TS/Process-Modules/DataDependencies.js b/Projects/Foundations/TS/Process-Modules/DataDependencies.js index 72e77dc56..62df1f3cc 100644 --- a/Projects/Foundations/TS/Process-Modules/DataDependencies.js +++ b/Projects/Foundations/TS/Process-Modules/DataDependencies.js @@ -50,7 +50,7 @@ /* First we will get all the data dependencies of the bot, as defined at the Trading Mine. */ - thisObject.curatedDependencyNodeArray = TS.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processDependencies, 'Data Dependency') + thisObject.curatedDependencyNodeArray = SA.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processDependencies, 'Data Dependency') if (thisObject.curatedDependencyNodeArray.length === 0) { TS.projects.foundations.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.foundations.globals.standardResponses.DEFAULT_FAIL_RESPONSE) @@ -61,7 +61,7 @@ This will allow the user to have less Data Mines loaded at the workspace that the ones that a Trading Mine depends on. */ - thisObject.curatedDependencyNodeArray = TS.projects.visualScripting.utilities.nodeFunctions.filterOutNodeWihtoutReferenceParentFromNodeArray(thisObject.curatedDependencyNodeArray) + thisObject.curatedDependencyNodeArray = SA.projects.visualScripting.utilities.nodeFunctions.filterOutNodeWihtoutReferenceParentFromNodeArray(thisObject.curatedDependencyNodeArray) } else { TS.projects.foundations.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.") diff --git a/Projects/Foundations/TS/Process-Modules/Dataset.js b/Projects/Foundations/TS/Process-Modules/Dataset.js index 685777744..74c76193a 100644 --- a/Projects/Foundations/TS/Process-Modules/Dataset.js +++ b/Projects/Foundations/TS/Process-Modules/Dataset.js @@ -222,7 +222,7 @@ exports.newFoundationsProcessModulesDataset = function (processIndex) { function scanNodeMesh(startingNode) { if (startingNode === undefined) { return } - let schemaDocument = TS.projects.foundations.globals.taskConstants.APP_SCHEMA_MAP.get(startingNode.project + '-' + startingNode.type) + let schemaDocument = SA.projects.foundations.globals.schemas.APP_SCHEMA_MAP.get(startingNode.project + '-' + startingNode.type) if (schemaDocument === undefined) { return } if (startingNode.id === productDefinition.id) { diff --git a/Projects/Foundations/TS/Process-Modules/ProcessOutput.js b/Projects/Foundations/TS/Process-Modules/ProcessOutput.js index 876af534d..c76eee859 100644 --- a/Projects/Foundations/TS/Process-Modules/ProcessOutput.js +++ b/Projects/Foundations/TS/Process-Modules/ProcessOutput.js @@ -18,23 +18,23 @@ /* We will raise the events for the datasets impacted by the process that just finished. */ if (TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput !== undefined) { - let outputDatasets = TS.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') + let outputDatasets = SA.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') for (let j = 0; j < outputDatasets.length; j++) { let outputDataset = outputDatasets[j] - let botNode = TS.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDataset, 'Indicator Bot') + let botNode = SA.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDataset, 'Indicator Bot') if (botNode === undefined) { - botNode = TS.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDataset, 'Trading Bot') + botNode = SA.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDataset, 'Trading Bot') } if (botNode === undefined) { - botNode = TS.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDataset, 'Sensor Bot') + botNode = SA.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDataset, 'Sensor Bot') } if (botNode === undefined) { - botNode = TS.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDataset, 'API Data Fetcher Bot') + botNode = SA.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDataset, 'API Data Fetcher Bot') } if (botNode === undefined) { - botNode = TS.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDataset, 'Learning Bot') + botNode = SA.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDataset, 'Learning Bot') } /* Some validations to verify that everything is in place. */ @@ -112,23 +112,23 @@ function asyncRaiseEvents(lastFile, timeFrames) { if (TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput !== undefined) { - let outputDatasets = TS.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') + let outputDatasets = SA.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') for (let j = 0; j < outputDatasets.length; j++) { let outputDataset = outputDatasets[j] - let botNode = TS.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDataset, 'Indicator Bot') + let botNode = SA.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDataset, 'Indicator Bot') if (botNode === undefined) { - botNode = TS.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDataset, 'Trading Bot') + botNode = SA.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDataset, 'Trading Bot') } if (botNode === undefined) { - botNode = TS.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDataset, 'Sensor Bot') + botNode = SA.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDataset, 'Sensor Bot') } if (botNode === undefined) { - botNode = TS.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDataset, 'API Data Fetcher Bot') + botNode = SA.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDataset, 'API Data Fetcher Bot') } if (botNode === undefined) { - botNode = TS.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDataset, 'Learning Bot') + botNode = SA.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(outputDataset, 'Learning Bot') } /* Some validations to verify that everything is in place. */ diff --git a/Projects/Machine-Learning/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/LearningEngine.js b/Projects/Machine-Learning/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/LearningEngine.js index b82a4c8af..0d4d2c691 100644 --- a/Projects/Machine-Learning/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/LearningEngine.js +++ b/Projects/Machine-Learning/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/LearningEngine.js @@ -111,7 +111,7 @@ exports.newMachineLearningBotModulesLearningEngine = function (processIndex) { destinationNode.value = originNode.value /* Now we go down through all the children of the origin node, assuming the destination node has the same children structure*/ - let schemaDocument = TS.projects.foundations.globals.taskConstants.APP_SCHEMA_MAP.get(originNode.project + '-' + originNode.type) + let schemaDocument = SA.projects.foundations.globals.schemas.APP_SCHEMA_MAP.get(originNode.project + '-' + originNode.type) if (schemaDocument === undefined) { return } if (schemaDocument.childrenNodesProperties !== undefined) { @@ -150,7 +150,7 @@ exports.newMachineLearningBotModulesLearningEngine = function (processIndex) { nodesMap.set(node.id, node) /* Now we go down through all this node children */ - let schemaDocument = TS.projects.foundations.globals.taskConstants.APP_SCHEMA_MAP.get(node.project + '-' + node.type) + let schemaDocument = SA.projects.foundations.globals.schemas.APP_SCHEMA_MAP.get(node.project + '-' + node.type) if (schemaDocument === undefined) { return } if (schemaDocument.childrenNodesProperties !== undefined) { @@ -193,7 +193,7 @@ exports.newMachineLearningBotModulesLearningEngine = function (processIndex) { } /* Now we go down through all this node children */ - let schemaDocument = TS.projects.foundations.globals.taskConstants.APP_SCHEMA_MAP.get(node.project + '-' + node.type) + let schemaDocument = SA.projects.foundations.globals.schemas.APP_SCHEMA_MAP.get(node.project + '-' + node.type) if (schemaDocument === undefined) { return } if (schemaDocument.childrenNodesProperties !== undefined) { diff --git a/Projects/Machine-Learning/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/LearningOutput.js b/Projects/Machine-Learning/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/LearningOutput.js index a553ead09..ddae66359 100644 --- a/Projects/Machine-Learning/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/LearningOutput.js +++ b/Projects/Machine-Learning/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/LearningOutput.js @@ -31,7 +31,7 @@ exports.newMachineLearningBotModulesLearningOutput = function (processIndex) { /* Preparing everything for the Simulation */ let learningSimulationModuleObject = TS.projects.machineLearning.botModules.learningSimulation.newMachineLearningBotModulesLearningSimulation(processIndex) - let outputDatasets = TS.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') + let outputDatasets = SA.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') let outputDatasetsMap = new Map() await TS.projects.foundations.functionLibraries.outputManagementFunctions.readFiles( diff --git a/Projects/Machine-Learning/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/LearningRecords.js b/Projects/Machine-Learning/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/LearningRecords.js index c7fdbd726..f0d9eb1ed 100644 --- a/Projects/Machine-Learning/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/LearningRecords.js +++ b/Projects/Machine-Learning/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/LearningRecords.js @@ -37,7 +37,7 @@ exports.newMachineLearningBotModulesLearningRecords = function (processIndex) { we have a pointer to the node that have the information we need to extract. Later, based on the product record definition we will extract each individual value. */ - let outputDatasets = TS.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') + let outputDatasets = SA.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') for (let i = 0; i < outputDatasets.length; i++) { let outputDatasetNode = outputDatasets[i] diff --git a/Projects/Machine-Learning/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/LearningSimulation.js b/Projects/Machine-Learning/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/LearningSimulation.js index 4ae1809e7..a3e6b2cc6 100644 --- a/Projects/Machine-Learning/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/LearningSimulation.js +++ b/Projects/Machine-Learning/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/LearningSimulation.js @@ -381,8 +381,8 @@ exports.newMachineLearningBotModulesLearningSimulation = function (processIndex) } function positionChart(chart) { - let dataDependencies = TS.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processDependencies, 'Data Dependency') - dataDependencies = TS.projects.visualScripting.utilities.nodeFunctions.filterOutNodeWihtoutReferenceParentFromNodeArray(dataDependencies) + let dataDependencies = SA.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processDependencies, 'Data Dependency') + dataDependencies = SA.projects.visualScripting.utilities.nodeFunctions.filterOutNodeWihtoutReferenceParentFromNodeArray(dataDependencies) /* Finding the Current Element on Market Files */ if (TS.projects.foundations.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).TRADING_PROCESSING_DAILY_FILES) { diff --git a/Projects/Machine-Learning/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/LearningSystem.js b/Projects/Machine-Learning/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/LearningSystem.js index 32c3539f6..d7c0a8939 100644 --- a/Projects/Machine-Learning/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/LearningSystem.js +++ b/Projects/Machine-Learning/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/LearningSystem.js @@ -292,7 +292,7 @@ exports.newMachineLearningBotModulesLearningSystem = function (processIndex) { } /* Now we go down through all this node children */ - let schemaDocument = TS.projects.foundations.globals.taskConstants.APP_SCHEMA_MAP.get(node.project + '-' + node.type) + let schemaDocument = SA.projects.foundations.globals.schemas.APP_SCHEMA_MAP.get(node.project + '-' + node.type) if (schemaDocument === undefined) { return } if (schemaDocument.childrenNodesProperties !== undefined) { diff --git a/Projects/Network/SA/Modules/UserProfiles.js b/Projects/Network/SA/Modules/UserProfiles.js index 5292f4127..4f2b55195 100644 --- a/Projects/Network/SA/Modules/UserProfiles.js +++ b/Projects/Network/SA/Modules/UserProfiles.js @@ -20,88 +20,161 @@ exports.newNetworkModulesUserProfiles = function newNetworkModulesUserProfiles() async function initialize(nodeCodeName, p2pNetworkIdentity) { - let pluginFileNames = await SA.projects.communityPlugins.utilities.plugins.getPluginFileNames( - 'Governance', - 'User-Profiles' - ) + await loadAppSchemas() + await loadProfiles() - for (let i = 0; i < pluginFileNames.length; i++) { - let pluginFileName = pluginFileNames[i] + async function loadAppSchemas() { - let pluginFileContent = await SA.projects.communityPlugins.utilities.plugins.getPluginFileContent( - 'Governance', - 'User-Profiles', - pluginFileName - ) + let promise = new Promise((resolve, reject) => { - let userProfilePlugin = JSON.parse(pluginFileContent) - let config = JSON.parse(userProfilePlugin.config) - let signatureObject = config.signature - let web3 = new SA.nodeModules.web3() - let blockchainAccount = web3.eth.accounts.recover(signatureObject) - let ranking = 0 // TODO: read the blockchain balance and transactions from the Treasury Account to calculate the profile ranking. - let userProfileId = userProfilePlugin.id - let userHandle = config.signature.message + let project = 'Governance' + let filePath = global.env.PATH_TO_PROJECTS + '/' + project + '/Schemas/' + let folder = 'App-Schema' - let userProfile = SA.projects.socialTrading.modules.socialGraphUserProfile.newSocialTradingModulesSocialGraphUserProfile() - userProfile.initialize( - userProfileId, - userHandle, - blockchainAccount, - ranking - ) + SA.projects.foundations.utilities.filesAndDirectories.getAllFilesInDirectoryAndSubdirectories(filePath + folder, onFilesReady) - SA.projects.network.globals.memory.maps.USER_PROFILES_BY_ID.set(userProfileId, userProfile) - SA.projects.network.globals.memory.maps.USER_PROFILES_BY_HANDLE.set(userHandle, userProfile) - SA.projects.network.globals.memory.maps.USER_PROFILES_BY_BLOKCHAIN_ACCOUNT.set(blockchainAccount, userProfile) - /* - Each User Profile might have Signing Accounts, meaning - accounts that can sign on behalf of the User Profile. - */ - if (userProfilePlugin.signingAccounts !== undefined) { - for (let j = 0; j < userProfilePlugin.signingAccounts.signingAccounts.length; j++) { - let signingAccount = userProfilePlugin.signingAccounts.signingAccounts[j] - let config = JSON.parse(signingAccount.config) - let signatureObject = config.signature - let web3 = new SA.nodeModules.web3() - let blockchainAccount = web3.eth.accounts.recover(signatureObject) - SA.projects.network.globals.memory.maps.USER_PROFILES_BY_BLOKCHAIN_ACCOUNT.set(blockchainAccount, userProfile) - /* - If the Signing Account is for a P2P node, we will add the node to the array of available nodes at the p2p network. - */ - if ( - signingAccount.referenceParent !== undefined && - signingAccount.referenceParent.type === "P2P Network Node" && - signingAccount.referenceParent.config !== undefined - ) { - let config + function onFilesReady(files) { + + for (let k = 0; k < files.length; k++) { + let name = files[k] + let nameSplitted = name.split(folder) + let fileName = nameSplitted[1] + for (let i = 0; i < 10; i++) { + fileName = fileName.replace('\\', '/') + } + let fileToRead = filePath + folder + fileName + + let fileContent = SA.nodeModules.fs.readFileSync(fileToRead) + let schemaDocument try { - config = JSON.parse(signingAccount.referenceParent.config) + schemaDocument = JSON.parse(fileContent) + SA.projects.foundations.globals.schemas.APP_SCHEMA_MAP.set(project + '-' + schemaDocument.type, schemaDocument) } catch (err) { - console.log('P2P Network Node Config not in JSON format. userProfileHandle = ' + userHandle + ' NodeId = ' + signingAccount.referenceParent.id) - continue + console.log('[WARN] loadAppSchemas -> Error Parsing JSON File: ' + fileToRead + '. Error = ' + err.stack) + return } - if (config.host === undefined) { - continue - } - if (config.webSocketsPort === undefined) { - continue - } - - let p2pNetworkNode = SA.projects.network.modules.p2pNetworkNode.newNetworkModulesP2PNetworkNode() - p2pNetworkNode.initialize(signingAccount.referenceParent, userProfile, blockchainAccount) - SA.projects.network.globals.memory.arrays.P2P_NETWORK_NODES.push(p2pNetworkNode) } - /* - Now, we will extract the information from the User Profile, specifically of our identity at the p2p network. - */ - if ( - signingAccount.referenceParent !== undefined && - signingAccount.referenceParent.id === SA.secrets.map.get(nodeCodeName).nodeId - ) { - p2pNetworkIdentity.node = signingAccount.referenceParent - p2pNetworkIdentity.blockchainAccount = blockchainAccount - p2pNetworkIdentity.userProfile = userProfile + resolve() + } + } + ) + return promise + } + + async function loadProfiles() { + + let pluginFileNames = await SA.projects.communityPlugins.utilities.plugins.getPluginFileNames( + 'Governance', + 'User-Profiles' + ) + + for (let i = 0; i < pluginFileNames.length; i++) { + let pluginFileName = pluginFileNames[i] + + let pluginFileContent = await SA.projects.communityPlugins.utilities.plugins.getPluginFileContent( + 'Governance', + 'User-Profiles', + pluginFileName + ) + + let userProfilePlugin = JSON.parse(pluginFileContent) + let config = JSON.parse(userProfilePlugin.config) + let signatureObject = config.signature + let web3 = new SA.nodeModules.web3() + let blockchainAccount = web3.eth.accounts.recover(signatureObject) + let ranking = 0 // TODO: read the blockchain balance and transactions from the Treasury Account to calculate the profile ranking. + let userProfileId = userProfilePlugin.id + let userHandle = config.signature.message + + let userProfile = SA.projects.socialTrading.modules.socialGraphUserProfile.newSocialTradingModulesSocialGraphUserProfile() + userProfile.initialize( + userProfileId, + userHandle, + blockchainAccount, + ranking + ) + + SA.projects.network.globals.memory.maps.USER_PROFILES_BY_ID.set(userProfileId, userProfile) + SA.projects.network.globals.memory.maps.USER_PROFILES_BY_HANDLE.set(userHandle, userProfile) + SA.projects.network.globals.memory.maps.USER_PROFILES_BY_BLOKCHAIN_ACCOUNT.set(blockchainAccount, userProfile) + /* + Each User Profile might have Signing Accounts, meaning + accounts that can sign on behalf of the User Profile. + */ + if (userProfilePlugin.signingAccounts !== undefined) { + + let algoTradersPlatform = SA.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(userProfilePlugin.userApps, 'Algo Traders Platform') + let socialTradingDesktopApp = SA.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(userProfilePlugin.userApps, 'Social Trading Desktop App') + let socialTradingMobileApp = SA.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(userProfilePlugin.userApps, 'Social Trading Mobile App') + let socialTradingServerApp = SA.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(userProfilePlugin.userApps, 'Social Trading Server App') + let socialTradingBots = SA.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(userProfilePlugin.userBots, 'Social Trading Bot') + let socialPersonas = SA.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(userProfilePlugin.socialPersonas, 'Social Persona') + let p2pNetworkNodes = SA.projects.visualScripting.utilities.nodeFunctions.nodeBranchToArray(userProfilePlugin.p2pNetworkNodes, 'P2P Network Node') + + let networkClientsMap = new Map() + + addToNetworkClientMap(algoTradersPlatform, 'Algo Traders Platform') + addToNetworkClientMap(socialTradingDesktopApp, 'Social Trading Desktop App') + addToNetworkClientMap(socialTradingMobileApp, 'Social Trading Mobile App') + addToNetworkClientMap(socialTradingServerApp, 'Social Trading Server App') + addToNetworkClientMap(socialTradingBots, 'Social Trading Bot') + addToNetworkClientMap(socialPersonas, 'Social Persona') + addToNetworkClientMap(p2pNetworkNodes, 'P2P Network Node') + + function addToNetworkClientMap(nodeArray) { + for (let i = 0; i < nodeArray.length; i++) { + let currentNode = nodeArray[i] + networkClientsMap.set(currentNode.id, currentNode) + } + } + + for (let j = 0; j < userProfilePlugin.signingAccounts.signingAccounts.length; j++) { + let signingAccount = userProfilePlugin.signingAccounts.signingAccounts[j] + let config = JSON.parse(signingAccount.config) + let signatureObject = config.signature + let web3 = new SA.nodeModules.web3() + let blockchainAccount = web3.eth.accounts.recover(signatureObject) + SA.projects.network.globals.memory.maps.USER_PROFILES_BY_BLOKCHAIN_ACCOUNT.set(blockchainAccount, userProfile) + /* + If the Signing Account is for a P2P node, we will add the node to the array of available nodes at the p2p network. + */ + if (signingAccount.savedPayload === undefined) { continue } + if (signingAccount.savedPayload.referenceParent === undefined) { continue } + signingAccount.referenceParent = networkClientsMap.get(signingAccount.savedPayload.referenceParent.id) + if ( + signingAccount.referenceParent !== undefined && + signingAccount.referenceParent.type === "P2P Network Node" && + signingAccount.referenceParent.config !== undefined + ) { + let config + try { + config = JSON.parse(signingAccount.referenceParent.config) + } catch (err) { + console.log('P2P Network Node Config not in JSON format. userProfileHandle = ' + userHandle + ' NodeId = ' + signingAccount.referenceParent.id) + continue + } + if (config.host === undefined) { + continue + } + if (config.webSocketsPort === undefined) { + continue + } + + let p2pNetworkNode = SA.projects.network.modules.p2pNetworkNode.newNetworkModulesP2PNetworkNode() + p2pNetworkNode.initialize(signingAccount.referenceParent, userProfile, blockchainAccount) + SA.projects.network.globals.memory.arrays.P2P_NETWORK_NODES.push(p2pNetworkNode) + } + /* + Now, we will extract the information from the User Profile, specifically of our identity at the p2p network. + */ + if ( + signingAccount.referenceParent !== undefined && + signingAccount.referenceParent.id === SA.secrets.map.get(nodeCodeName).nodeId + ) { + p2pNetworkIdentity.node = signingAccount.referenceParent + p2pNetworkIdentity.blockchainAccount = blockchainAccount + p2pNetworkIdentity.userProfile = userProfile + } } } } diff --git a/Projects/ProjectsSchema.json b/Projects/ProjectsSchema.json index 95127a643..0d393a901 100644 --- a/Projects/ProjectsSchema.json +++ b/Projects/ProjectsSchema.json @@ -329,7 +329,7 @@ } ] }, - "TS": { + "SA": { "utilities": [ { "name": "Node Functions", @@ -795,6 +795,12 @@ "propertyName": "timeConstants", "functionName": "newFoundationsGlobalsTimeConstants", "fileName": "TimeConstants.js" + }, + { + "name": "Schemas", + "propertyName": "schemas", + "functionName": "newFoundationsGlobalsSchemas", + "fileName": "Schemas.js" } ], "utilities": [ diff --git a/Projects/Visual-Scripting/TS/Utilities/NodeFunctions.js b/Projects/Visual-Scripting/SA/Utilities/NodeFunctions.js similarity index 93% rename from Projects/Visual-Scripting/TS/Utilities/NodeFunctions.js rename to Projects/Visual-Scripting/SA/Utilities/NodeFunctions.js index 0d87560ab..f5d457e1a 100644 --- a/Projects/Visual-Scripting/TS/Utilities/NodeFunctions.js +++ b/Projects/Visual-Scripting/SA/Utilities/NodeFunctions.js @@ -16,7 +16,11 @@ exports.newVisualScriptingUtilitiesNodeFunctions = function () { return resultArray function scanNodeBranch(startingNode) { - let schemaDocument = TS.projects.foundations.globals.taskConstants.APP_SCHEMA_MAP.get(startingNode.project + '-' + startingNode.type) + if (startingNode === undefined) { + return + } + + let schemaDocument = SA.projects.foundations.globals.schemas.APP_SCHEMA_MAP.get(startingNode.project + '-' + startingNode.type) if (schemaDocument === undefined) { return } if (startingNode.type === nodeType) { @@ -60,7 +64,7 @@ exports.newVisualScriptingUtilitiesNodeFunctions = function () { if (startingNode === undefined) { return } if (nodeFound !== undefined) { return } - let schemaDocument = TS.projects.foundations.globals.taskConstants.APP_SCHEMA_MAP.get(startingNode.project + '-' + startingNode.type) + let schemaDocument = SA.projects.foundations.globals.schemas.APP_SCHEMA_MAP.get(startingNode.project + '-' + startingNode.type) if (schemaDocument === undefined) { return } if (startingNode.type === nodeType) { @@ -114,7 +118,7 @@ exports.newVisualScriptingUtilitiesNodeFunctions = function () { function scanNodeMesh(startingNode) { if (startingNode === undefined) { return } - let schemaDocument = TS.projects.foundations.globals.taskConstants.APP_SCHEMA_MAP.get(startingNode.project + '-' + startingNode.type) + let schemaDocument = SA.projects.foundations.globals.schemas.APP_SCHEMA_MAP.get(startingNode.project + '-' + startingNode.type) if (schemaDocument === undefined) { return } if (startingNode.id === nodeId) { diff --git a/TaskServer/TaskServer.js b/TaskServer/TaskServer.js index c9e327ed6..463058c99 100644 --- a/TaskServer/TaskServer.js +++ b/TaskServer/TaskServer.js @@ -76,7 +76,7 @@ exports.newTaskServer = function newTaskServer() { for (let j = 0; j < project.schema.length; j++) { let schemaDocument = project.schema[j] let key = project.name + '-' + schemaDocument.type - TS.projects.foundations.globals.taskConstants.APP_SCHEMA_MAP.set(key, schemaDocument) + SA.projects.foundations.globals.schemas.APP_SCHEMA_MAP.set(key, schemaDocument) } } } @@ -88,7 +88,7 @@ exports.newTaskServer = function newTaskServer() { setupTaskHeartbeats() function initializeProjectDefinitionNode() { - TS.projects.foundations.globals.taskConstants.PROJECT_DEFINITION_NODE = TS.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(TS.projects.foundations.globals.taskConstants.TASK_NODE, 'Project Definition') + TS.projects.foundations.globals.taskConstants.PROJECT_DEFINITION_NODE = SA.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(TS.projects.foundations.globals.taskConstants.TASK_NODE, 'Project Definition') if (TS.projects.foundations.globals.taskConstants.PROJECT_DEFINITION_NODE === undefined) { console.log("[ERROR] Task Server -> Task -> bootingProcess -> Project Definition not found. ") TS.projects.foundations.globals.taskVariables.FATAL_ERROR_MESSAGE = 'Project Definition not found. Fatal Error, can not continue. Fix the problem and try again.'