From 791966a78c97282d115061a0eeebe4f120bdb85a Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 10 Mar 2020 13:01:09 +0100 Subject: [PATCH] Performance Boost --- AppSchema.json | 1 + CanvasApp/Canvas.js | 2 +- CanvasApp/DesignSpace/Workspace/Workspace.js | 11 ++++ CanvasApp/FloatingSpace/CircularMenu.js | 13 ++-- CanvasApp/FloatingSpace/CircularMenuItem.js | 10 ++- CanvasApp/FloatingSpace/FloatingLayer.js | 22 +++++-- CanvasApp/FloatingSpace/FloatingObject.js | 17 +---- CanvasApp/FloatingSpace/UiObject.js | 6 +- .../FloatingSpace/UiObjectConstructor.js | 15 +++++ CanvasApp/Frame.js | 2 +- CanvasApp/Spaces/DesignSpace.js | 2 +- .../Historic-OHLCVs/User.Bot.js | 66 +++++++++++++++++-- 12 files changed, 129 insertions(+), 38 deletions(-) diff --git a/AppSchema.json b/AppSchema.json index 3e0d6d6a9..403c333eb 100644 --- a/AppSchema.json +++ b/AppSchema.json @@ -1147,6 +1147,7 @@ "addLeftIcons": true, "level": 1, "icon": "network", + "docURL": "https://docs.superalgos.org/suite-network-hierarchy.html#network", "properties": [ { "name": "networkNodes", diff --git a/CanvasApp/Canvas.js b/CanvasApp/Canvas.js index 7745830a2..cb22a7308 100644 --- a/CanvasApp/Canvas.js +++ b/CanvasApp/Canvas.js @@ -758,7 +758,7 @@ function newCanvas () { let container - /* We check if the mouse is over an element of the Strategy Space / */ + /* We check if the mouse is over an element of the Designe Space / */ if (thisObject.designSpace !== undefined) { container = thisObject.designSpace.getContainer(point) diff --git a/CanvasApp/DesignSpace/Workspace/Workspace.js b/CanvasApp/DesignSpace/Workspace/Workspace.js index 415d34e58..41d4fd779 100644 --- a/CanvasApp/DesignSpace/Workspace/Workspace.js +++ b/CanvasApp/DesignSpace/Workspace/Workspace.js @@ -412,6 +412,17 @@ function newWorkspace () { referenceDetachNode(payload.node) } break + case 'Open Documentation': + { + let definition = APP_SCHEMA_MAP.get(payload.node.type) + if (definition !== undefined) { + if (definition.docURL !== undefined) { + let newTab = window.open(definition.docURL, '_blank') + newTab.focus() + } + } + } + break } } } diff --git a/CanvasApp/FloatingSpace/CircularMenu.js b/CanvasApp/FloatingSpace/CircularMenu.js index 0e81863c4..93a940068 100644 --- a/CanvasApp/FloatingSpace/CircularMenu.js +++ b/CanvasApp/FloatingSpace/CircularMenu.js @@ -49,7 +49,7 @@ function newCircularMenu () { let iconAndTextArray = [] let iconOnlyArray - let ringsArray = [[], [], []] + let ringsArray = [[], [], [], []] for (let i = 0; i < menuItemsInitialValues.length; i++) { let menuItem = newCircularMenuItem() @@ -103,15 +103,18 @@ function newCircularMenu () { menuItems.push(menuItem) } - /* There are 3 possible rings of icons, we will go through each of them here. */ - let amplitudeArray = [80, 50, 40] - let initialAngleArray = [220, 205, 200] - for (let j = 1; j < 4; j++) { + /* There are 4 possible rings of icons, we will go through each of them here. */ + let amplitudeArray = [80, 50, 40, 80] + let initialAngleArray = [220, 205, 200, 180] + for (let j = 1; j < ringsArray.length + 1; j++) { let iconOnlyArray = ringsArray[j - 1] /* Here we calculate the angles for each menu item, and then apply it if it was not previously defined. */ let amplitude = amplitudeArray[j - 1] let initialAngle = initialAngleArray[j - 1] let step = amplitude / (iconOnlyArray.length - 1) + if (iconOnlyArray.length === 1) { + step = 0 + } for (let i = 0; i < iconOnlyArray.length; i++) { let menuItem = iconOnlyArray[i] diff --git a/CanvasApp/FloatingSpace/CircularMenuItem.js b/CanvasApp/FloatingSpace/CircularMenuItem.js index af5c83a95..64c2d220f 100644 --- a/CanvasApp/FloatingSpace/CircularMenuItem.js +++ b/CanvasApp/FloatingSpace/CircularMenuItem.js @@ -150,15 +150,19 @@ function newCircularMenuItem () { if (thisObject.type === 'Icon Only') { switch (thisObject.ring) { case 1: { - radiusGrowthFactor = 6 + radiusGrowthFactor = 6.5 break } case 2: { - radiusGrowthFactor = 4.5 + radiusGrowthFactor = 5.0 break } case 3: { - radiusGrowthFactor = 3 + radiusGrowthFactor = 3.5 + break + } + case 4: { + radiusGrowthFactor = 2.5 break } } diff --git a/CanvasApp/FloatingSpace/FloatingLayer.js b/CanvasApp/FloatingSpace/FloatingLayer.js index 621404fbb..066533c25 100644 --- a/CanvasApp/FloatingSpace/FloatingLayer.js +++ b/CanvasApp/FloatingSpace/FloatingLayer.js @@ -200,10 +200,24 @@ function newFloatingLayer () { } } + function collapsePhysics (thisObject) { + let parent = thisObject.payload.chainParent + if (parent === undefined) { return } + if (parent.payload === undefined) { return } + if (parent.payload.floatingObject === undefined) { return } + + thisObject.isParentCollapsed = parent.payload.floatingObject.isCollapsed + if (thisObject.collapsedManually === false) { + thisObject.isCollapsed = parent.payload.floatingObject.isCollapsed + } + } + function makeVisible () { for (let i = 0; i < invisibleFloatingObjects.length; i++) { let floatingObject = invisibleFloatingObjects[i] + collapsePhysics(floatingObject) + if (floatingObject.isFrozen === false && floatingObject.isParentCollapsed === false) { visibleFloatingObjects.push(floatingObject) invisibleFloatingObjects.splice(i, 1) // Delete item from array. @@ -217,6 +231,8 @@ function newFloatingLayer () { for (let i = 0; i < visibleFloatingObjects.length; i++) { let floatingObject = visibleFloatingObjects[i] + collapsePhysics(floatingObject) + if (floatingObject.isFrozen === true || floatingObject.isParentCollapsed === true) { invisibleFloatingObjects.push(floatingObject) visibleFloatingObjects.splice(i, 1) // Delete item from array. @@ -256,10 +272,8 @@ function newFloatingLayer () { /* This function makes all the calculations to apply phisycs on all visible floatingObjects in this layer. */ try { - for (let i = 0; i < invisibleFloatingObjects.length; i++) { - let floatingObject = invisibleFloatingObjects[i] - floatingObject.physics() - } + DEBUG.variable1 = 'Invisible Floating Objets: ' + invisibleFloatingObjects.length + DEBUG.variable2 = 'Visible Floating Objets: ' + visibleFloatingObjects.length for (let i = 0; i < visibleFloatingObjects.length; i++) { let floatingObject = visibleFloatingObjects[i] diff --git a/CanvasApp/FloatingSpace/FloatingObject.js b/CanvasApp/FloatingSpace/FloatingObject.js index 6e9ce5833..15f4dd0f3 100644 --- a/CanvasApp/FloatingSpace/FloatingObject.js +++ b/CanvasApp/FloatingSpace/FloatingObject.js @@ -219,12 +219,13 @@ function newFloatingObject () { } function physics () { - collapsePhysics() frozenPhysics() /* From here on, only if they are not too far. */ if (canvas.floatingSpace.isItFar(thisObject.payload)) { return } thisObjectPhysics() - thisObject.payload.uiObject.physics() + if (thisObject.payload.uiObject !== undefined) { + thisObject.payload.uiObject.physics() + } positionContraintsPhysics() } @@ -241,18 +242,6 @@ function newFloatingObject () { } } - function collapsePhysics () { - let parent = thisObject.payload.chainParent - if (parent === undefined) { return } - if (parent.payload === undefined) { return } - if (parent.payload.floatingObject === undefined) { return } - - thisObject.isParentCollapsed = parent.payload.floatingObject.isCollapsed - if (thisObject.collapsedManually === false) { - thisObject.isCollapsed = parent.payload.floatingObject.isCollapsed - } - } - function positionContraintsPhysics () { if (thisObject.angleToParent !== ANGLE_TO_PARENT.NOT_FIXED && thisObject.isOnFocus !== true) { let parent = thisObject.payload.chainParent diff --git a/CanvasApp/FloatingSpace/UiObject.js b/CanvasApp/FloatingSpace/UiObject.js index cbba06149..1d94d1b7f 100644 --- a/CanvasApp/FloatingSpace/UiObject.js +++ b/CanvasApp/FloatingSpace/UiObject.js @@ -54,7 +54,7 @@ function newUiObject () { let executingIcon let selfFocusEventSubscriptionId - let selfNotFocuskEventSubscriptionId + let selfNotFocusEventSubscriptionId let selfDisplaceEventSubscriptionId let selfDragStartedEventSubscriptionId let selfDragFinishedEventSubscriptionId @@ -106,7 +106,7 @@ function newUiObject () { systemEventHandler.stopListening(key, eventSubscriptionIdOnStopped, 'UiObject') thisObject.container.eventHandler.stopListening(selfFocusEventSubscriptionId) - thisObject.container.eventHandler.stopListening(selfNotFocuskEventSubscriptionId) + thisObject.container.eventHandler.stopListening(selfNotFocusEventSubscriptionId) thisObject.container.eventHandler.stopListening(selfDisplaceEventSubscriptionId) thisObject.container.eventHandler.stopListening(selfDragStartedEventSubscriptionId) thisObject.container.eventHandler.stopListening(selfDragFinishedEventSubscriptionId) @@ -168,7 +168,7 @@ function newUiObject () { iconPhysics() selfFocusEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onFocus', onFocus) - selfNotFocuskEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onNotFocus', onNotFocus) + selfNotFocusEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onNotFocus', onNotFocus) selfDisplaceEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onDisplace', onDisplace) selfDragStartedEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onDragStarted', onDragStarted) selfDragFinishedEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onDragFinished', onDragFinished) diff --git a/CanvasApp/FloatingSpace/UiObjectConstructor.js b/CanvasApp/FloatingSpace/UiObjectConstructor.js index 82077883e..215f9f742 100644 --- a/CanvasApp/FloatingSpace/UiObjectConstructor.js +++ b/CanvasApp/FloatingSpace/UiObjectConstructor.js @@ -274,6 +274,21 @@ function newUiObjectConstructor () { ring: 3 } ) + + menuItemsInitialValues.push( + { + action: 'Open Documentation', + actionFunction: floatingObject.payload.onMenuItemClick, + label: undefined, + visible: true, + iconPathOn: 'quality', + iconPathOff: 'quality', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + ring: 4 + } + ) } function getMenuItemsInitialValues (uiObject, floatingObject, payload) { diff --git a/CanvasApp/Frame.js b/CanvasApp/Frame.js index 04cec82ad..ea2b7ab12 100644 --- a/CanvasApp/Frame.js +++ b/CanvasApp/Frame.js @@ -209,7 +209,7 @@ function newFrame () { } /* Now we check if the resulting point is whin the current Frame. */ - + if (isNaN(checkPoint.x) || isNaN(checkPoint.y)) { return false } if (thisObject.type === 'Circle') { let distance = Math.sqrt(Math.pow(thisObject.position.x - point.x, 2) + Math.pow(thisObject.position.y - point.y, 2)) diff --git a/CanvasApp/Spaces/DesignSpace.js b/CanvasApp/Spaces/DesignSpace.js index c727b5a7b..cea2a4637 100644 --- a/CanvasApp/Spaces/DesignSpace.js +++ b/CanvasApp/Spaces/DesignSpace.js @@ -1,6 +1,6 @@ function newDesignSpace () { - const MODULE_NAME = 'Strategy Space' + const MODULE_NAME = 'Designe Space' let thisObject = { sidePanel: undefined, container: undefined, diff --git a/Legacy-Code/AAMasters/bots/AACharly-Sensor-Bot/Historic-OHLCVs/User.Bot.js b/Legacy-Code/AAMasters/bots/AACharly-Sensor-Bot/Historic-OHLCVs/User.Bot.js index b49de2887..ab698d363 100644 --- a/Legacy-Code/AAMasters/bots/AACharly-Sensor-Bot/Historic-OHLCVs/User.Bot.js +++ b/Legacy-Code/AAMasters/bots/AACharly-Sensor-Bot/Historic-OHLCVs/User.Bot.js @@ -20,10 +20,13 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt const ONE_MIN = 60000 const ONE_DAY = ONE_MIN * 60 * 24 - const MAX_OHLCVs_PER_EXECUTION = 10000000 + const MAX_OHLCVs_PER_EXECUTION = 2000 // 10000000 const symbol = bot.market.baseAsset + '/' + bot.market.quotedAsset const ccxt = require('ccxt') + let fetchType = "by Time" + let lastId + let firstId let allOHLCVs = [] let thisReport; let since @@ -32,7 +35,6 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt let lastFile let exchangeId let options = {} - let firstId let rateLimit = 500 let exchange let uiStartDate = new Date(bot.uiStartDate) @@ -52,7 +54,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt exchangeId = bot.exchange.toLowerCase() - /* Applying the parameters defined by the user at the Exchange node */ + /* Applying the parameters defined by the user at the Exchange Node Config */ if (bot.exchangeNode.code.API !== undefined) { for (let i = 0; i < bot.exchangeNode.code.API.length; i++) { if (bot.exchangeNode.code.API[i].method === 'fetch_ohlcv') { @@ -73,6 +75,9 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt if (bot.exchangeNode.code.API[i].hostname !== undefined) { hostname = bot.exchangeNode.code.API[i].hostname } + if (bot.exchangeNode.code.API[i].fetchType !== undefined) { + fetchType = bot.exchangeNode.code.API[i].fetchType + } } } } @@ -94,7 +99,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt 'secret': secret, 'timeout': 30000, 'enableRateLimit': true, - verbose: false, + verbose: true, options: options } if (rateLimit !== undefined) { @@ -145,6 +150,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt getContextVariables() if (abort === true) { return } + await getFirstId() await getOHLCVs() if (abort === true) { return } if (global.STOP_TASK_GRACEFULLY === true) { @@ -173,6 +179,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt if (thisReport.file.beginingOfMarket !== undefined) { // This means this is not the first time this process run. beginingOfMarket = new Date(thisReport.file.beginingOfMarket.year + "-" + thisReport.file.beginingOfMarket.month + "-" + thisReport.file.beginingOfMarket.days + " " + thisReport.file.beginingOfMarket.hours + ":" + thisReport.file.beginingOfMarket.minutes + GMT_SECONDS); lastFile = new Date(thisReport.file.lastFile.year + "-" + thisReport.file.lastFile.month + "-" + thisReport.file.lastFile.days + " " + thisReport.file.lastFile.hours + ":" + thisReport.file.lastFile.minutes + GMT_SECONDS); + lastId = thisReport.file.lastId } else { // This means this is the first time this process run. fisrtTimeThisProcessRun = true beginingOfMarket = new Date(uiStartDate.valueOf()) @@ -213,6 +220,33 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt } } + async function getFirstId() { + try { + /* We need the first id only when we are going to fetch trades based on id and it is the first time the process runs*/ + if (fetchType !== "by Id") { return } + if (lastId !== undefined) { return } + lastId = 0 + + return + /* + const limit = 1 + const exchangeClass = ccxt[exchangeId] + const exchange = new exchangeClass({ + 'timeout': 30000, + 'enableRateLimit': true, + verbose: false + }) + + const OHLCVs = await exchange.fetchOHLCV(symbol, '1m', since, limit, undefined) + + let lastRecord = OHLCVs[OHLCVs.length - 1] + lastId = lastRecord.info[firstId] + */ + } catch (err) { + /* If something fails trying to get an id close to since, we just will continue without an id.*/ + } + } + async function getOHLCVs() { try { @@ -228,6 +262,16 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getOHLCVs -> Fetching OHLCVs @ " + processingDate + "-> exchange = " + bot.exchange + " -> symbol = " + symbol + " -> since = " + since + " -> limit = " + limit) } bot.processHeartBeat("Fetching " + allOHLCVs.length.toFixed(0) + " OHLCVs from " + bot.exchange + " " + symbol + " @ " + processingDate) // tell the world we are alive and doing well + /* Defining if we will query the exchange by Date or Id */ + if (fetchType === "by Id") { + /* + params = { + 'fromId': lastId + } + */ + since = lastId + } + /* Fetching the OHLCVs from the exchange.*/ await new Promise(resolve => setTimeout(resolve, rateLimit)) // rate limit const OHLCVs = await exchange.fetchOHLCV(symbol, '1m', since, limit, params) @@ -272,6 +316,8 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt since++ // this prevents requesting in a loop OHLCVs with the same timestamp, that can happen when all the records fetched comes with exactly the same timestamp. } + lastId = OHLCVs[OHLCVs.length - 1]['id'] + for (let i = 0; i < OHLCVs.length; i++) { let OHLCV = OHLCVs[i] @@ -323,6 +369,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt let headOfTheMarketReached = false let i = 0 + lastId = undefined controlLoop() @@ -357,7 +404,6 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt headOfTheMarketReached = true saveFile(currentDay) - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> saveOHLCVs -> Saving OHLCVs @ " + processingDate + " -> i = " + i + " -> total = " + allOHLCVs.length) } bot.processHeartBeat("Saving " + i.toFixed(0) + " / " + allOHLCVs.length + " OHLCVs from " + bot.exchange + " " + symbol + " @ " + processingDate) // tell the world we are alive and doing well @@ -414,7 +460,8 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt hight: record[2], low: record[3], close: record[4], - volume: record[5] + volume: record[5], + id: record[6] } checkOHLCVMinute() } @@ -440,6 +487,9 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt if (i < allOHLCVs.length - 1) { i++ } + + lastId = OHLCV.id + } lastCandle = candle @@ -555,6 +605,10 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt uiStartDate: uiStartDate.toUTCString() }; + if (fetchType === "by Id") { + thisReport.file.lastId = lastId + } + thisReport.save(onSaved); function onSaved(err) {