From c6a77349b4d28b8941cecd290671b872c7d8df5f Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 20 Feb 2018 12:33:50 +0100 Subject: [PATCH] FileCache implementation ready --- .vs/AAOlivia-Plotter/v15/.suo | Bin 17920 -> 16896 bytes Candlestick.js | 90 +++++++++++++++++----------------- 2 files changed, 46 insertions(+), 44 deletions(-) diff --git a/.vs/AAOlivia-Plotter/v15/.suo b/.vs/AAOlivia-Plotter/v15/.suo index 266555c3ef5a0bbda595de04404a82fa59ad188a..7100e282fdff4f900e4fd047e90d875b5573e056 100644 GIT binary patch delta 106 zcmZqZVQgq&oM0f!00ROH41z#5BM|@l|NlQom~pZrhyBKc62?hPIjjyzOD5WFE@b-6 m%=)3Dc><8hw!uOYqznd_fDCaU<^f{n$%2k;n-ADKFaZDvf){N7 delta 145 zcmZo@VQlDOoM0f!!~g{X3=AwlCL<94`~UwxNR)Z9BZvLQgc8O{OgXF%Dmrc%Z7yW` u&CF_$6Zi=YS^PzC@B2ORkT diff --git a/Candlestick.js b/Candlestick.js index 6e193c766..ed5cd58d9 100644 --- a/Candlestick.js +++ b/Candlestick.js @@ -1,11 +1,10 @@ function newAAMastersAAOliviaCandlesticks() { - var candles = []; // this changed. - let timePeriod = INITIAL_TIME_PERIOD; - + var candles = []; var plotArea = newPlotArea(); - var datetime = INITIAL_DATE; + let timePeriod; + var datetime; var candlesticks = { onLayerStatusChanged: onLayerStatusChanged, @@ -36,22 +35,48 @@ return candlesticks; - function initialize(pExchange, pMarket, pDatetime, pTimePeriod, chartLayersPanel) { + function initialize(pExchange, pMarket, pDatetime, pTimePeriod, chartLayersPanel, callBackFunction) { datetime = pDatetime; timePeriod = pTimePeriod; fileCache = newFileCache(); - fileCache.initialize("AAMasters", "AAOlivia", "Candles", "Candlesticks", pExchange, pMarket, pDatetime, onFileReady); + fileCache.initialize("AAMasters", "AAOlivia", "Market Candles", "Market Candlesticks", pExchange, pMarket, onFileReady); + + fileCursorCache = newFileCursorCache(); + fileCursorCache.initialize("AAMasters", "AAOlivia", "Daily Candles", "Daily Candlesticks", pExchange, pMarket, pDatetime, onFileReady); function onFileReady() { - let newMarketFile = fileCache.getMarketFile(pTimePeriod); + let newMarketFile = fileCache.getFile(pTimePeriod); if (newMarketFile !== undefined && marketFile === undefined) { // if the file ready is the one we need then it and we dont have it yet, then we will continue here. marketFile = newMarketFile; + finishInitialization(); + + } + + let newFileCursor = fileCursorCache.getFileCursor(pTimePeriod); + + if (newFileCursor !== undefined && marketFile === undefined) { // if the file ready is the one we need then it and we dont have it yet, then we will continue here. + + fileCursor = newFileCursor; + + let stringDate = datetime.getUTCFullYear() + '-' + pad(datetime.getUTCMonth() + 1, 2) + '-' + pad(datetime.getUTCDate(), 2); + + let dailyFile = fileCursor.files.get(stringDate); + + if (dailyFile !== undefined) { + + finishInitialization(); + + } + } + + function finishInitialization() { + recalculateScale(); layerStatus = chartLayersPanel.getLayerStatus(chartLayersPanel.layerNames.OLIVIA_CANDLES); @@ -62,7 +87,10 @@ viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); + callBackFunction(); + } + } } @@ -119,7 +147,7 @@ if (timePeriod >= _1_HOUR_IN_MILISECONDS) { - let newMarketFile = fileCache.getMarketFile(pTimePeriod); + let newMarketFile = fileCache.getFile(pTimePeriod); if (newMarketFile !== undefined) { @@ -148,7 +176,7 @@ datetime = newDatetime; recalculateCandles(); - fileCache.setDatetime(newDatetime); + fileCursorCache.setDatetime(newDatetime); } @@ -305,8 +333,6 @@ leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, candlesticks.container, plotArea); rightDate = getDateFromPoint(viewPort.visibleArea.topRight, candlesticks.container, plotArea); - - leftDate.setDate(leftDate.getDate() - daysOnSides); rightDate.setDate(rightDate.getDate() + daysOnSides); @@ -320,46 +346,22 @@ let stringDate = currentDate.getFullYear() + '-' + pad(currentDate.getMonth() + 1, 2) + '-' + pad(currentDate.getDate(), 2); - let dailyFile = fileCursor.dailyFiles.get(stringDate); + let dailyFile = fileCursor.files.get(stringDate); if (dailyFile !== undefined) { - const fileTimePeriod = 60 * 1000; - const totalCandles = dailyFile.length * fileTimePeriod / timePeriod; - const recordsPerCandle = timePeriod / fileTimePeriod; - - for (var i = 0; i < totalCandles; i++) { + for (var i = 0; i < dailyFile.length; i++) { var candle = newCandle(); - let min = dailyFile[i * recordsPerCandle][0]; - let max = dailyFile[i * recordsPerCandle][1]; + candle.min = dailyFile[i][0]; + candle.max = dailyFile[i][1]; - for (var j = 0; j < recordsPerCandle; j++) { + candle.open = dailyFile[i][2]; + candle.close = dailyFile[i][3]; - if (dailyFile[i * recordsPerCandle + j][0] < min) { - - min = dailyFile[i * recordsPerCandle + j][0]; - } - - if (dailyFile[i * recordsPerCandle + j][1] > max) { - - max = dailyFile[i * recordsPerCandle + j][1]; - } - - } - - candle.min = min; - candle.max = max; - - candle.open = dailyFile[i * recordsPerCandle][2]; - candle.close = dailyFile[i * recordsPerCandle + recordsPerCandle - 1][3]; - - candle.begin = dailyFile[i * recordsPerCandle][4]; - candle.end = dailyFile[i * recordsPerCandle + recordsPerCandle - 1][5]; - - candle.beginId = dailyFile[i * recordsPerCandle][6]; - candle.endId = dailyFile[i * recordsPerCandle + recordsPerCandle - 1][7]; + candle.begin = (new Date(dailyFile[i][4])).valueOf(); + candle.end = (new Date(dailyFile[i][5])).valueOf(); if (candle.open > candle.close) { candle.direction = 'down'; } if (candle.open < candle.close) { candle.direction = 'up'; } @@ -377,7 +379,7 @@ } - currentDate.setDate(currentDate.getDate() + 1); + currentDate.setUTCDate(currentDate.getUTCDate() + 1); } }