From 42d9557a564369cb49972e961684dd5c30be94f9 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 21 Feb 2018 11:04:42 +0100 Subject: [PATCH] Optimized file cursors --- .vs/AAWebPlatform/v15/.suo | Bin 56320 -> 58368 bytes Dashboard.js | 26 +++++ FileCursor.js | 205 ++++++++++++++++++++++++++++++++++++- FileCursorCache.js | 23 +++-- 4 files changed, 245 insertions(+), 9 deletions(-) diff --git a/.vs/AAWebPlatform/v15/.suo b/.vs/AAWebPlatform/v15/.suo index 752d890c9987e833e3c5a30080e1dc0aedc9719a..87e963a56f1686141b416cb5597831395cbf8308 100644 GIT binary patch delta 1306 zcmd6kYe-a45XbkNd++XEU2WBMQ!~@l+OpCfl%@=D^>yVQK&c+up|cVrVks+R~EgX4yFuWVVr z0TVIbe`HOEqFp)beh%sgBonDcGLVf}JP{g=Mp6l3N(6KoZC&N&kRS{N%B>fHC~Qo( z1_?&OksL&H2tSNbYA!l?NGZ%$Gm@RCijfjTr0hjohV0Y){b&2TqPV*0; zbs_Fq@kY3AQ)Y8j8WT{pncViai)W61=3aCAb} zgDQBly_hHO7?pxMuthO}Np}s*2R*RBt-yCz3S8RL0O>U*h;-WEv$Ka>#%R5AxXN>^ zik~iMqcC1-f@Os^KDygTc}H;}kxjasSy^zpU|F#0|G=}N?(iz;DqRxvyQ`me!CsR~ zN+E$pK&#t5Q@HiQDT!53cwKJ^+kzbi&Q>9y#qF8t?|Jn=SX>~CHVKKxj0%=U;ZkiZ zxQlFj+ssmTil8S`Hj*1N@E#;r@2=6+HdBI zdPfMW#H}CEi>}1x>u~dHWpJGT!! zCNSZ#z({uxkGnS}!NP6_clhqAV9$tv-bbN4;l)RVJ)-O_Wv^v6Oxdu^-pjuL!Na-5 delta 1121 zcmb`FUr1AN6vy}b-Fvs|oVMxIr4xo`O|4vzQCW&jD#%K$)~sctM9t>1(Eiz<6{!93 zA@7NZ9zuUusBi5jA?3(GqL-qG$SfixBBIAIh;W@>ZPZH-MF&2d?>WD7@9&&*Z|I>E z8kH`&vZ*d+W}VK6QpB^-XjEh+xUZDm^0yI9A5i+D#p50Ppx!{pdpKt3)?_Q#Rka#x zqsdroLxh&mXTaaH@#R? z*^)4mj)?u1qOU;85cnqB61JmQhpdNer6f<3crmI)b|5liVH3GY&8RRD z-H$%-b8K_i=%(Clj*xJ&5T*!W=~S~GrJXi@+}cH03T2sc*gla66GcAma1Iz?VgU-* zT|1e9*Ofh_3CikAtF40?agg~p;$}{Ue zNvw@RK23(QU3$wJyeMuPP}soIcqn$wJB#=&;wHA3D^9t&VTNedHvL-6h)EB35qQ#A zz+Fvu2z&^djN)^P|E%I>Y=9JgIzWk1gSldS#Szgim&50%f*GBgUmR&CY?;hX$?ODW zXH~88)t~l5*aga}=zrdl#I8~3-8WyFK6a0=$1>zR&xEQW6Q6&3O2IQsu}R7%W%h=$Y5E;kA#XhZ diff --git a/Dashboard.js b/Dashboard.js index 5c2f4766d..43dccd81c 100644 --- a/Dashboard.js +++ b/Dashboard.js @@ -34,6 +34,32 @@ let dailyFilePeriods = 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]; + + } + } +} + + var viewPort = newViewPort(); diff --git a/FileCursor.js b/FileCursor.js index b16b759a3..5c71f822c 100644 --- a/FileCursor.js +++ b/FileCursor.js @@ -6,6 +6,7 @@ function newFileCursor() { let fileCursor = { setDatetime: setDatetime, + setTimePeriod: setTimePeriod, files: undefined, initialize: initialize } @@ -20,10 +21,11 @@ function newFileCursor() { let fileCloud; let product; let periodName; + let timePeriod; return fileCursor; - function initialize(pFileCloud, pProduct, pExchange, pMarket, pPeriodName, pCursorDate, callBackFunction) { + function initialize(pFileCloud, pProduct, pExchange, pMarket, pPeriodName, pCursorDate, pTimePeriod, callBackFunction) { market = pMarket; exchange = pExchange; @@ -31,11 +33,212 @@ function newFileCursor() { product = pProduct; periodName = pPeriodName; cursorDate = pCursorDate; + timePeriod = pTimePeriod; + + setTimePeriod(pTimePeriod); getFiles(callBackFunction); } + function setTimePeriod(pTimePeriod) { + + /* + + We are implementing here an algorithm designed to save bandwidth, memory and processing power at the browser. + We say there is a saving mode where the cursor is running at a minimum size. When the end user aproaches the time period the cursor + is set, then it should exit the saving mode and go to its actual size. + + To do this we are going to measure the distance from the Time Period received to the one the cursors was initialized with. + If these periods are consecutive, it means that the cursor should exit saving mode and load its full size. + + */ + + let positionA; + + for (let i = 0; i < dailyFilePeriods.length; i++) { + + let period = dailyFilePeriods[i]; + + if (period[0] === pTimePeriod) { + + positionA = i; + + } + + if (period[0] === timePeriod) { + + positionB = i; + + } + } + + if (Math.abs(positionB - positionA) <= 1) { + + exitSavingMode(); + console.log("File Cursor with period " + periodName + " EXITED saving mode after being notified the user is at period " + convertTimePeriodToName(pTimePeriod)); + + } else { + + enterSavingMode(); + console.log("File Cursor with period " + periodName + " ENTERED saving mode after being notified the user is at period " + convertTimePeriodToName(pTimePeriod)); + + } + + + function enterSavingMode() { + + switch (timePeriod) { + + case _45_MINUTES_IN_MILISECONDS: + { + minCursorSize = 1; + maxCursorSize = 30; + } + break; + case _40_MINUTES_IN_MILISECONDS: + { + minCursorSize = 1; + maxCursorSize = 20; + } + break; + case _30_MINUTES_IN_MILISECONDS: + { + minCursorSize = 1; + maxCursorSize = 15; + } + break; + case _20_MINUTES_IN_MILISECONDS: + { + minCursorSize = 1; + maxCursorSize = 15; + } + break; + case _15_MINUTES_IN_MILISECONDS: + { + minCursorSize = 1; + maxCursorSize = 15; + } + break; + case _10_MINUTES_IN_MILISECONDS: + { + minCursorSize = 1; + maxCursorSize = 15; + } + break; + case _5_MINUTES_IN_MILISECONDS: + { + minCursorSize = 1; + maxCursorSize = 15; + } + break; + case _4_MINUTES_IN_MILISECONDS: + { + minCursorSize = 1; + maxCursorSize = 15; + } + break; + case _3_MINUTES_IN_MILISECONDS: + { + minCursorSize = 1; + maxCursorSize = 15; + } + break; + case _2_MINUTES_IN_MILISECONDS: + { + minCursorSize = 1; + maxCursorSize = 15; + } + break; + case _1_MINUTE_IN_MILISECONDS: + { + minCursorSize = 1; + maxCursorSize = 15; + } + break; + default: + } + } + + function exitSavingMode() { + + switch (timePeriod) { + + case _45_MINUTES_IN_MILISECONDS: + { + minCursorSize = 10; + maxCursorSize = 30; + } + break; + case _40_MINUTES_IN_MILISECONDS: + { + minCursorSize = 8; + maxCursorSize = 20; + } + break; + case _30_MINUTES_IN_MILISECONDS: + { + minCursorSize = 6; + maxCursorSize = 15; + } + break; + case _20_MINUTES_IN_MILISECONDS: + { + minCursorSize = 5; + maxCursorSize = 15; + } + break; + case _15_MINUTES_IN_MILISECONDS: + { + minCursorSize = 5; + maxCursorSize = 15; + } + break; + case _10_MINUTES_IN_MILISECONDS: + { + minCursorSize = 5; + maxCursorSize = 15; + } + break; + case _5_MINUTES_IN_MILISECONDS: + { + minCursorSize = 3; + maxCursorSize = 15; + } + break; + case _4_MINUTES_IN_MILISECONDS: + { + minCursorSize = 3; + maxCursorSize = 15; + } + break; + case _3_MINUTES_IN_MILISECONDS: + { + minCursorSize = 3; + maxCursorSize = 15; + } + break; + case _2_MINUTES_IN_MILISECONDS: + { + minCursorSize = 3; + maxCursorSize = 15; + } + break; + case _1_MINUTE_IN_MILISECONDS: + { + minCursorSize = 3; + maxCursorSize = 15; + } + break; + default: + } + } + + + } + + + function setDatetime(datetime) { if (datetime === undefined) { return; } diff --git a/FileCursorCache.js b/FileCursorCache.js index eaa283df4..24c89c631 100644 --- a/FileCursorCache.js +++ b/FileCursorCache.js @@ -12,11 +12,9 @@ function newFileCursorCache() { let marketFiles = new Map; let fileCursors = new Map; - let datetime; - return fileCursorCache; - function initialize(pTeamCodeName, pBotCodeName, pProductCodeName, pLayerCodeName, pExchange, pMarket, pDatetime, callBackFunction) { + function initialize(pTeamCodeName, pBotCodeName, pProductCodeName, pLayerCodeName, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { let product = ecosystem.getProduct(ecosystem.getBot(ecosystem.getTeam(pTeamCodeName), pBotCodeName), pProductCodeName); @@ -55,7 +53,7 @@ function newFileCursorCache() { if (layer.validPeriods.includes(periodName) === true) { let fileCursor = newFileCursor(); - fileCursor.initialize(fileCloud, product, exchange, pMarket, periodName, pDatetime, onFileReceived); + fileCursor.initialize(fileCloud, product, exchange, pMarket, periodName, pDatetime, pTimePeriod, onFileReceived); fileCursors.set(periodTime, fileCursor); @@ -74,15 +72,24 @@ function newFileCursorCache() { } - function setDatetime(newDatetime) { - - datetime = newDatetime; + function setDatetime(pDatetime) { fileCursors.forEach(setDatetimeToEach) function setDatetimeToEach(value, key, map) { - value.setDatetime(newDatetime); + value.setDatetime(pDatetime); + + } + } + + function setTimePeriod(pTimePeriod) { + + fileCursors.forEach(setTimePeriodToEach) + + function setTimePeriodToEach(value, key, map) { + + value.setTimePeriod(pTimePeriod); } }