From c7bc3ea93b84861c68ae2420a28de60d1fdae450 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 13 Sep 2020 19:30:53 +0200 Subject: [PATCH] Session Reference --- ChartingSpace/PlottersManager.js | 2 +- .../FunctionLibraries/DataStorageFunctions.js | 30 +++++++++- DesignSpace/Workspace/Workspace.js | 5 ++ Panels/Layer.js | 26 ++++---- Utilities/Branches.js | 4 ++ Utilities/Hiriarchy.js | 7 ++- Utilities/Meshes.js | 60 ++++++++++++------- 7 files changed, 95 insertions(+), 39 deletions(-) diff --git a/ChartingSpace/PlottersManager.js b/ChartingSpace/PlottersManager.js index 09abb9b7a..476169fd4 100644 --- a/ChartingSpace/PlottersManager.js +++ b/ChartingSpace/PlottersManager.js @@ -144,7 +144,7 @@ function newPlottersManager() { A layer can be referencing a Data Product in two different branches of the Network hiriatchy. In one of those braches we can get the Session node, at the other we Cannot. */ - let sessionReference = findNodeInNodeMesh(layer.definition, 'Session Reference') + let sessionReference = findNodeInNodeMesh(layer.definition, 'Session Reference', false, true, true, true) if (sessionReference !== undefined) { session = sessionReference.referenceParent diff --git a/DesignSpace/Workspace/FunctionLibraries/DataStorageFunctions.js b/DesignSpace/Workspace/FunctionLibraries/DataStorageFunctions.js index 37b9b0acb..d2257e0c4 100644 --- a/DesignSpace/Workspace/FunctionLibraries/DataStorageFunctions.js +++ b/DesignSpace/Workspace/FunctionLibraries/DataStorageFunctions.js @@ -1,7 +1,8 @@ function newDataStorageFunctions() { thisObject = { addAllDataProducts: addAllDataProducts, - addAllDataMineProducts: addAllDataMineProducts + addAllDataMineProducts: addAllDataMineProducts, + addMissingSessionReferences: addMissingSessionReferences } return thisObject @@ -55,11 +56,36 @@ function newDataStorageFunctions() { function addAllDataMineProducts(node, rootNodes, functionLibraryUiObjectsFromNodes) { for (let i = 0; i < rootNodes.length; i++) { let rootNode = rootNodes[i] - + if (rootNode.type === 'Data Mine') { let dataMineProducts = functionLibraryUiObjectsFromNodes.addUIObject(node, 'Data Mine Products') dataMineProducts.payload.referenceParent = rootNode } } } + + function addMissingSessionReferences(node, rootNodes, functionLibraryUiObjectsFromNodes) { + let networkNode = findNodeInNodeMesh(node, 'Network Node', true, false, true, false) + if (networkNode === undefined) {return} + + let backtestingSessionsArray = nodeBranchToArray(networkNode, 'Backtesting Session') + let fordwardTestingSessionsArray = nodeBranchToArray(networkNode, 'Fordward Testing Session') + let paperTradingSessionsArray = nodeBranchToArray(networkNode, 'Paper Trading Session') + let liveTradingSessionsArray = nodeBranchToArray(networkNode, 'Live Trading Session') + + addMissingSession(backtestingSessionsArray) + addMissingSession(fordwardTestingSessionsArray) + addMissingSession(paperTradingSessionsArray) + addMissingSession(liveTradingSessionsArray) + + function addMissingSession(sessionsArray) { + for (let i = 0; i < sessionsArray.length; i++) { + let session = sessionsArray[i] + if (isMissingChildren(node, session, true) === true) { + let sessionReference = functionLibraryUiObjectsFromNodes.addUIObject(node, 'Session Reference') + sessionReference.payload.referenceParent = session + } + } + } + } } diff --git a/DesignSpace/Workspace/Workspace.js b/DesignSpace/Workspace/Workspace.js index 9291f2c88..2f71bbcd1 100644 --- a/DesignSpace/Workspace/Workspace.js +++ b/DesignSpace/Workspace/Workspace.js @@ -716,6 +716,11 @@ function newWorkspace() { functionLibraryDataStorageFunctions.addAllDataMineProducts(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryUiObjectsFromNodes) } break + case 'Add Missing Session References': + { + functionLibraryDataStorageFunctions.addMissingSessionReferences(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryUiObjectsFromNodes) + } + break case 'Add All Data Dependencies': { functionLibraryDataMineFunctions.addAllDataDependencies(payload.node, functionLibraryUiObjectsFromNodes) diff --git a/Panels/Layer.js b/Panels/Layer.js index 57a6107ae..c90adf702 100644 --- a/Panels/Layer.js +++ b/Panels/Layer.js @@ -205,49 +205,49 @@ function newLayer() { } /* Here we validate that we have all the needed information */ - if (findNodeInNodeMesh(thisObject.definition, 'Data Product') === undefined) { + if (findNodeInNodeMesh(thisObject.definition, 'Data Product', false, true, true, true) === undefined) { thisObject.payload.uiObject.setErrorMessage('Data Product not Found') return } - if (findNodeInNodeMesh(thisObject.definition, 'Market') === undefined) { + if (findNodeInNodeMesh(thisObject.definition, 'Market', false, true, true, true) === undefined) { thisObject.payload.uiObject.setErrorMessage('Market not Found') return } - thisObject.productDefinition = findNodeInNodeMesh(thisObject.definition, 'Product Definition') + thisObject.productDefinition = findNodeInNodeMesh(thisObject.definition, 'Product Definition', false, true, true, true) if (thisObject.productDefinition === undefined) { thisObject.payload.uiObject.setErrorMessage('Product Definition not Found') return } - thisObject.bot = findNodeInNodeMesh(thisObject.definition, 'Sensor Bot') + thisObject.bot = findNodeInNodeMesh(thisObject.definition, 'Sensor Bot', false, true, true, true) if (thisObject.bot === undefined) { - thisObject.bot = findNodeInNodeMesh(thisObject.definition, 'Indicator Bot') + thisObject.bot = findNodeInNodeMesh(thisObject.definition, 'Indicator Bot', false, true, true, true) } if (thisObject.bot === undefined) { - thisObject.bot = findNodeInNodeMesh(thisObject.definition, 'Trading Bot') + thisObject.bot = findNodeInNodeMesh(thisObject.definition, 'Trading Bot', false, true, true, true) } if (thisObject.bot === undefined) { thisObject.payload.uiObject.setErrorMessage('Bot not Found') return } - thisObject.dataMine = findNodeInNodeMesh(thisObject.definition, 'Data Mine') + thisObject.dataMine = findNodeInNodeMesh(thisObject.definition, 'Data Mine', false, true, true, true) if (thisObject.dataMine === undefined) { - thisObject.dataMine = findNodeInNodeMesh(thisObject.definition, 'Trading Mine') + thisObject.dataMine = findNodeInNodeMesh(thisObject.definition, 'Trading Mine', false, true, true, true) if (thisObject.dataMine === undefined) { thisObject.payload.uiObject.setErrorMessage('Data Mine or Trading Mine not Found') return } } - thisObject.exchange = findNodeInNodeMesh(thisObject.definition, 'Crypto Exchange') + thisObject.exchange = findNodeInNodeMesh(thisObject.definition, 'Crypto Exchange', false, true, true, true) if (thisObject.exchange === undefined) { thisObject.payload.uiObject.setErrorMessage('Crypto Exchange not Found') return } - thisObject.baseAsset = findNodeInNodeMesh(thisObject.definition, 'Market Base Asset') + thisObject.baseAsset = findNodeInNodeMesh(thisObject.definition, 'Market Base Asset', false, true, true, true) if (thisObject.baseAsset !== undefined) { thisObject.baseAsset = thisObject.baseAsset.referenceParent } @@ -256,7 +256,7 @@ function newLayer() { return } - thisObject.quotedAsset = findNodeInNodeMesh(thisObject.definition, 'Market Quoted Asset') + thisObject.quotedAsset = findNodeInNodeMesh(thisObject.definition, 'Market Quoted Asset', false, true, true, true) if (thisObject.quotedAsset !== undefined) { thisObject.quotedAsset = thisObject.quotedAsset.referenceParent } @@ -265,13 +265,13 @@ function newLayer() { return } - thisObject.plotterModule = findNodeInNodeMesh(thisObject.definition, 'Plotter Module') + thisObject.plotterModule = findNodeInNodeMesh(thisObject.definition, 'Plotter Module', false, true, true, true) if (thisObject.plotterModule === undefined) { thisObject.payload.uiObject.setErrorMessage('Market Quoted Asset not Found') return } - thisObject.networkNode = findNodeInNodeMesh(thisObject.definition, 'Network Node') + thisObject.networkNode = findNodeInNodeMesh(thisObject.definition, 'Network Node', false, true, true, true) if (thisObject.networkNode === undefined) { thisObject.payload.uiObject.setErrorMessage('Network Node not Found') return diff --git a/Utilities/Branches.js b/Utilities/Branches.js index 71123093d..e51b34012 100644 --- a/Utilities/Branches.js +++ b/Utilities/Branches.js @@ -3,11 +3,15 @@ function nodeBranchToArray(node, nodeType) { This function scans a node branch for a certain node type and return an array of with all the nodes of that type found. */ + if (node === undefined) { return } + if (nodeType === undefined) { return } let resultArray = [] scanNodeBranch(node, nodeType) return resultArray function scanNodeBranch(startingNode) { + if (startingNode === undefined) {return} + let nodeDefinition = APP_SCHEMA_MAP.get(startingNode.type) if (nodeDefinition === undefined) { return } diff --git a/Utilities/Hiriarchy.js b/Utilities/Hiriarchy.js index 1c4665a77..e37b075fb 100644 --- a/Utilities/Hiriarchy.js +++ b/Utilities/Hiriarchy.js @@ -1,8 +1,9 @@ -/* -This function scans a node hiriatchy recursively and creates a Map by Id of all the nodes of it. -*/ + function getHiriarchyMap(rootNode) { + /* + This function scans a node hiriatchy recursively and creates a Map by Id of all the nodes of it. + */ let hiriatchyMap = new Map() evalNode(rootNode) return hiriatchyMap diff --git a/Utilities/Meshes.js b/Utilities/Meshes.js index 42d53bea1..d7b48d3b1 100644 --- a/Utilities/Meshes.js +++ b/Utilities/Meshes.js @@ -1,10 +1,10 @@ -function findNodeInNodeMesh(node, nodeType) { +function findNodeInNodeMesh(node, nodeType, connectedViaPayload, findInChildren, findInParents, findInReferenceParents) { /* This function scans a node mesh for a certain node type and returns the first instance found. */ let nodeFound - scanNodeMesh(node, nodeType) + scanNodeMesh(node) return nodeFound function scanNodeMesh(startingNode) { @@ -20,34 +20,54 @@ function findNodeInNodeMesh(node, nodeType) { } /* We scan through this node children */ - if (nodeDefinition.properties !== undefined) { - for (let i = 0; i < nodeDefinition.properties.length; i++) { - let property = nodeDefinition.properties[i] + if (findInChildren === true) { + if (nodeDefinition.properties !== undefined) { + for (let i = 0; i < nodeDefinition.properties.length; i++) { + let property = nodeDefinition.properties[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]) + 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 } - break } } } } + /* We scan parents nodes. */ - if (startingNode.parentNode !== undefined) { - scanNodeMesh(startingNode.parentNode) + if (findInParents === true) { + if (connectedViaPayload === true) { + if (startingNode.payload.parentNode !== undefined) { + scanNodeMesh(startingNode.payload.parentNode) + } + } else { + if (startingNode.parentNode !== undefined) { + scanNodeMesh(startingNode.parentNode) + } + } } + /* We scan reference parents too. */ - if (startingNode.referenceParent !== undefined) { - scanNodeMesh(startingNode.referenceParent) + if (findInReferenceParents === true) { + if (connectedViaPayload === true) { + if (startingNode.payload.referenceParent !== undefined) { + scanNodeMesh(startingNode.payload.referenceParent) + } + } else { + if (startingNode.referenceParent !== undefined) { + scanNodeMesh(startingNode.referenceParent) + } + } } } } \ No newline at end of file