From 998a84478d5a59637d59426f220401b48565fbbc Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 6 May 2018 15:53:03 +0200 Subject: [PATCH] Competition Plotter Upgraded to use Sequence Files --- .vs/AAWeb/v15/.suo | Bin 71168 -> 70144 bytes Canvas.js | 15 ---- CompetitionStorage.js | 165 +++++++++++++++++++++++++++--------------- Files/FileSequence.js | 4 +- TimelineChart.js | 41 +++++------ server.js | 2 +- 6 files changed, 128 insertions(+), 99 deletions(-) diff --git a/.vs/AAWeb/v15/.suo b/.vs/AAWeb/v15/.suo index 92594446530b36cbd1d06682cc33ee7391c184dd..c095d5d550c2105e72e7544eeaa8e52ee6865b83 100644 GIT binary patch delta 4515 zcmd6q3s93+7RSH)k;I?@5)wl|9syC&3I-n(5G6>&M{NN`ag|k3Y0@ zksPa5XLo9JJKNo=n|z~oclwB{%=TZ6l&XcFH!G=yF+bONLg?1VPAf72akvL17GSKa|ptbN&H$(9+2aF z19-y;$om1Uubhlr3FZLaHE&};o&bgbHOK>8&r=xWUSK%T1?csVdxIRGP9+F-??e5e z7zjrADtIS-Ajoj2aj)tcGQM4bfi5!sj>K!UI>ZHFuH-A*kmj%i=WCGq80yg}E_ z+^Q_5=5uaE)05yM{>X$7i~TBu3*aL781P1)BLA;XzJ&a9pL`kl6`yl$;m&1&_cJ;`;*f!QT_!=FOjC~3CXhK4bfc@BDUi{k6eK*12aLQ z$i#kP1EZXMGe~(XTAzZgq)Is0{9;_Voc<0EKepMlIqEIQj!t7FefG3Ik{nbJMBYacnw zL}!uc57Nyle~^~iRWW$02zYYN6`iX@M-rlML6VH`ULAg3(Bw5yRDzP9w|w*Wn&>=) z_q`@cm^o4P2}-X3p8kIVAYWK2*o4J6t;#qQmZAMozLq(ED>^G>&Pp+?%X&;3af3QZDD!Y zgA)z!*|}=hg}z-p0Bv}uwpMbTpV-~|9=yx)2#abp4;b2-vZ!h>X`1w1_=vSU`GdV8 zhgb3g?42EBtthW5$;m0U&MxWljq#xms%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F$Gm80()JBYnNo#_c8MbDs!!Yw{>4(+!cnDd<~; z3SC?2mKUs}OkNIsAFhVFH`=3ib2VH8SI50i-)q{dY3RJ**o8K!-=BcF3A%oDbqGHVM$`J(6s*k|Uv!=qj#|HFc^$krmc#4o1i08=q_hv7 z=2PbUiW zmGm`B#bsaV>^onj<XGvo9Mgf3(LbLpOuF{UvmC(b7~(SoH>=Q z^KInHp(!v@Af>(BrxPl^WS<$q~p!|a*iNXGvcIK6*1 diff --git a/Canvas.js b/Canvas.js index b237269af..363b6ae57 100644 --- a/Canvas.js +++ b/Canvas.js @@ -398,21 +398,6 @@ function newCanvas() { floatingObject.currentPosition.x = dragVector.upX; floatingObject.currentPosition.y = dragVector.upY; - /* Now we estimate if the drag was towards the Target Point of the floatingObject or not. */ - - let distDown = distance(dragVector.downX, dragVector.downY, floatingObject.targetPosition.x, floatingObject.targetPosition.y); - let distUp = distance(dragVector.upX, dragVector.upY, floatingObject.targetPosition.x, floatingObject.targetPosition.y); - - let mZoomValue; - - if (distDown < distUp) { - - mZoomValue = 1; - } else { - mZoomValue = -1; - } - - //floatingObject.container.zoom.mZoom(mZoomValue); // Zoom is applied to floatingObject mass of all floatingObjects in the same container. } if (containerDragStarted || viewPortBeingDragged) { diff --git a/CompetitionStorage.js b/CompetitionStorage.js index 3b27b00ea..14e476777 100644 --- a/CompetitionStorage.js +++ b/CompetitionStorage.js @@ -1,20 +1,15 @@  function newCompetitionStorage(pName) { - const CONSOLE_LOG = false; - - /* - - This object will initialize children objects that will end up loading the data of each participant on the competition. - - At the same time it will raise an event for each underlaying file being loaded, so that the UI can reflect the progress to the end user. - - */ + const MODULE_NAME = "Competition Storage"; + const INFO_LOG = false; + const ERROR_LOG = true; + const logger = newDebugLog(); + logger.fileName = MODULE_NAME; let thisObject = { - files: new Map(), - + competitorsSequences: [], eventHandler: undefined, initialize: initialize @@ -26,84 +21,136 @@ function newCompetitionStorage(pName) { thisObject.eventHandler.name = "Storage-" + pName; + let fileSequences = []; + return thisObject; - function initialize(pHost, pCompetition, callBackFunction) { + function initialize(pHost, pCompetition, pExchange, pMarket, callBackFunction) { - if (CONSOLE_LOG === true) { + try { - console.log("Competition storage initialize for " + pHost.codeName + "-" + pCompetition.codeName); + if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); } + if (INFO_LOG === true) { logger.write("[INFO] initialize -> key = " + pHost.codeName + "-" + pCompetition.codeName); } - } + let dataSetsToLoad = 0; + let dataSetsLoaded = 0; - let dataSetsToLoad = 0; - let dataSetsLoaded = 0; + fileSequences = []; - for (let i = 0; i < pCompetition.participants.length; i++) { + for (let j = 0; j < pCompetition.participants.length; j++) { - let devTeam = ecosystem.getTeam(pCompetition.participants[i].devTeam); - let bot = ecosystem.getBot(devTeam, pCompetition.participants[i].bot) - let product = ecosystem.getProduct(bot, "Live Trading History"); + let devTeam = ecosystem.getTeam(pCompetition.participants[j].devTeam); + let bot = ecosystem.getBot(devTeam, pCompetition.participants[j].bot) + let product = ecosystem.getProduct(bot, "Competition Trading History"); - for (let i = 0; i < product.dataSets.length; i++) { + if (INFO_LOG === true) { logger.write("[INFO] initialize -> key = " + devTeam.codeName + "-" + bot.codeName + "-" + product.codeName); } - let thisSet = product.dataSets[i]; + for (let i = 0; i < product.dataSets.length; i++) { - switch (thisSet.type) { + let thisSet = product.dataSets[i]; - case 'Single File': { + switch (thisSet.type) { + case 'File Sequence': { - let singleFile = newSingleFile(); - singleFile.initialize(devTeam, bot, product, thisSet, undefined, undefined, onSingleFileReady); - thisObject.files.set(pCompetition.participants[i].devTeam + "-" + pCompetition.participants[i].bot, singleFile); - dataSetsToLoad++; + if (INFO_LOG === true) { logger.write("[INFO] initialize -> File Sequence -> key = " + pHost.codeName + "-" + pCompetition.codeName + "-" + devTeam.codeName + "-" + bot.codeName + "-" + product.codeName); } - if (CONSOLE_LOG === true) { + let fileSequence = newFileSequence(); + fileSequence.initialize(devTeam, bot, product, thisSet, pExchange, pMarket, onFileSequenceReady); + fileSequences.push(fileSequence); + dataSetsToLoad++; + } + break; + } - console.log("Competition storage initialize Single File for " + devTeam.codeName + "-" + bot.codeName + "-" + product.codeName); + function onFileSequenceReady(err, pCaller) { + try { + + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> Entering function."); } + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> key = " + pHost.codeName + "-" + pCompetition.codeName + "-" + devTeam.codeName + "-" + bot.codeName + "-" + product.codeName); } + + switch (err.result) { + case GLOBAL.DEFAULT_OK_RESPONSE.result: { + + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> Received OK Response."); } + break; + } + + case GLOBAL.DEFAULT_FAIL_RESPONSE.result: { + + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> Received FAIL Response."); } + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE); + return; + } + + case GLOBAL.CUSTOM_FAIL_RESPONSE.result: { + + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> Received CUSTOM FAIL Response."); } + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> err.message = " + err.message); } + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> This bot has not starting competing yet."); } + + break; + } + + default: { + + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> Received Unexpected Response."); } + callBackFunction(err); + return; + } + } + + let event = { + totalValue: pCaller.getExpectedFiles(), + currentValue: pCaller.getFilesLoaded() + } + + thisObject.eventHandler.raiseEvent('File Sequence Loaded', event); + + if (event.currentValue === event.totalValue) { + + dataSetsLoaded++; + + checkInitializeComplete(); + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> onFileSequenceReady -> err = " + err); } + callBackFunction(GLOBAL.CUSTOM_FAIL_RESPONSE); } } - break; - } + function checkInitializeComplete() { - function onSingleFileReady() { + try { - if (CONSOLE_LOG === true) { + if (INFO_LOG === true) { logger.write("[INFO] checkInitializeComplete -> Entering function."); } + if (INFO_LOG === true) { logger.write("[INFO] checkInitializeComplete -> key = " + pHost.codeName + "-" + pCompetition.codeName + "-" + devTeam.codeName + "-" + bot.codeName + "-" + product.codeName); } - console.log("Competition storage initialize onSingleFileReady for " + devTeam.codeName + "-" + bot.codeName + "-" + product.codeName); + if (dataSetsLoaded === dataSetsToLoad) { - } + callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE); - let event = { - totalValue: 1, - currentValue: 1 - } + } - thisObject.eventHandler.raiseEvent('Single File Loaded', event); + } catch (err) { - if (event.currentValue === event.totalValue) { - - dataSetsLoaded++; - checkInitializeComplete(); - } - } - - function checkInitializeComplete() { - - if (CONSOLE_LOG === true) { - - console.log("Competition storage initialize checkInitializeComplete for " + devTeam.codeName + "-" + bot.codeName + "-" + product.codeName); - - } - - if (dataSetsLoaded === dataSetsToLoad) { - callBackFunction(); + if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> checkInitializeComplete -> err = " + err); } + callBackFunction(GLOBAL.CUSTOM_FAIL_RESPONSE); + } } } } + + thisObject.competitorsSequences.push(fileSequences); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err); } + callBackFunction(GLOBAL.CUSTOM_FAIL_RESPONSE); } } + } diff --git a/Files/FileSequence.js b/Files/FileSequence.js index 6f485fd95..cc7c8aa99 100644 --- a/Files/FileSequence.js +++ b/Files/FileSequence.js @@ -20,7 +20,7 @@ function newFileSequence() { let files = new Map; - let maxSequence; + let maxSequence = -1; // This is replaced by the content of the sequence file, which contains an index that starts on zero. In the case that the sequence file is not found the default value is -1 sin when you add 1 it gives you the amount of files in the sequence, zero. return thisObject; @@ -81,7 +81,7 @@ function newFileSequence() { if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Received CUSTOM FAIL Response."); } if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> err.message = " + err.message); } - callBackFunction(err); + callBackFunction(err, thisObject); return; } diff --git a/TimelineChart.js b/TimelineChart.js index 3fc9a496c..d09f05c2e 100644 --- a/TimelineChart.js +++ b/TimelineChart.js @@ -82,9 +82,6 @@ if (INFO_LOG === true) { logger.write("[INFO] initializeCompetitionPlotters -> Entering function."); } - if (INFO_LOG === true) { logger.write("[INFO] initializeCompetitionPlotters -> Aborting function until Competition Plotter is ready."); } - return; - /* At this current version of the platform, we will support only one competition with only one plotter. */ const COMPETITION_HOST = "AAArena"; @@ -96,11 +93,11 @@ let host = ecosystem.getHost(COMPETITION_HOST); let competition = ecosystem.getCompetition(host, COMPETITION); - storage.initialize(host, competition, onStorageInitialized); + storage.initialize(host, competition, DEFAULT_EXCHANGE, DEFAULT_MARKET, onCompetitionStorageInitialized); - function onStorageInitialized(err) { + function onCompetitionStorageInitialized(err) { - if (INFO_LOG === true) { logger.write("[INFO] initializeCompetitionPlotters -> onStorageInitialized -> Entering function."); } + if (INFO_LOG === true) { logger.write("[INFO] initializeCompetitionPlotters -> onCompetitionStorageInitialized -> Entering function."); } /* Now we have all the initial data loaded and ready to be delivered to the new instance of the plotter. */ @@ -121,7 +118,7 @@ function onPlotterInizialized() { - if (INFO_LOG === true) { logger.write("[INFO] initializeCompetitionPlotters -> onStorageInitialized -> onPlotterInizialized -> Entering function."); } + if (INFO_LOG === true) { logger.write("[INFO] initializeCompetitionPlotters -> onCompetitionStorageInitialized -> onPlotterInizialized -> Entering function."); } let competitionPlotter = { plotter: plotter, @@ -198,40 +195,40 @@ } } - storage.initialize(pProductCard.devTeam, pProductCard.bot, pProductCard.product, DEFAULT_EXCHANGE, DEFAULT_MARKET, datetime, timePeriod, onStorageInitialized) ; + storage.initialize(pProductCard.devTeam, pProductCard.bot, pProductCard.product, DEFAULT_EXCHANGE, DEFAULT_MARKET, datetime, timePeriod, onProductStorageInitialized) ; - function onStorageInitialized(err) { + function onProductStorageInitialized(err) { - if (INFO_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onStorageInitialized -> Entering function."); } - if (INFO_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onStorageInitialized -> key = " + pProductCard.devTeam.codeName + "-" + pProductCard.bot.codeName + "-" + pProductCard.product.codeName); } + if (INFO_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onProductStorageInitialized -> Entering function."); } + if (INFO_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onProductStorageInitialized -> key = " + pProductCard.devTeam.codeName + "-" + pProductCard.bot.codeName + "-" + pProductCard.product.codeName); } switch (err.result) { case GLOBAL.DEFAULT_OK_RESPONSE.result: { - if (INFO_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onStorageInitialized -> Received OK Response."); } - if (INFO_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onStorageInitialized -> The plotter will be started."); } + if (INFO_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onProductStorageInitialized -> Received OK Response."); } + if (INFO_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onProductStorageInitialized -> The plotter will be started."); } break; } case GLOBAL.DEFAULT_FAIL_RESPONSE.result: { - if (INFO_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onStorageInitialized -> Received FAIL Response."); } - if (INFO_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onStorageInitialized -> The plotter will not be started."); } + if (INFO_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onProductStorageInitialized -> Received FAIL Response."); } + if (INFO_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onProductStorageInitialized -> The plotter will not be started."); } return; } case GLOBAL.CUSTOM_FAIL_RESPONSE.result: { - if (INFO_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onStorageInitialized -> Received CUSTOM FAIL Response."); } - if (INFO_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onStorageInitialized -> err.message = " + err.message); } - if (INFO_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onStorageInitialized -> The plotter will not be started."); } + if (INFO_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onProductStorageInitialized -> Received CUSTOM FAIL Response."); } + if (INFO_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onProductStorageInitialized -> err.message = " + err.message); } + if (INFO_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onProductStorageInitialized -> The plotter will not be started."); } return; } default: { - if (INFO_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onStorageInitialized -> Received Unexpected Response."); } - if (INFO_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onStorageInitialized -> The plotter will not be started."); } + if (INFO_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onProductStorageInitialized -> Received Unexpected Response."); } + if (INFO_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onProductStorageInitialized -> The plotter will not be started."); } return; } } @@ -255,8 +252,8 @@ function onPlotterInizialized() { - if (INFO_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onStorageInitialized -> onPlotterInizialized -> Entering function."); } - if (INFO_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onStorageInitialized -> onPlotterInizialized -> key = " + pProductCard.product.plotter.devTeam + "-" + pProductCard.product.plotter.repo + "-" + pProductCard.product.plotter.moduleName); } + if (INFO_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onProductStorageInitialized -> onPlotterInizialized -> Entering function."); } + if (INFO_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onProductStorageInitialized -> onPlotterInizialized -> key = " + pProductCard.product.plotter.devTeam + "-" + pProductCard.product.plotter.repo + "-" + pProductCard.product.plotter.moduleName); } try { plotter.positionAtDatetime(INITIAL_DATE); diff --git a/server.js b/server.js index 626140bfd..f4b180fca 100644 --- a/server.js +++ b/server.js @@ -6,7 +6,7 @@ if (CONSOLE_LOG === true) { } -const DEBUG_MODE = true; // This forces the server to read Plotters from the local drive. +const DEBUG_MODE = false; // This forces the server to read Plotters from the local drive. if (CONSOLE_LOG === true && DEBUG_MODE === true) {