Competition Plotter Upgraded to use Sequence Files
This commit is contained in:
1 parent
f15722d166
commit
998a84478d
6 files changed
+128
-99
No files matched your search
Binary file not shown.
@@ -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) {
|
||||
|
||||
+106
-59
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+19
-22
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
|
||||
Reference in new issue
Block a user