From e567acdd5d4fe040a5aad05bc8ff14e7eb998668 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 15 Sep 2020 12:57:50 +0200 Subject: [PATCH] Data Mining Installed --- .../CryptoEcosystemFunctions.js | 52 +++++++++++- .../FunctionLibraries/TaskFunctions.js | 3 +- DesignSpace/Workspace/Workspace.js | 10 +++ Utilities/Branches.js | 13 ++- Utilities/Menu.js | 14 ++++ Utilities/NodeChildren.js | 84 +++++++++++++++++++ 6 files changed, 173 insertions(+), 3 deletions(-) create mode 100644 Utilities/Menu.js diff --git a/DesignSpace/Workspace/FunctionLibraries/CryptoEcosystemFunctions.js b/DesignSpace/Workspace/FunctionLibraries/CryptoEcosystemFunctions.js index ec75c0190..90673f35d 100644 --- a/DesignSpace/Workspace/FunctionLibraries/CryptoEcosystemFunctions.js +++ b/DesignSpace/Workspace/FunctionLibraries/CryptoEcosystemFunctions.js @@ -2,7 +2,9 @@ function newCryptoEcosystemFunctions() { thisObject = { addMissingExchanges: addMissingExchanges, addMissingAssets: addMissingAssets, - addMissingMarkets: addMissingMarkets + addMissingMarkets: addMissingMarkets, + installMarket: installMarket, + uninstallMarket: uninstallMarket } return thisObject @@ -203,4 +205,52 @@ function newCryptoEcosystemFunctions() { console.log(err.stack) } } + + function installMarket(node, rootNodes, functionLibraryUiObjectsFromNodes, functionLibraryNodeDeleter) { + + let market = node + let cryptoExchange = findNodeInNodeMesh(node, 'Crypto Exchange', undefined, true, false, true, false) + if (cryptoExchange === undefined) { + node.payload.uiObject.setErrorMessage('Market must be a descendant of a Crypto Exchange') + return + } + + for (let i = 0; i < rootNodes.length; i++) { + let rootNode = rootNodes[i] + if (rootNode.type === 'Network') { + installInNetwork(rootNode) + } + } + + function installInNetwork(network) { + /* + Here we complete the missing stuff at Data Mining + */ + let dataMining = findInBranch(network, 'Data Mining', node, true) + if (dataMining === undefined) { return } + + let exchangeDataTasks = findOrCreateChildWithReference(dataMining, 'Exchange Data Tasks', cryptoExchange, functionLibraryUiObjectsFromNodes) + exchangeDataTasks.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 + let marketDataTask = findAndRecreateChildWithReference(exchangeDataTasks, 'Market Data Tasks', market, rootNodes, functionLibraryUiObjectsFromNodes, functionLibraryNodeDeleter) + + menuClick(marketDataTask, 'Add Missing Data Mine Tasks', true) + menuClickOfNodeArray(marketDataTask.dataMineTasks, 'Add All Tasks', true) + /* + Here we complete the missing stuff at Session Independent Data + */ + let sessionIndependentData = findInBranch(network, 'Session Independent Data', node, true) + if (sessionIndependentData === undefined) { return } + + let exchangeDataProducts = findOrCreateChildWithReference(sessionIndependentData, 'Exchange Data Products', cryptoExchange, functionLibraryUiObjectsFromNodes) + exchangeDataProducts.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 + let singleMarketData = findAndRecreateChildWithReference(exchangeDataProducts, 'Single Market Data', market, rootNodes, functionLibraryUiObjectsFromNodes, functionLibraryNodeDeleter) + + menuClick(singleMarketData, 'Add All Data Mine Products', true) + menuClickOfNodeArray(singleMarketData.dataMineProducts, 'Add All Data Products', true) + } + } + + function uninstallMarket(node, rootNodes, functionLibraryUiObjectsFromNodes, functionLibraryNodeDeleter) { + + } } diff --git a/DesignSpace/Workspace/FunctionLibraries/TaskFunctions.js b/DesignSpace/Workspace/FunctionLibraries/TaskFunctions.js index 89a39afc2..626082b22 100644 --- a/DesignSpace/Workspace/FunctionLibraries/TaskFunctions.js +++ b/DesignSpace/Workspace/FunctionLibraries/TaskFunctions.js @@ -451,7 +451,8 @@ function newTaskFunctions() { if (node.payload.referenceParent === undefined) { return } let taskManager = functionLibraryUiObjectsFromNodes.addUIObject(node, 'Task Manager') - taskManager.name = node.name + taskManager.name = node.payload.referenceParent.name + taskManager.payload.floatingObject.collapseToggle() switch (node.type) { case 'Data Mine Tasks': { diff --git a/DesignSpace/Workspace/Workspace.js b/DesignSpace/Workspace/Workspace.js index 5a6ea267b..991d43d68 100644 --- a/DesignSpace/Workspace/Workspace.js +++ b/DesignSpace/Workspace/Workspace.js @@ -700,6 +700,16 @@ function newWorkspace() { functionLibraryCryptoEcosystemFunctions.addMissingMarkets(payload.node, functionLibraryUiObjectsFromNodes, functionLibraryNodeCloning) } break + case 'Install Market': + { + functionLibraryCryptoEcosystemFunctions.installMarket(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryUiObjectsFromNodes, functionLibraryNodeDeleter) + } + break + case 'Uninstall Market': + { + functionLibraryCryptoEcosystemFunctions.uninstallMarket(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryUiObjectsFromNodes, functionLibraryNodeDeleter) + } + break case 'Add All Output Datasets': { functionLibraryDataMineFunctions.addAllOutputDatasets(payload.node, functionLibraryUiObjectsFromNodes) diff --git a/Utilities/Branches.js b/Utilities/Branches.js index b67bb9438..7609b6ec3 100644 --- a/Utilities/Branches.js +++ b/Utilities/Branches.js @@ -43,4 +43,15 @@ function nodeBranchToArray(node, nodeType) { } } - +function findInBranch(startingNode, nodeType, errorNode, connectedViaPayload) { + /* + This function finds a node in a brach and reports an error if it could not be found. + */ + let nodeFound = findNodeInNodeMesh(startingNode, nodeType, undefined, connectedViaPayload, true, false, false) + if (nodeFound === undefined) { + errorNode.payload.uiObject.setErrorMessage('Could not find ' + nodeType + ' at ' + startingNode.type + ' ' + startingNode.name) + return + } else { + return nodeFound + } +} diff --git a/Utilities/Menu.js b/Utilities/Menu.js new file mode 100644 index 000000000..6412faf23 --- /dev/null +++ b/Utilities/Menu.js @@ -0,0 +1,14 @@ +function menuClickOfNodeArray(nodeArray, action, confirm) { + for (let j=0; j < nodeArray.length; j++) { + let node = nodeArray[j] + menuClick(node, action, confirm) + } +} + +function menuClick(node, action, confirm) { + let menu = node.payload.uiObject.menu + menu.internalClick(action) + if (confirm === true) { + menu.internalClick(action) + } +} \ No newline at end of file diff --git a/Utilities/NodeChildren.js b/Utilities/NodeChildren.js index 3af5b1643..43889d8df 100644 --- a/Utilities/NodeChildren.js +++ b/Utilities/NodeChildren.js @@ -58,4 +58,88 @@ function isMissingChildren(startingNode, checkNode, checkReferenceParent) { } return true } +} + +function findChildReferencingThisNode(startingNode, checkNode) { + /* + This functioin scan all the children of a node and returns the child + that is referencing the checkNode. + */ + if (startingNode === undefined) { return } + if (checkNode === undefined) { return } + + let nodeDefinition = APP_SCHEMA_MAP.get(startingNode.type) + if (nodeDefinition === undefined) { return } + + /* We scan through this node children */ + if (nodeDefinition.properties !== undefined) { + for (let i = 0; i < nodeDefinition.properties.length; i++) { + let property = nodeDefinition.properties[i] + + switch (property.type) { + case 'node': { + let child = startingNode[property.name] + + if (child.payload !== undefined) { + if (child.payload.referenceParent !== undefined) { + if (child.payload.referenceParent.id === checkNode.id) { + return child + } + } + } + } + break + case 'array': { + let startingNodePropertyArray = startingNode[property.name] + if (startingNodePropertyArray !== undefined) { + for (let m = 0; m < startingNodePropertyArray.length; m++) { + let arrayItem = startingNodePropertyArray[m] + + if (arrayItem.payload !== undefined) { + if (arrayItem.payload.referenceParent !== undefined) { + if (arrayItem.payload.referenceParent.id === checkNode.id) { + return arrayItem + } + } + } + } + } + break + } + } + } + return true + } +} + +function findOrCreateChildWithReference(startingNode, childType, referencedNode, functionLibraryUiObjectsFromNodes) { + /* + This function find the child node of starting node that references + refereced node. If there is none, then it creates a child and stablish + the referecen. + */ + let child + if (isMissingChildren(startingNode, referencedNode, true) === true) { + child = functionLibraryUiObjectsFromNodes.addUIObject(startingNode, childType) + child.payload.referenceParent = referencedNode + } else { + child = findChildReferencingThisNode(startingNode, referencedNode) + } + return child +} + +function findAndRecreateChildWithReference(startingNode, childType, referencedNode, rootNodes, functionLibraryUiObjectsFromNodes, functionLibraryNodeDeleter) { + /* + This function finds the child of the starting node that references + the reference node and if found it deletes it. Existing or not + it creates it again with the child type specified. + */ + let child + child = findChildReferencingThisNode(startingNode, referencedNode) + if (child !== undefined) { + functionLibraryNodeDeleter.deleteUIObject(child, rootNodes) + } + child = functionLibraryUiObjectsFromNodes.addUIObject(startingNode, childType) + child.payload.referenceParent = referencedNode + return child } \ No newline at end of file