From 9fef60c27eb9e0f9cd1dedb2450bfbc46febe863 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 27 Jun 2018 15:18:23 +0200 Subject: [PATCH] Improving Logging, cleaning, Globals module introduced --- Dashboard.js | 176 +--------------------------------------- Globals.js | 162 ++++++++++++++++++++++++++++++++++++ Markets.js | 164 ------------------------------------- Project.njsproj | 4 +- Scripts/AppLoader.js | 2 + Scripts/AppPreLoader.js | 17 ++-- WebDebugLog.js | 8 +- 7 files changed, 186 insertions(+), 347 deletions(-) create mode 100644 Globals.js delete mode 100644 Markets.js diff --git a/Dashboard.js b/Dashboard.js index f6bed3383..f503f601f 100644 --- a/Dashboard.js +++ b/Dashboard.js @@ -1,181 +1,11 @@  - - -/* User Interface Colors */ - -UI_COLOR = { - DARK: "48, 48, 54", - LIGHT: "234, 226, 222", - WHITE: "255, 255, 255", - GOLDEN_ORANGE: "240, 162, 2", - RUSTED_RED: "204, 88, 53", - GREEN: "188, 214, 67", - RED: "223, 70, 60", - PATINATED_TURQUOISE: "27,153,139", - TITANIUM_YELLOW: "244,228,9", - MANGANESE_PURPLE: "91,80,122" -}; - -/* User Interface Fonts */ - -UI_FONT = { - PRIMARY: "Saira", - SECONDARY: "Source Code Pro" -}; - -FONT_ASPECT_RATIO = 0.50; - -/* User Interface Panels */ - -UI_PANEL = { - WIDTH: { - SMALL: 100, - NORMAL: 150, - LARGE: 350 - }, - HEIGHT: { - SMALL: 65, - NORMAL: 300, - LARGE: 450 - } -}; - - -/* The Dashboard is the root object that contains all the other stuff in it. Some of that stuff is visible, some other is invisible. */ - let canvas; -let markets; +let markets; let ecosystem = newEcosystem(); - -let marketFilesPeriods = - '[' + - '[' + 24 * 60 * 60 * 1000 + ',' + '"24-hs"' + ']' + ',' + - '[' + 12 * 60 * 60 * 1000 + ',' + '"12-hs"' + ']' + ',' + - '[' + 8 * 60 * 60 * 1000 + ',' + '"08-hs"' + ']' + ',' + - '[' + 6 * 60 * 60 * 1000 + ',' + '"06-hs"' + ']' + ',' + - '[' + 4 * 60 * 60 * 1000 + ',' + '"04-hs"' + ']' + ',' + - '[' + 3 * 60 * 60 * 1000 + ',' + '"03-hs"' + ']' + ',' + - '[' + 2 * 60 * 60 * 1000 + ',' + '"02-hs"' + ']' + ',' + - '[' + 1 * 60 * 60 * 1000 + ',' + '"01-hs"' + ']' + ']'; - -marketFilesPeriods = JSON.parse(marketFilesPeriods); - -let dailyFilePeriods = - '[' + - '[' + 45 * 60 * 1000 + ',' + '"45-min"' + ']' + ',' + - '[' + 40 * 60 * 1000 + ',' + '"40-min"' + ']' + ',' + - '[' + 30 * 60 * 1000 + ',' + '"30-min"' + ']' + ',' + - '[' + 20 * 60 * 1000 + ',' + '"20-min"' + ']' + ',' + - '[' + 15 * 60 * 1000 + ',' + '"15-min"' + ']' + ',' + - '[' + 10 * 60 * 1000 + ',' + '"10-min"' + ']' + ',' + - '[' + 05 * 60 * 1000 + ',' + '"05-min"' + ']' + ',' + - '[' + 04 * 60 * 1000 + ',' + '"04-min"' + ']' + ',' + - '[' + 03 * 60 * 1000 + ',' + '"03-min"' + ']' + ',' + - '[' + 02 * 60 * 1000 + ',' + '"02-min"' + ']' + ',' + - '[' + 01 * 60 * 1000 + ',' + '"01-min"' + ']' + ']'; - -dailyFilePeriods = JSON.parse(dailyFilePeriods); - -function convertTimePeriodToName(pTimePeriod) { - - for (let i = 0; i < dailyFilePeriods.length; i++) { - - let period = dailyFilePeriods[i]; - - if (period[0] === pTimePeriod) { - - return period[1]; - - } - } - - for (let i = 0; i < marketFilesPeriods.length; i++) { - - let period = marketFilesPeriods[i]; - - if (period[0] === pTimePeriod) { - - return period[1]; - - } - } -} - - let cloudVM = newCloudVM(); -window.AT_BREAKPOINT = false; - -const INITIAL_DEFAULT_MARKET = 2; // This is the market that will be shown when loading the site for the first time. -const DEFAULT_EXCHANGE = "Poloniex"; -const DEFAULT_MARKET = { - assetA: "USDT", - assetB: "BTC", -}; - -const USDT_BTC_HTH = 19900; // This is needed to know the scale of the market time line. - -const WIDHTER_VOLUME_BAR_BASE_FACTOR = 2.5; -const LESS_WIDHTER_VOLUME_BAR_TOP_FACTOR = 1 / 4; - -const ONE_DAY_IN_MILISECONDS = 24 * 60 * 60 * 1000; -const _12_HOURS_IN_MILISECONDS = 12 * 60 * 60 * 1000; -const _8_HOURS_IN_MILISECONDS = 8 * 60 * 60 * 1000; -const _6_HOURS_IN_MILISECONDS = 6 * 60 * 60 * 1000; -const _4_HOURS_IN_MILISECONDS = 4 * 60 * 60 * 1000; -const _3_HOURS_IN_MILISECONDS = 3 * 60 * 60 * 1000; -const _2_HOURS_IN_MILISECONDS = 2 * 60 * 60 * 1000; -const _1_HOUR_IN_MILISECONDS = 1 * 60 * 60 * 1000; - -const _45_MINUTES_IN_MILISECONDS = 45 * 60 * 1000; -const _40_MINUTES_IN_MILISECONDS = 40 * 60 * 1000; -const _30_MINUTES_IN_MILISECONDS = 30 * 60 * 1000; -const _20_MINUTES_IN_MILISECONDS = 20 * 60 * 1000; -const _15_MINUTES_IN_MILISECONDS = 15 * 60 * 1000; -const _10_MINUTES_IN_MILISECONDS = 10 * 60 * 1000; -const _5_MINUTES_IN_MILISECONDS = 5 * 60 * 1000; -const _4_MINUTES_IN_MILISECONDS = 4 * 60 * 1000; -const _3_MINUTES_IN_MILISECONDS = 3 * 60 * 1000; -const _2_MINUTES_IN_MILISECONDS = 2 * 60 * 1000; -const _1_MINUTE_IN_MILISECONDS = 1 * 60 * 1000; - -const EARLIEST_DATE = new Date(2014, 0, 18, 4, 26, 8); - -const CHART_ASPECT_RATIO = 1 / 10; - let INITIAL_ZOOM_LEVEL = -26; // This is the zoom level at the view port in which the APP starts. let INITIAL_TIME_PERIOD = recalculatePeriod(INITIAL_ZOOM_LEVEL); // This value will be overwritten at the viewPort.initialize if the user had a prevous session with this same browser. - -const TOP_SPACE_HEIGHT = 50; -const BOTTOM_SPACE_HEIGHT = 50; -var viewPort = newViewPort(); - - - -const PRODUCT_CARD_STATUS = { - ON: 'on', - LOADING: 'loading', - OFF: 'off' -}; - -/* Here we list the valid Time Periods: */ - -const PERIOD_24_HS = "24-hs"; -const PERIOD_12_HS = "12-hs"; -const PERIOD_06_HS = "06-hs"; -const PERIOD_03_HS = "03-hs"; -const PERIOD_01_HS = "01-hs"; -const PERIOD_30_MIN = "30-min"; -const PERIOD_10_MIN = "10-min"; -const PERIOD_05_MIN = "05-min"; -const PERIOD_01_MIN = "01-min"; - -let INITIAL_DATE = new Date(); // This value will be overwritten at the viewPort.initialize if the user had a prevous session with this same browser. - -var maxDate = new Date(); -maxDate.setMilliseconds(0); -maxDate.setDate(maxDate.getDate() + 10); - -const MAX_PLOTABLE_DATE = maxDate; +let viewPort = newViewPort(); function newDashboard() { @@ -216,8 +46,6 @@ function newDashboard() { if (INFO_LOG === true) { logger.write("[INFO] delayedStart -> Entering function."); } - const ID_EXCHANGE_POLONIEX = 1; - /* For now, we are supporting only one market. */ let market = { diff --git a/Globals.js b/Globals.js new file mode 100644 index 000000000..fba1a2855 --- /dev/null +++ b/Globals.js @@ -0,0 +1,162 @@ +/* User Interface Colors */ + +UI_COLOR = { + DARK: "48, 48, 54", + LIGHT: "234, 226, 222", + WHITE: "255, 255, 255", + GOLDEN_ORANGE: "240, 162, 2", + RUSTED_RED: "204, 88, 53", + GREEN: "188, 214, 67", + RED: "223, 70, 60", + PATINATED_TURQUOISE: "27,153,139", + TITANIUM_YELLOW: "244,228,9", + MANGANESE_PURPLE: "91,80,122" +}; + +/* User Interface Fonts */ + +UI_FONT = { + PRIMARY: "Saira", + SECONDARY: "Source Code Pro" +}; + +FONT_ASPECT_RATIO = 0.50; + +/* User Interface Panels */ + +UI_PANEL = { + WIDTH: { + SMALL: 100, + NORMAL: 150, + LARGE: 350 + }, + HEIGHT: { + SMALL: 65, + NORMAL: 300, + LARGE: 450 + } +}; + + +let marketFilesPeriods = + '[' + + '[' + 24 * 60 * 60 * 1000 + ',' + '"24-hs"' + ']' + ',' + + '[' + 12 * 60 * 60 * 1000 + ',' + '"12-hs"' + ']' + ',' + + '[' + 8 * 60 * 60 * 1000 + ',' + '"08-hs"' + ']' + ',' + + '[' + 6 * 60 * 60 * 1000 + ',' + '"06-hs"' + ']' + ',' + + '[' + 4 * 60 * 60 * 1000 + ',' + '"04-hs"' + ']' + ',' + + '[' + 3 * 60 * 60 * 1000 + ',' + '"03-hs"' + ']' + ',' + + '[' + 2 * 60 * 60 * 1000 + ',' + '"02-hs"' + ']' + ',' + + '[' + 1 * 60 * 60 * 1000 + ',' + '"01-hs"' + ']' + ']'; + +marketFilesPeriods = JSON.parse(marketFilesPeriods); + +let dailyFilePeriods = + '[' + + '[' + 45 * 60 * 1000 + ',' + '"45-min"' + ']' + ',' + + '[' + 40 * 60 * 1000 + ',' + '"40-min"' + ']' + ',' + + '[' + 30 * 60 * 1000 + ',' + '"30-min"' + ']' + ',' + + '[' + 20 * 60 * 1000 + ',' + '"20-min"' + ']' + ',' + + '[' + 15 * 60 * 1000 + ',' + '"15-min"' + ']' + ',' + + '[' + 10 * 60 * 1000 + ',' + '"10-min"' + ']' + ',' + + '[' + 05 * 60 * 1000 + ',' + '"05-min"' + ']' + ',' + + '[' + 04 * 60 * 1000 + ',' + '"04-min"' + ']' + ',' + + '[' + 03 * 60 * 1000 + ',' + '"03-min"' + ']' + ',' + + '[' + 02 * 60 * 1000 + ',' + '"02-min"' + ']' + ',' + + '[' + 01 * 60 * 1000 + ',' + '"01-min"' + ']' + ']'; + +dailyFilePeriods = JSON.parse(dailyFilePeriods); + +function convertTimePeriodToName(pTimePeriod) { + + for (let i = 0; i < dailyFilePeriods.length; i++) { + + let period = dailyFilePeriods[i]; + + if (period[0] === pTimePeriod) { + + return period[1]; + + } + } + + for (let i = 0; i < marketFilesPeriods.length; i++) { + + let period = marketFilesPeriods[i]; + + if (period[0] === pTimePeriod) { + + return period[1]; + + } + } +} + +window.AT_BREAKPOINT = false; + +const INITIAL_DEFAULT_MARKET = 2; // This is the market that will be shown when loading the site for the first time. +const DEFAULT_EXCHANGE = "Poloniex"; +const DEFAULT_MARKET = { + assetA: "USDT", + assetB: "BTC", +}; + +const USDT_BTC_HTH = 19900; // This is needed to know the scale of the market time line. + +const WIDHTER_VOLUME_BAR_BASE_FACTOR = 2.5; +const LESS_WIDHTER_VOLUME_BAR_TOP_FACTOR = 1 / 4; + +const ONE_DAY_IN_MILISECONDS = 24 * 60 * 60 * 1000; +const _12_HOURS_IN_MILISECONDS = 12 * 60 * 60 * 1000; +const _8_HOURS_IN_MILISECONDS = 8 * 60 * 60 * 1000; +const _6_HOURS_IN_MILISECONDS = 6 * 60 * 60 * 1000; +const _4_HOURS_IN_MILISECONDS = 4 * 60 * 60 * 1000; +const _3_HOURS_IN_MILISECONDS = 3 * 60 * 60 * 1000; +const _2_HOURS_IN_MILISECONDS = 2 * 60 * 60 * 1000; +const _1_HOUR_IN_MILISECONDS = 1 * 60 * 60 * 1000; + +const _45_MINUTES_IN_MILISECONDS = 45 * 60 * 1000; +const _40_MINUTES_IN_MILISECONDS = 40 * 60 * 1000; +const _30_MINUTES_IN_MILISECONDS = 30 * 60 * 1000; +const _20_MINUTES_IN_MILISECONDS = 20 * 60 * 1000; +const _15_MINUTES_IN_MILISECONDS = 15 * 60 * 1000; +const _10_MINUTES_IN_MILISECONDS = 10 * 60 * 1000; +const _5_MINUTES_IN_MILISECONDS = 5 * 60 * 1000; +const _4_MINUTES_IN_MILISECONDS = 4 * 60 * 1000; +const _3_MINUTES_IN_MILISECONDS = 3 * 60 * 1000; +const _2_MINUTES_IN_MILISECONDS = 2 * 60 * 1000; +const _1_MINUTE_IN_MILISECONDS = 1 * 60 * 1000; + +const EARLIEST_DATE = new Date(2014, 0, 18, 4, 26, 8); + +const CHART_ASPECT_RATIO = 1 / 10; + +const TOP_SPACE_HEIGHT = 50; +const BOTTOM_SPACE_HEIGHT = 50; + + +const PRODUCT_CARD_STATUS = { + ON: 'on', + LOADING: 'loading', + OFF: 'off' +}; + +/* Here we list the valid Time Periods: */ + +const PERIOD_24_HS = "24-hs"; +const PERIOD_12_HS = "12-hs"; +const PERIOD_06_HS = "06-hs"; +const PERIOD_03_HS = "03-hs"; +const PERIOD_01_HS = "01-hs"; +const PERIOD_30_MIN = "30-min"; +const PERIOD_10_MIN = "10-min"; +const PERIOD_05_MIN = "05-min"; +const PERIOD_01_MIN = "01-min"; + +let INITIAL_DATE = new Date(); // This value will be overwritten at the viewPort.initialize if the user had a prevous session with this same browser. + +var maxDate = new Date(); +maxDate.setMilliseconds(0); +maxDate.setDate(maxDate.getDate() + 10); + +const MAX_PLOTABLE_DATE = maxDate; \ No newline at end of file diff --git a/Markets.js b/Markets.js deleted file mode 100644 index eb6d43d76..000000000 --- a/Markets.js +++ /dev/null @@ -1,164 +0,0 @@ -/* This business logic module is responsible for Markets and Assets. */ - -const MODULE_NAME = "Markets"; -var DATA_LAYER_MODULE = require('./Data Layer'); - - -exports.newMarkets = function newMarkets() { - - markets = { - getMarketsByExchange: getMarketsByExchange, - getExistingOrNewMarketId: getExistingOrNewMarketId, - createNewAsset: createNewAsset, - createNewMarket: createNewMarket, - initialize: initialize - }; - - var dataLayer; - - return markets; - - - - function initialize() { - - dataLayer = DATA_LAYER_MODULE.newDataLayer(); - - } - - - - function getMarketsByExchange(exchangeId, callBackFunction) { - - dataLayer.getMarketsByExchange(exchangeId, onResultSetReady); - - function onResultSetReady(resultSet) { - - callBackFunction(resultSet); - - } - - } - - - function getExistingOrNewMarketId(marketName, market, exchangeId, callBackFunction) { - - var assets = marketName.split("_"); - - var assetCodeA = assets[0]; - var assetCodeB = assets[1]; - - var idAssetA; - var idAssetB; - - var marketId; - - getIdAssetA(); - - function getIdAssetA() { - - dataLayer.getAssetIdByCodeName(assetCodeA, onIdReady); - - function onIdReady(resultSet) { - - idAssetA = resultSet.getValue(1, "Id"); - - if (idAssetA === undefined) { - - createNewAsset(assetCodeA, onAssetCreated); - - function onAssetCreated(resultSet) { - - idAssetA = resultSet.getValue(1, "Id"); - getIdAssetB(); - } - - } else { - getIdAssetB(); - } - } - } - - function getIdAssetB() { - - dataLayer.getAssetIdByCodeName(assetCodeB, onIdReady); - - function onIdReady(resultSet) { - - idAssetB = resultSet.getValue(1, "Id"); - - if (idAssetB === undefined) { - - createNewAsset(assetCodeB, onAssetCreated); - - function onAssetCreated(resultSet) { - - idAssetB = resultSet.getValue(1, "Id"); - getMarketId(); - } - - } else { - getMarketId(); - } - } - } - - function getMarketId() { - - dataLayer.getMarketId(idAssetA, idAssetB, exchangeId, onIdReady); - - function onIdReady(resultSet) { - - marketId = resultSet.getValue(1, "Id"); - - if (marketId === undefined) { - - createNewMarket(exchangeId, idAssetA, idAssetB, onMarketCreated); - - function onMarketCreated(resultSet) { - - marketId = resultSet.getValue(1, "Id"); - respond(); - } - - } else { - respond(); - } - } - } - - function respond() { - - callBackFunction(marketName, market, marketId); - - } - } - - - function createNewAsset(assetCode, callBackFunction) { - - dataLayer.newAsset(assetCode, onIdReady); - - function onIdReady(resultSet) { - - callBackFunction(resultSet); - - } - - } - - - - function createNewMarket(exchangeId, idAssetA, idAssetB, callBackFunction) { - - dataLayer.newMarket(exchangeId, idAssetA, idAssetB, onIdReady); - - function onIdReady(resultSet) { - - callBackFunction(resultSet); - - } - - } - -}; \ No newline at end of file diff --git a/Project.njsproj b/Project.njsproj index ff40bb8b2..6867d949b 100644 --- a/Project.njsproj +++ b/Project.njsproj @@ -51,6 +51,9 @@ + + Code + Code @@ -182,7 +185,6 @@ - diff --git a/Scripts/AppLoader.js b/Scripts/AppLoader.js index 7ba9e2eb8..79360b8e0 100644 --- a/Scripts/AppLoader.js +++ b/Scripts/AppLoader.js @@ -27,6 +27,8 @@ /* PlotterPanels */ + "Globals.js", + "BottomSpace/DeleteTradingHistory.js", "TopSpace/PlayStopButton.js", diff --git a/Scripts/AppPreLoader.js b/Scripts/AppPreLoader.js index a7a1f5259..a67ef84e0 100644 --- a/Scripts/AppPreLoader.js +++ b/Scripts/AppPreLoader.js @@ -28,9 +28,14 @@ GLOBAL.CUSTOM_FAIL_RESPONSE = { message: "Custom Message" }; +function spacePad(str, max) { + str = str.toString(); + return str.length < max ? spacePad(" " + str, max) : str; +} + function loadAdvancedAlgosPlatform() { - console.log("AppPreLoader : " + "[INFO] loadAdvancedAlgosPlatform -> Entering function."); + console.log(spacePad("App Pre-Loader", 50) + " : " + "[INFO] loadAdvancedAlgosPlatform -> Entering function."); /* The first thing to do here is to add the canvas where all the action is going to happen. */ @@ -56,7 +61,7 @@ function loadAdvancedAlgosPlatform() { function onServerReponded(pResponseFromServer) { - console.log("AppPreLoader : " + "[INFO] loadAdvancedAlgosPlatform -> onServerReponded -> Entering function."); + console.log(spacePad("App Pre-Loader", 50) + " : " + "[INFO] loadAdvancedAlgosPlatform -> onServerReponded -> Entering function."); let responseFromServer = JSON.parse(pResponseFromServer); @@ -76,7 +81,7 @@ function loadAdvancedAlgosPlatform() { function loadDebugModule() { - console.log("AppPreLoader : " + "[INFO] loadDebugModule -> Entering function."); + console.log(spacePad("App Pre-Loader", 50) + " : " + "[INFO] loadDebugModule -> Entering function."); let path = "WebDebugLog.js"; @@ -84,7 +89,7 @@ function loadAdvancedAlgosPlatform() { function onRequired(pModule) { - console.log("AppPreLoader : " + "[INFO] " + path + " downloaded."); + console.log(spacePad("App Pre-Loader", 50) + " : " + "[INFO] " + path + " downloaded."); loadModules(); @@ -95,7 +100,7 @@ function loadAdvancedAlgosPlatform() { function loadModules() { - console.log("AppPreLoader : " + "[INFO] loadModules -> Entering function."); + console.log(spacePad("App Pre-Loader", 50) + " : " + "[INFO] loadModules -> Entering function."); let path = "Scripts/AppLoader.js"; @@ -103,7 +108,7 @@ function loadAdvancedAlgosPlatform() { function onRequired(pModule) { - console.log("AppPreLoader : " + "[INFO] " + path + " downloaded."); + console.log(spacePad("App Pre-Loader", 50) + " : " + "[INFO] " + path + " downloaded."); let APP_LOADER_MODULE = newAppLoader(); APP_LOADER_MODULE.loadModules(); diff --git a/WebDebugLog.js b/WebDebugLog.js index 44af92f0e..7adc87a10 100644 --- a/WebDebugLog.js +++ b/WebDebugLog.js @@ -10,7 +10,11 @@ function newWebDebugLog() { function write(pText) { - console.log(thisObject.fileName + " : " + pText); - + console.log(spacePad(thisObject.fileName, 50) + " : " + pText); + + function spacePad(str, max) { + str = str.toString(); + return str.length < max ? spacePad(" " + str, max) : str; + } } } \ No newline at end of file