From ecda46ad1cd1d0a87190b05b954c13e46051b501 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 26 Apr 2018 09:38:38 +0200 Subject: [PATCH] Some Cleaning Part 1 --- .vs/AAWeb/v15/.suo | Bin 59392 -> 53248 bytes File.js => Files/File.js | 0 FileCache.js => Files/FileCache.js | 0 FileCloud.js => Files/FileCloud.js | 0 FileCursor.js => Files/FileCursor.js | 0 .../FileCursorCache.js | 0 FileServer.js => Files/FileServer.js | 0 MarketTrades.js | 366 ------------------ ProductStorage.js | 13 + Project.njsproj | 14 +- index.html | 15 +- server.js | 7 +- 12 files changed, 34 insertions(+), 381 deletions(-) rename File.js => Files/File.js (100%) rename FileCache.js => Files/FileCache.js (100%) rename FileCloud.js => Files/FileCloud.js (100%) rename FileCursor.js => Files/FileCursor.js (100%) rename FileCursorCache.js => Files/FileCursorCache.js (100%) rename FileServer.js => Files/FileServer.js (100%) delete mode 100644 MarketTrades.js diff --git a/.vs/AAWeb/v15/.suo b/.vs/AAWeb/v15/.suo index 04e0797965dc033030e26a1c1a6b797328ef949a..7c7690f6f3682a4e5b1d0417e9de1a6900bbd064 100644 GIT binary patch delta 4655 zcmc&%eNa@_6@T}!3oPn_fFKIGAP9yJStJO==mHCVMpnf70TNMGgF)F@RueT1o3U}G z6FbTt2~itU*P6tpt%g^vAFV(zCN&zdTCLF-HR*IZ(>Bu<+vqf*zw`DjqG0upbb9f( z=iGD8yYJq6&hOl(yDPx`qksc-vax;3U+m^j&x^^DBw6xky}Vw0LAT_M@)ber1Ey1F zkU6jdW2YnOPQa+f9H>2LI>=N_9}1bF>BAvMX!;~gvVVRbJrw#lAQs34B7qbj5n$gr zkYhBR`-7mHfjCKOl(L}A1&qLGfE@;F(gc~V>1-bhJx1$)%?7k+tv^ze2FPz~0oNr;2#;#2sr$bliT}tU zjXnM&QH@R2|L_=H;&WPKY!o-?R#>CBL2E)w$(o-@-J#{WLD&clElCmYsV;4F%Q)Mh z<`3teI&%E(14EZs{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rXad!X)ak z=ToWIOWp%hX+zB!#bGn%;UG9)fJcwxx&1c#9%p(E&xb!K7E{<}$}S(FSW^q+ZZ`k6v#0xj<~!o`=`w zlXsUFp&gZv4B>lAq^7PX`ymsx^kvcd{j(j?t$Chgfo8Oa%+k1W2d zY3Uk>Eb>+uRKwc#@uP^m^J>1S&Km8h`}9n`q1@?mX^wi1{TR+e&9Azvci^iI{Y1`j z7ZO~n1Z+>o?OG_Lg=GKS?QQMt`w9we1;q=C3i2wJ%`YHlQ_i@1eATrNc(SRhX$kcn zQUr%@edy_ZP;80gx3k_2cNe91rf3DKe&oq<3{N)YP|l%bdC@-7yEOISGwS7wMS^+{ zK5dAUY@;ZPG-~XDg>3q@FWvN+kwxV&`gdo$=|)kHDA7Mk4j;eB&}gFhDB6R!Wd zj(#`zOcR(Z5SPWoX*320f#AXMCYeW$_d!3`JHEHrzPS1%#C@h9Va)}+LCRRwDma-q z#w7U;Kg@26ydB(EbI(Xw+|=)<2hPXyPtY&pIbJ&4j!zf9BuDzmeb7Mer!whJhb$wh z^M7V&`WPfMGDFryjx}wR-3A*=yRrzD&3q(*&*96MZXxYVjI5y2GgZn4A7}aq%}P=={g!Z-=KA`(Ko4 z+WDztI*j7aCh`rIs*VoPo5wERvwNtfDoss0IUwlzIh%Ut=ZZnJQtw%-`qMXzBGh+k T_pz#o(MGwyGKQTlydwV(4k?P@ diff --git a/File.js b/Files/File.js similarity index 100% rename from File.js rename to Files/File.js diff --git a/FileCache.js b/Files/FileCache.js similarity index 100% rename from FileCache.js rename to Files/FileCache.js diff --git a/FileCloud.js b/Files/FileCloud.js similarity index 100% rename from FileCloud.js rename to Files/FileCloud.js diff --git a/FileCursor.js b/Files/FileCursor.js similarity index 100% rename from FileCursor.js rename to Files/FileCursor.js diff --git a/FileCursorCache.js b/Files/FileCursorCache.js similarity index 100% rename from FileCursorCache.js rename to Files/FileCursorCache.js diff --git a/FileServer.js b/Files/FileServer.js similarity index 100% rename from FileServer.js rename to Files/FileServer.js diff --git a/MarketTrades.js b/MarketTrades.js deleted file mode 100644 index fbe3f78f0..000000000 --- a/MarketTrades.js +++ /dev/null @@ -1,366 +0,0 @@ - - -function newMarketTrades() { - - /* - - The object mantains the information of the trades of a certain market. - - It is initially empty until it receives a request for trades from any of its clients. It tries to serve the request with already existing trades, - in case that request was done before, and if it wasnt, then it makes the request to a Server object and store the trades received. - - */ - - var trades = new Map(); // Here we store all the trades that we received from the server. - var marketId; - var exchangeId; - var server; - - let minId = 100000000000000; - let maxId = 0; - - let absoluteMinId; - let absoluteMaxId; - - var marketTrades = { - getTradesByDateRange: getTradesByDateRange, - getTradesById: getTradesById, - initialize: initialize - }; - - let processingRequest = false; - - const MAX_TRADES_PER_SERVER_REQUEST = 100000; - - let targetBeginId; - let targetEndId; - - let currentRecursion = 0; - const MAX_RECURSIVE_CALLS = 6; - let leftOrRight = "left"; - - //tradesSegments = []; // We will devide the whole history of this market in segments of 100K records, so as to fetch from the server no more than 100K a the time. - - return marketTrades; - - function initialize(exchange, market, callBackFunction) { - - exchangeId = exchange; - marketId = market; - - /* First we initialize the server that will allow us to retrieve data. */ - - server = newFileServer(); - server.initialize(); - - trades = new Map(); - - server.getLastTrades(marketId, exchangeId, onLastTradesReady); - - function onLastTradesReady(resultSet) { - - addTrades(resultSet); - - callBackFunction(); - - } - - } - - - - - - function getTradesById(initialId, finalId, callBackFunction) { - - /* - if (processingRequest === true) { - - return; - - } else { - - processingRequest = true; - - } - */ - - currentRecursion = 0; - processRequest(initialId, finalId, callBackFunction); - - } - - async function processRequest(initialId, finalId, callBackFunction) { - - if (absoluteMinId !== undefined && initialId < absoluteMinId) { - - initialId = absoluteMinId; // We can not deal with ids before the absolute minimun in existence. - - } - - if (absoluteMaxId !== undefined && finalId > absoluteMaxId) { - - finalId = absoluteMaxId; // We can not deal with ids after the absolute maximun in existence. - - } - - /* - - At this point we already have a collection of trades, and we know the min and max id of the collection. - We need to see if the requested range is within the collection or we need to ask for more trades to the Server. - - */ - - /* First scenario is that the range requested is fully inside of the set of trades we already have */ - - if (initialId >= minId && finalId <= maxId) { - - respondWithTradesById(); // We already have the trades needed. - return; - - } - - /* - - Second scenario is that there is a gap between the range requested and the set of trades we already have. - In this case the current set is obsolete and must be replaced by a new one. - - */ - - if (finalId < minId || initialId > maxId) { - - trades = new Map(); - - minId = 100000000000000; - maxId = 0; - targetBeginId = undefined; - targetEndId = undefined; - - if (finalId - initialId > MAX_TRADES_PER_SERVER_REQUEST) { - - targetBeginId = initialId; - targetEndId = finalId; - initialId = initialId + Math.trunc((finalId - initialId) / 2 - MAX_TRADES_PER_SERVER_REQUEST / 2); - finalId = initialId + MAX_TRADES_PER_SERVER_REQUEST; - } - - server.getTrades(initialId, finalId, marketId, exchangeId, onServerSecondResponse); - - return; - - } - - - /* The third and last scenario is when there is no gap, and the range requested expands the current set. */ - - checkBeforeTheCurrentRange(); - - function checkBeforeTheCurrentRange() { - - if (initialId < minId) { - - if (minId - initialId > MAX_TRADES_PER_SERVER_REQUEST) { - - targetBeginId = initialId; - - initialId = minId - MAX_TRADES_PER_SERVER_REQUEST; - } - - server.getTrades(initialId, minId - 1, marketId, exchangeId, onServerFirstResponse); - - } else { - checkAfterTheCurrentRange(); - } - } - - - function onServerFirstResponse(resultSet) { - - if (resultSet.length > 0) { - - let firstTradeId = resultSet[0][0][1]; - - if (initialId < firstTradeId) { - - /* This means that there are no more records before the Id received, which transform this id in the absolute minimum. */ - - absoluteMinId = firstTradeId; - - } - - addTrades(resultSet); - - } else { - - absoluteMinId = minId; - - } - - checkAfterTheCurrentRange(); - - } - - function checkAfterTheCurrentRange() { - - if (finalId > maxId) { - - if (finalId - maxId > MAX_TRADES_PER_SERVER_REQUEST) { - - targetFinalId = finalId; - - finalId = maxId + MAX_TRADES_PER_SERVER_REQUEST; - } - - server.getTrades(maxId + 1, finalId, marketId, exchangeId, onServerSecondResponse); - - } else { - respondWithTradesById(); - } - } - - function onServerSecondResponse(resultSet) { - - if (resultSet.length > 0) { - - let lastTradeId = resultSet[resultSet.length - 1][0][1]; - - if (finalId > lastTradeId) { - - /* This means that there are no more records after the Id received, which transform this id in the absolute maximun. */ - - absoluteMaxId = lastTradeId; - - } - - addTrades(resultSet); - - } else { - - absoluteMaxId = maxId; - - } - - respondWithTradesById(); - - } - - function respondWithTradesById() { - - let tradesToReturn = []; - - /* We are ready to create an array of the trades for the id range requested. For this we need to scan the whole Trades Map. */ - - for (let i = initialId; i <= finalId; i++) { - - let trade = trades.get(i); - - if (trade !== undefined) { - - tradesToReturn.push(trade); - - } - } - callBackFunction(tradesToReturn); - - processingRequest = false; - - if (currentRecursion !== MAX_RECURSIVE_CALLS) { - - if (leftOrRight === "left") { - leftOrRight = "right"; - if (minId > targetBeginId) { - processRequest(targetBeginId, finalId, callBackFunction); - currentRecursion++; - } - if (maxId < targetEndId) { - processRequest(initialId, targetEndId, callBackFunction); - currentRecursion++; - } - } else { - leftOrRight = "left"; - if (maxId < targetEndId) { - processRequest(initialId, targetEndId, callBackFunction); - currentRecursion++; - } - if (minId > targetBeginId) { - processRequest(targetBeginId, finalId, callBackFunction); - currentRecursion++; - } - } - - } - else { - currentRecursion = 0; - } - - - } - } - - - - function getTradesByDateRange(datetimeRange, callBackFunction) { - - /* So far, we only accept dates range against the current collection of trades we hold here. */ - - respondToCallerByDateRange(); - - function respondToCallerByDateRange() { - - let tradesToReturn = []; - - let begin = datetimeRange.begin.valueOf(); - let end = datetimeRange.end.valueOf(); - - /* We are ready to create an array of the trades for the date requested. For this we need to scan the whole Trades Map. */ - - for (let i = minId; i <= maxId; i++) { - - let trade = trades.get(i); - - if (trade !== undefined) { - - let now = trade.datetime.valueOf(); - - if (begin <= now && now < end) { - - tradesToReturn.push(trade); - - } - } - } - - callBackFunction(tradesToReturn); - - } - } - - - - - function addTrades(resultSet) { - - /* Last Trades are asked in reversed order, so we put it here in the correct order as it is going to be consumed */ - - for (let i = 0; i < resultSet.length; i++) { - - let row = resultSet[i]; - - var trade = newTrade(row[0][1], row[1][1], row[2][1], row[3][1], row[4][1], new Date(row[5][1])); - - trades.set(trade.id, trade); // Because it is a map, I don-t need to worry about duplicate records. - - if (trade.id < minId) { - - minId = trade.id; - - } - - if (trade.id > maxId) { - - maxId = trade.id; - - } - } - } -} \ No newline at end of file diff --git a/ProductStorage.js b/ProductStorage.js index fccceac74..cfb6e852c 100644 --- a/ProductStorage.js +++ b/ProductStorage.js @@ -98,6 +98,19 @@ function newProductStorage(pName) { } break; + case 'File Sequence': { + + thisObject.file = newFileSequence(); + thisObject.file.initialize(pDevTeam, pBot, pProduct, thisSet, pExchange, pMarket, onSingleFileReady); + dataSetsToLoad++; + + if (CONSOLE_LOG === true) { + + console.log("Product storage initialize File Sequence for " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); + + } + } + break; } function onCacheFileReady() { diff --git a/Project.njsproj b/Project.njsproj index 57dbdc3d1..f5667362e 100644 --- a/Project.njsproj +++ b/Project.njsproj @@ -53,16 +53,16 @@ Code - + Code - + Code - + Code - + Code @@ -74,7 +74,7 @@ - + Code @@ -86,7 +86,6 @@ - @@ -99,7 +98,7 @@ - + Code @@ -123,6 +122,7 @@ + diff --git a/index.html b/index.html index f89319c2e..28578b5a5 100644 --- a/index.html +++ b/index.html @@ -16,12 +16,7 @@ - - - - - - + @@ -37,7 +32,6 @@ - @@ -71,6 +65,13 @@ + + + + + + +