From 85203e489e1f941c42d0e8f74627f2d9c42ac72e Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 2 Mar 2018 21:47:52 +0100 Subject: [PATCH] Initialize improved --- .vs/Plotters-Candles-Volumes/v15/.suo | Bin 20480 -> 22528 bytes Candles.js | 74 +++++------------------ Volumes.js | 81 +++++++------------------- 3 files changed, 37 insertions(+), 118 deletions(-) diff --git a/.vs/Plotters-Candles-Volumes/v15/.suo b/.vs/Plotters-Candles-Volumes/v15/.suo index 3e53531af0d60afa9fcb9580ccf7280ad49d18ee..51998f4f15d066eb9f0b3c58ff9272314e3c522a 100644 GIT binary patch delta 285 zcmZozz}T>Xae{#Y0}Kc-FmM6cj6nSF|Ns9WVGw&`;CjZ%{~2@HKI|@!b=tJKh$)DX zhYcv90K`Cb|0fG7s7(ICY{4izS(ineR|F^w($52=g*FGWd>7#WF<~kWae{#Y69W_oFfgzHnT$aE@Bjb*AW>!@-Wa%^aq@rGJk~h%J5x4pE@BE| zqK&HS{ZZ46$!o$IZ zB4XgrJozw_A*%;alwHTz+$a K;|8WheoO$lq&@in diff --git a/Candles.js b/Candles.js index d0ebe2e4b..5e8cb0d86 100644 --- a/Candles.js +++ b/Candles.js @@ -40,76 +40,34 @@ return thisObject; - function initialize(pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { + function initialize(pStorage, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { - let cursorCacheInProgress = false; - let finaleStepsInProgress = false; + /* Store the information received. */ + + fileCache = pStorage.fileCache; + fileCursorCache = pStorage.fileCursorCache; datetime = pDatetime; timePeriod = pTimePeriod; - fileCache = newFileCache(); - fileCache.initialize("AAMasters", "AAOlivia", "Candles", "Market Files", pExchange, pMarket, onFileReady); + /* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */ - function onFileReady() { + marketFile = fileCache.getFile(ONE_DAY_IN_MILISECONDS); // This file is the one processed faster. - let newMarketFile = fileCache.getFile(ONE_DAY_IN_MILISECONDS); + recalculateScale(); + recalculate(); - if (newMarketFile !== undefined) { + /* Now we set the right files according to current Period. */ - marketFile = newMarketFile; + marketFile = fileCache.getFile(pTimePeriod); + fileCursor = fileCursorCache.getFileCursor(pTimePeriod); - initializeFileCursorCache(); + /* Listen to the necesary events. */ - } - } + viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); + canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); - function initializeFileCursorCache() { - - if (cursorCacheInProgress === false) { - - cursorCacheInProgress = true; - - fileCursorCache = newFileCursorCache(); - fileCursorCache.initialize("AAMasters", "AAOlivia", "Candles", "Daily Files", pExchange, pMarket, pDatetime, pTimePeriod, onFileCursorReady); - - } - } - - function onFileCursorReady() { - - recalculate(); - - let newFileCursor = fileCursorCache.getFileCursor(pTimePeriod); - - if (newFileCursor !== undefined) { // if the file ready is the one we need then it and we dont have it yet, then we will continue here. - - let stringDate = datetime.getUTCFullYear() + '-' + pad(datetime.getUTCMonth() + 1, 2) + '-' + pad(datetime.getUTCDate(), 2); - - let dailyFile = newFileCursor.files.get(stringDate); - - if (dailyFile !== undefined) { - - if (finaleStepsInProgress === false) { - - finaleStepsInProgress = true; - - fileCursor = newFileCursor; - - recalculateScale(); // With any of the market files we can calculate the scale. - - recalculate(); - - viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); - canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); - - callBackFunction(); - - } - } - } - - } + callBackFunction(); } diff --git a/Volumes.js b/Volumes.js index db889e796..ad1520b2c 100644 --- a/Volumes.js +++ b/Volumes.js @@ -30,82 +30,43 @@ let fileCache; // This object will provide the different Market Files at different Time Periods. let fileCursorCache; // This object will provide the different File Cursors at different Time Periods. + let scaleFile; // This file is used to calculate the scale. + /* these are module specific variables: */ let volumes = []; // Here we keep the volumes to be ploted every time the Draw() function is called by the AAWebPlatform. return thisObject; - function initialize(pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { + function initialize(pStorage, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { - let cursorCacheInProgress = false; - let finaleStepsInProgress = false; + /* Store the information received. */ + + fileCache = pStorage.fileCache; + fileCursorCache = pStorage.fileCursorCache; datetime = pDatetime; timePeriod = pTimePeriod; - fileCache = newFileCache(); - fileCache.initialize("AAMasters", "AAOlivia", "Volumes", "Market Files", pExchange, pMarket, onFileReady); + /* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */ - function onFileReady() { + scaleFile = fileCache.getFile(ONE_DAY_IN_MILISECONDS); // This file is the one processed faster. - let newMarketFile = fileCache.getFile(ONE_DAY_IN_MILISECONDS); + recalculateScaleX(); + recalculate(); + recalculateScaleY(); - if (newMarketFile !== undefined) { + /* Now we set the right files according to current Period. */ - marketFile = newMarketFile; + marketFile = fileCache.getFile(pTimePeriod); + fileCursor = fileCursorCache.getFileCursor(pTimePeriod); - initializeFileCursorCache(); + /* Listen to the necesary events. */ - } - } + viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); + canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); - function initializeFileCursorCache() { - - if (cursorCacheInProgress === false) { - - cursorCacheInProgress = true; - - fileCursorCache = newFileCursorCache(); - fileCursorCache.initialize("AAMasters", "AAOlivia", "Volumes", "Daily Files", pExchange, pMarket, pDatetime, pTimePeriod, onFileCursorReady); - - } - } - - function onFileCursorReady() { - - recalculate(); - - let newFileCursor = fileCursorCache.getFileCursor(pTimePeriod); - - if (newFileCursor !== undefined) { // if the file ready is the one we need then it and we dont have it yet, then we will continue here. - - let stringDate = datetime.getUTCFullYear() + '-' + pad(datetime.getUTCMonth() + 1, 2) + '-' + pad(datetime.getUTCDate(), 2); - - let dailyFile = newFileCursor.files.get(stringDate); - - if (dailyFile !== undefined) { - - if (finaleStepsInProgress === false) { - - finaleStepsInProgress = true; - - fileCursor = newFileCursor; - - recalculateScaleX(); - recalculate(); - recalculateScaleY(); - - viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); - canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); - - callBackFunction(); - - } - } - } - - } + callBackFunction(); } @@ -404,9 +365,9 @@ let maxValue = 0; - for (var i = 0; i < marketFile.length; i++) { + for (var i = 0; i < scaleFile.length; i++) { - let currentMax = (marketFile[i][0] + marketFile[i][1]) * 4; + let currentMax = (scaleFile[i][0] + scaleFile[i][1]) * 4; if (maxValue < currentMax) { maxValue = currentMax;