From 308bd0db5f514aae8a1aef1a8f28d2ef46dbd44e Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 12 Mar 2018 10:55:21 +0100 Subject: [PATCH] Competition Plotter connected, ready for debug --- .vs/AAWebPlatform/v15/.suo | Bin 79360 -> 81408 bytes AAWebPlatform.njsproj | 3 + CompetitionStorage.js | 109 +++++++++++++++++++++++++++++++++++++ Ecosystem.js | 21 +++++++ Plotters.js | 4 +- ProductStorage.js | 16 +++--- TimelineChart.js | 73 +++++++++++++++++++++---- index.html | 1 + server.js | 24 ++++---- 9 files changed, 219 insertions(+), 32 deletions(-) create mode 100644 CompetitionStorage.js diff --git a/.vs/AAWebPlatform/v15/.suo b/.vs/AAWebPlatform/v15/.suo index 9d90c68614354ceb8c02294dcdc21a86f7dd65df..cf7d5572cca696c04f344e2c37f7907368723195 100644 GIT binary patch delta 3063 zcmd6p3viUx7017GcQ>0&b~l^HZk7bhvI&?-fP^Hxjd@Z;3`syxAwrM<2_zdfD-Vr% zkcbsiC3|KX+afHVOxpU0@ZAoXI*JiSCX6C=+A?ERxVRu)Zu5)n^~BPxkF zBJ|FbFyBP}4B}40qbRLPdRXN=@-v7SVgfOhm`2<|@Wj%{P9kO#bBH`5i^wHr5)=SM zPfR2-iRnZ#5lh@h%qPYZJh3RU`AUkSxX4K*c(sLOiwSN}M)scWie$_*MNTcC%o3uU zs30a2%Lr~bi)_P~&-tqEig^7)RDjz}E=z4#O&wNy;|&ff3E&&1Vt+)ve%zwY8>rGr zO+u=0mz*N0ELEbgvI#Kng3_LY=jEmjkuo@P<}p&h#oDTaC~-bPs*G^8ao zQ>Hbn9e3!r&Ni_fMHX6fgopvT)wWxAlN$4G@aMXu%Mk=E!7ZfQc^0%dw_dvUOoqr! zW8GtgJq>-`UE26!z+z`M`X+Q?-uxIDZ{a&ef7U|S*IhB)w4Z9mdTRx>GLkw}SLwBxRYF#+eF3zn07PD- zHdde>ep9$zy4DW?ihOUx{Zu+^myhP}0<})4-^ zb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ecc --- /dev/null +++ b/CompetitionStorage.js @@ -0,0 +1,109 @@ + +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. + + */ + + let thisObject = { + + files: new Map(), + + eventHandler: undefined, + initialize: initialize + + } + + thisObject.eventHandler = newEventHandler(); + + /* We name the event Handler to easy debugging. */ + + thisObject.eventHandler.name = "Storage-" + pName; + + return thisObject; + + function initialize(pHost, pCompetition, callBackFunction) { + + if (CONSOLE_LOG === true) { + + console.log("Competition storage initialize for " + pHost.codeName + "-" + pCompetition.codeName); + + } + + let dataSetsToLoad = 0; + let dataSetsLoaded = 0; + + for (let i = 0; i < pCompetition.participants.length; i++) { + + let devTeam = ecosystem.getTeam(pCompetition.participants[i].devTeam); + let bot = ecosystem.getBot(devTeam, pCompetition.participants[i].bot) + let product = ecosystem.getProduct(bot, "Trading History"); + + for (let i = 0; i < product.sets.length; i++) { + + let thisSet = product.sets[i]; + + switch (thisSet.type) { + + case 'Single File': { + + let file = newFile(); + file.initialize(devTeam, bot, product, thisSet, undefined, undefined, onSingleFileReady); + thisObject.files.set(devTeam.codeName+ "-" + bot.codeName, file); + dataSetsToLoad++; + + if (CONSOLE_LOG === true) { + + console.log("Competition storage initialize Single File for " + devTeam.codeName + "-" + bot.codeName + "-" + product.codeName); + + } + } + break; + + } + + function onSingleFileReady() { + + if (CONSOLE_LOG === true) { + + console.log("Competition storage initialize onSingleFileReady for " + devTeam.codeName + "-" + bot.codeName + "-" + product.codeName); + + } + + let event = { + totalValue: 1, + currentValue: 1 + } + + thisObject.eventHandler.raiseEvent('Single File Loaded', event); + + 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(); + } + } + } + } + } +} + diff --git a/Ecosystem.js b/Ecosystem.js index 91a2206ba..9da330e92 100644 --- a/Ecosystem.js +++ b/Ecosystem.js @@ -21,6 +21,27 @@ function newEcosystem() { } + function getHost(pHostCodeName) { + + for (let i = 0; i < ECOSYSTEM.hosts.length; i++) { + + if (ECOSYSTEM.hosts[i].codeName === pHostCodeName) { + + return ECOSYSTEM.hosts[i]; + } + } + } + + function getCompetition(pHost, pCompetitionCodeName) { + + for (let i = 0; i < pHost.competitions.length; i++) { + + if (pHost.competitions[i].codeName === pCompetitionCodeName) { + + return pHost.competitions[i]; + } + } + } function getTeams() { diff --git a/Plotters.js b/Plotters.js index 554f17a68..a481a565a 100644 --- a/Plotters.js +++ b/Plotters.js @@ -1,9 +1,9 @@  -function getNewPlotter(pDevTeam, pRepo, pModule) { +function getNewPlotter(pDevTeamOrHost, pRepo, pModule) { let plotter; - let fullCode = pDevTeam + pRepo + pModule; + let fullCode = pDevTeamOrHost + pRepo + pModule; fullCode = fullCode.replace(/-/g, ""); switch (fullCode) { diff --git a/ProductStorage.js b/ProductStorage.js index 7e5266058..d5281a674 100644 --- a/ProductStorage.js +++ b/ProductStorage.js @@ -44,7 +44,7 @@ function newProductStorage(pName) { if (CONSOLE_LOG === true) { - console.log("Storage initialize for " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); + console.log("Product storage initialize for " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); } @@ -64,7 +64,7 @@ function newProductStorage(pName) { if (CONSOLE_LOG === true) { - console.log("Storage initialize Market Files for " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); + console.log("Product storage initialize Market Files for " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); } } @@ -78,7 +78,7 @@ function newProductStorage(pName) { if (CONSOLE_LOG === true) { - console.log("Storage initialize Daily Files for " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); + console.log("Product storage initialize Daily Files for " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); } } @@ -92,7 +92,7 @@ function newProductStorage(pName) { if (CONSOLE_LOG === true) { - console.log("Storage initialize Single File for " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); + console.log("Product storage initialize Single File for " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); } } @@ -104,7 +104,7 @@ function newProductStorage(pName) { if (CONSOLE_LOG === true) { - console.log("Storage initialize onCacheFileReady for " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); + console.log("Product storage initialize onCacheFileReady for " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); } @@ -127,7 +127,7 @@ function newProductStorage(pName) { if (CONSOLE_LOG === true) { - console.log("Storage initialize onFileCursorReady for " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); + console.log("Product storage initialize onFileCursorReady for " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); } @@ -150,7 +150,7 @@ function newProductStorage(pName) { if (CONSOLE_LOG === true) { - console.log("Storage initialize onSingleFileReady for " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); + console.log("Product storage initialize onSingleFileReady for " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); } @@ -173,7 +173,7 @@ function newProductStorage(pName) { if (CONSOLE_LOG === true) { - console.log("Storage initialize checkInitializeComplete for " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); + console.log("Product storage initialize checkInitializeComplete for " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); } diff --git a/TimelineChart.js b/TimelineChart.js index 10604b9a8..fb5a305d1 100644 --- a/TimelineChart.js +++ b/TimelineChart.js @@ -79,7 +79,8 @@ function newTimelineChart() { viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); - initializePlotters(); + initializeProductPlotters(); + initializeCompetitionPlotters(); callBackFunction(); @@ -87,7 +88,64 @@ function newTimelineChart() { } } - function initializePlotters() { + function initializeCompetitionPlotters() { + + /* At this current version of the platform, we will support only one competition with only one plotter. */ + + const COMPETITION_HOST = "AAArena"; + const COMPETITION = "First-Closed-Door"; + + let objName = COMPETITION_HOST + "-" + COMPETITION; + let storage = newCompetitionStorage(objName); + + let host = ecosystem.getHost(COMPETITION_HOST); + let competition = ecosystem.getCompetition(host, COMPETITION); + + storage.initialize(host, competition, onStorageInitialized); + + function onStorageInitialized() { + + /* Now we have all the initial data loaded and ready to be delivered to the new instance of the plotter. */ + + let plotter = getNewPlotter(competition.plotter.host, competition.plotter.repo, competition.plotter.moduleName); + + plotter.container.displacement.parentDisplacement = thisObject.container.displacement; + plotter.container.zoom.parentZoom = thisObject.container.zoom; + plotter.container.frame.parentFrame = thisObject.container.frame; + + plotter.container.parentContainer = thisObject.container; + + plotter.container.frame.width = thisObject.container.frame.width * 1; + plotter.container.frame.height = thisObject.container.frame.height * 1; + + plotter.container.frame.position.x = thisObject.container.frame.width / 2 - plotter.container.frame.width / 2; + plotter.container.frame.position.y = thisObject.container.frame.height / 2 - plotter.container.frame.height / 2; + + plotter.initialize(storage, datetime, timePeriod, onPlotterInizialized); + + function onPlotterInizialized() { + + if (CONSOLE_LOG === true) { + + console.log(competition.plotter.host, competition.plotter.repo, competition.plotter.moduleName + " Initialized. "); + + } + + let activePlotter = { + productCard: undefined, + plotter: plotter, + storage: storage + }; + + /* Add the new Active Protter to the Array */ + + activePlotters.push(activePlotter); + + } + } + } + + function initializeProductPlotters() { /* Lets get all the cards that needs to be loaded. */ @@ -97,17 +155,12 @@ function newTimelineChart() { /* For each one, we will initialize the associated plotter. */ - initializePlotter(loadingProductCards[i]); + initializeProductPlotter(loadingProductCards[i]); } - - /* Finally we initialize the Competition Plotter. */ - - - } - function initializePlotter(pProductCard) { + function initializeProductPlotter(pProductCard) { /* Before Initializing a Plotter, we need the Storage it will use, loaded with the files it will initially need. */ @@ -223,7 +276,7 @@ function newTimelineChart() { if (found === false) { - initializePlotter(pProductCard); + initializeProductPlotter(pProductCard); } diff --git a/index.html b/index.html index 67f0c3930..b9e5f7b63 100644 --- a/index.html +++ b/index.html @@ -8,6 +8,7 @@ + diff --git a/server.js b/server.js index 32033320a..9c1dcd4e9 100644 --- a/server.js +++ b/server.js @@ -117,9 +117,9 @@ function initialize() { let requestsSent = 0; let responsesReceived = 0; - for (let i = 0; i < ecosystemObject.competitionHosts.length; i++) { + for (let i = 0; i < ecosystemObject.hosts.length; i++) { - let host = ecosystemObject.competitionHosts[i]; + let host = ecosystemObject.hosts[i]; for (let j = 0; j < host.competitions.length; j++) { @@ -375,16 +375,16 @@ function onBrowserRequest(request, response) { ' break;' + '\n' + '\n' let devTeams = ecosystemObject.devTeams; - let competitionHosts = ecosystemObject.competitionHosts; + let hosts = ecosystemObject.hosts; addToFileContent(devTeams); - addToFileContent(competitionHosts); + addToFileContent(hosts); - function addToFileContent(pDevTeamsOrCompetitionHosts) { + function addToFileContent(pDevTeamsOrHosts) { - for (let i = 0; i < pDevTeamsOrCompetitionHosts.length; i++) { + for (let i = 0; i < pDevTeamsOrHosts.length; i++) { - let devTeam = pDevTeamsOrCompetitionHosts[i]; + let devTeam = pDevTeamsOrHosts[i]; for (let j = 0; j < devTeam.plotters.length; j++) { @@ -523,16 +523,16 @@ function onBrowserRequest(request, response) { ' ' let devTeams = ecosystemObject.devTeams; - let competitionHosts = ecosystemObject.competitionHosts; + let hosts = ecosystemObject.hosts; addScript(devTeams); - addScript(competitionHosts); + addScript(hosts); - function addScript(pDevTeamsOrCompetitionHosts) { + function addScript(pDevTeamsOrHosts) { - for (let i = 0; i < pDevTeamsOrCompetitionHosts.length; i++) { + for (let i = 0; i < pDevTeamsOrHosts.length; i++) { - let devTeam = pDevTeamsOrCompetitionHosts[i]; + let devTeam = pDevTeamsOrHosts[i]; for (let j = 0; j < devTeam.plotters.length; j++) {