From 04b82bfd0964c6c4aab930a9fd554fea2d94d9c3 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 28 Nov 2020 19:28:59 +0100 Subject: [PATCH] debug log improvements --- TaskServer/DebugLog.js | 44 ++++++++++++------- TaskServer/IndicatorBot.js | 5 +-- .../ReinforcementLearning/LearningBot.js | 5 +-- TaskServer/SensorBot.js | 5 +-- TaskServer/TradingBot.js | 5 +-- 5 files changed, 35 insertions(+), 29 deletions(-) diff --git a/TaskServer/DebugLog.js b/TaskServer/DebugLog.js index 07901b028..02870a618 100644 --- a/TaskServer/DebugLog.js +++ b/TaskServer/DebugLog.js @@ -14,6 +14,7 @@ exports.newDebugLog = function (processIndex) { let thisObject = { bot: undefined, write: write, + newMainLoop: newMainLoop, newInternalLoop: newInternalLoop, persist: persist, // This method is executed at the end of each Main Loop. initialize: initialize, @@ -41,16 +42,13 @@ exports.newDebugLog = function (processIndex) { persist() } - function newInternalLoop(pBot, pProcess, date, percentage) { - if (percentage === undefined) { - percentage = "" - } else { - percentage = percentage.toFixed(2) + " %" - } - - if (date === undefined) { date = thisObject.bot.processDatetime } - date = date.getUTCFullYear() + '-' + strPad(date.getUTCMonth() + 1, 2, "0") + '-' + strPad(date.getUTCDate(), 2, "0"); + function strPad(str, max, fill) { + if (fill === undefined) { fill = " " } + str = str.toString(); + return str.length < max ? strPad(fill + str, max) : str; + } + function logLoop(pBot, pProcess, date, percentage, loopType) { console.log( new Date().toISOString() + " " + @@ -64,25 +62,37 @@ exports.newDebugLog = function (processIndex) { TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.quotedAsset.referenceParent.config.codeName , 10) + " " + + strPad(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.config.codeName, 30) + + " " + strPad(pBot, 30) + " " + strPad(pProcess, 30) + - " Internal Loop # " + - strPad(internalLoopCounter + 1, 8) + + loopType + + strPad(TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).MAIN_LOOP_COUNTER, 8) + " " + strPad(date, 30) + " " + strPad(percentage, 10) ) + } + function newMainLoop(pBot, pProcess, date, percentage) { + logLoop(pBot, pProcess, date, percentage, " Main Loop # ") + } + + function newInternalLoop(pBot, pProcess, date, percentage) { + if (percentage === undefined) { + percentage = "" + } else { + percentage = percentage.toFixed(2) + " %" + } + + if (date === undefined) { date = thisObject.bot.processDatetime } + date = date.getUTCFullYear() + '-' + strPad(date.getUTCMonth() + 1, 2, "0") + '-' + strPad(date.getUTCDate(), 2, "0"); + + logLoop(pBot, pProcess, date, percentage, " Internal Loop # ") persist(); - - function strPad(str, max, fill) { - if (fill === undefined) { fill = " " } - str = str.toString(); - return str.length < max ? strPad(fill + str, max) : str; - } } function persist() { diff --git a/TaskServer/IndicatorBot.js b/TaskServer/IndicatorBot.js index 6816736b9..9a65f21e1 100644 --- a/TaskServer/IndicatorBot.js +++ b/TaskServer/IndicatorBot.js @@ -129,9 +129,8 @@ /* We define the datetime for the process that we are running now. This will be the official processing time for both the infraestructure and the bot. */ bot.processDatetime = new Date(); // This will be considered the process date and time, so as to have it consistenly all over the execution. - /* High level log entry */ - console.log(new Date().toISOString() + " " + pad(TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.parentNode.parentNode.name, 20) + " " + pad(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, 10) + " " + pad(bot.codeName, 30) + " " + pad(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.config.codeName, 30) - + " Main Loop # " + pad(Number(TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).MAIN_LOOP_COUNTER), 8)) + /* Main Loop Console Logging */ + logger.newMainLoop(bot.codeName, TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.config.codeName, '', ''); /* We will prepare first the infraestructure needed for the bot to run. There are 3 modules we need to sucessfullly initialize first. */ let processExecutionEvents diff --git a/TaskServer/ReinforcementLearning/LearningBot.js b/TaskServer/ReinforcementLearning/LearningBot.js index 3c73659b6..9b8b906f0 100644 --- a/TaskServer/ReinforcementLearning/LearningBot.js +++ b/TaskServer/ReinforcementLearning/LearningBot.js @@ -88,9 +88,8 @@ exports.newLearningBot = function (processIndex, bot, parentLogger) { /* We define the datetime for the process that we are running now. This will be the official processing time for both the infraestructure and the bot. */ bot.processDatetime = new Date(); // This will be considered the process date and time, so as to have it consistenly all over the execution. - /* High level log entry */ - console.log(new Date().toISOString() + " " + pad(TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.parentNode.parentNode.name, 20) + " " + pad(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, 10) + " " + pad(bot.codeName, 30) + " " + pad(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.config.codeName, 30) - + " Main Loop # " + pad(Number(TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).MAIN_LOOP_COUNTER), 8) + " " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type + " " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.name) + /* Main Loop Console Logging */ + logger.newMainLoop(bot.codeName, TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.config.codeName, '', ''); /* Checking if we need to need to emit any event */ if (bot.SESSION_STATUS === 'Idle' && bot.STOP_SESSION === false) { diff --git a/TaskServer/SensorBot.js b/TaskServer/SensorBot.js index de3ce3e23..06f0fb360 100644 --- a/TaskServer/SensorBot.js +++ b/TaskServer/SensorBot.js @@ -134,9 +134,8 @@ /* We define the datetime for the process that we are running now. This will be the official processing time for both the infraestructure and the bot. */ bot.processDatetime = new Date(); // This will be considered the process date and time, so as to have it consistenly all over the execution. - /* High level log entry */ - console.log(new Date().toISOString() + " " + pad(TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.parentNode.parentNode.name, 20) + " " + pad(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, 10) + " " + pad(bot.codeName, 30) + " " + pad(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.config.codeName, 30) - + " Main Loop # " + pad(Number(TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).MAIN_LOOP_COUNTER), 8)) + /* Main Loop Console Logging */ + logger.newMainLoop(bot.codeName, TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.config.codeName, '', ''); /* We will prepare first the infraestructure needed for the bot to run. There are 4 modules we need to sucessfullly initialize first. */ let processExecutionEvents diff --git a/TaskServer/TradingBot.js b/TaskServer/TradingBot.js index f14cc37d3..1bed39b9f 100644 --- a/TaskServer/TradingBot.js +++ b/TaskServer/TradingBot.js @@ -88,9 +88,8 @@ /* We define the datetime for the process that we are running now. This will be the official processing time for both the infraestructure and the bot. */ bot.processDatetime = new Date(); // This will be considered the process date and time, so as to have it consistenly all over the execution. - /* High level log entry */ - console.log(new Date().toISOString() + " " + pad(TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.parentNode.parentNode.name, 20) + " " + pad(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, 10) + " " + pad(bot.codeName, 30) + " " + pad(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.config.codeName, 30) - + " Main Loop # " + pad(Number(TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).MAIN_LOOP_COUNTER), 8) + " " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type + " " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.name) + /* Main Loop Console Logging */ + logger.newMainLoop(bot.codeName, TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.config.codeName, '', ''); /* Checking if we need to need to emit any event */ if (bot.TRADING_SESSION_STATUS === 'Idle' && bot.STOP_SESSION === false) {