From e1ebd9d3315a02eb475cf94310113385985dd1b7 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 28 May 2018 08:38:29 +0200 Subject: [PATCH] BUG fixed, duplicated data in Notes fileSequence files. --- Files/FileSequence.js | 4 ++-- FloatingSpace/FloatingLayer.js | 39 +++++++++++++++++++++------------- FloatingSpace/NoteSets.js | 38 ++++++++++++++++++++++++++++++--- server.js | 21 ++++++++++++------ 4 files changed, 75 insertions(+), 27 deletions(-) diff --git a/Files/FileSequence.js b/Files/FileSequence.js index 200385790..497b7775b 100644 --- a/Files/FileSequence.js +++ b/Files/FileSequence.js @@ -19,7 +19,7 @@ function newFileSequence() { let filesLoaded = 0; let fileCloud; let files = new Map; - 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. + 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 so when you add 1 it gives you the amount of files in the sequence, zero. let market; let devTeam; let bot; @@ -70,7 +70,7 @@ function newFileSequence() { } - intervalHandle = setInterval(updateFiles, _1_MINUTE_IN_MILISECONDS); + //intervalHandle = setInterval(updateFiles, _1_MINUTE_IN_MILISECONDS); if (INFO_LOG === true) { logger.write("[INFO] initialize -> intervalHandle = " + intervalHandle); } diff --git a/FloatingSpace/FloatingLayer.js b/FloatingSpace/FloatingLayer.js index 3b47bbdf6..ff2b3b53b 100644 --- a/FloatingSpace/FloatingLayer.js +++ b/FloatingSpace/FloatingLayer.js @@ -62,6 +62,7 @@ function newFloatingLayer() { let dyingFloatingObjects = []; let maxTargetRepulsionForce = 0.0005; + let currentHandle = 0; return thisObject; @@ -98,7 +99,9 @@ function newFloatingLayer() { if (INFO_LOG === true) { logger.write("[INFO] addFloatingObject -> invisibleFloatingObjects.length = " + invisibleFloatingObjects.length); } - pFloatingObject.handle = Math.floor((Math.random() * 10000000) + 1); + currentHandle++; + + pFloatingObject.handle = currentHandle; //Math.floor((Math.random() * 10000000) + 1); if (INFO_LOG === true) { logger.write("[INFO] addFloatingObject -> pFloatingObject.handle = " + pFloatingObject.handle); } if (INFO_LOG === true) { logger.write("[INFO] addFloatingObject -> pFloatingObject.type = " + pFloatingObject.type); } @@ -155,6 +158,12 @@ function newFloatingLayer() { } } + if (ERROR_LOG === true) { logger.write("[ERROR] killFloatingObject -> Floating Object Not Found."); } + if (ERROR_LOG === true) { logger.write("[ERROR] killFloatingObject -> Floating Object cannot be killed."); } + if (ERROR_LOG === true) { logger.write("[ERROR] killFloatingObject -> pFloatingObjectHandle = " + pFloatingObjectHandle); } + + if (callBackFunction !== undefined) { callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE); } + function sendToDie(pFloatingObject) { try { @@ -524,7 +533,7 @@ function newFloatingLayer() { if (payload.visible === true) { - if (INFO_LOG === true) { logger.write("[INFO] physicsLoop -> payload.visible = " + payload.visible); } + if (INTENSIVE_LOG === true) { logger.write("[INFO] physicsLoop -> payload.visible = " + payload.visible); } /* The first time that the floatingObject becomes visible, we need to do this. */ @@ -533,15 +542,15 @@ function newFloatingLayer() { visibleFloatingObjects.push(floatingObject); - if (INFO_LOG === true) { logger.write("[INFO] physicsLoop -> floatingObject.handle = " + floatingObject.handle); } - if (INFO_LOG === true) { logger.write("[INFO] physicsLoop -> floatingObject added to visibleFloatingObjects"); } - if (INFO_LOG === true) { logger.write("[INFO] physicsLoop -> visibleFloatingObjects.length = " + visibleFloatingObjects.length); } + if (INTENSIVE_LOG === true) { logger.write("[INFO] physicsLoop -> floatingObject.handle = " + floatingObject.handle); } + if (INTENSIVE_LOG === true) { logger.write("[INFO] physicsLoop -> floatingObject added to visibleFloatingObjects"); } + if (INTENSIVE_LOG === true) { logger.write("[INFO] physicsLoop -> visibleFloatingObjects.length = " + visibleFloatingObjects.length); } invisibleFloatingObjects.splice(i, 1); // Delete item from array. - if (INFO_LOG === true) { logger.write("[INFO] physicsLoop -> floatingObject.handle = " + floatingObject.handle); } - if (INFO_LOG === true) { logger.write("[INFO] physicsLoop -> floatingObject removed from invisibleFloatingObjects"); } - if (INFO_LOG === true) { logger.write("[INFO] physicsLoop -> invisibleFloatingObjects.length = " + invisibleFloatingObjects.length); } + if (INTENSIVE_LOG === true) { logger.write("[INFO] physicsLoop -> floatingObject.handle = " + floatingObject.handle); } + if (INTENSIVE_LOG === true) { logger.write("[INFO] physicsLoop -> floatingObject removed from invisibleFloatingObjects"); } + if (INTENSIVE_LOG === true) { logger.write("[INFO] physicsLoop -> invisibleFloatingObjects.length = " + invisibleFloatingObjects.length); } return; // Only one at the time. @@ -595,19 +604,19 @@ function newFloatingLayer() { if (payload.visible === false) { - if (INFO_LOG === true) { logger.write("[INFO] physicsLoop -> payload.visible = " + payload.visible); } + if (INTENSIVE_LOG === true) { logger.write("[INFO] physicsLoop -> payload.visible = " + payload.visible); } invisibleFloatingObjects.push(floatingObject); - if (INFO_LOG === true) { logger.write("[INFO] physicsLoop -> floatingObject.handle = " + floatingObject.handle); } - if (INFO_LOG === true) { logger.write("[INFO] physicsLoop -> floatingObject added to invisibleFloatingObjects"); } - if (INFO_LOG === true) { logger.write("[INFO] physicsLoop -> invisibleFloatingObjects.length = " + invisibleFloatingObjects.length); } + if (INTENSIVE_LOG === true) { logger.write("[INFO] physicsLoop -> floatingObject.handle = " + floatingObject.handle); } + if (INTENSIVE_LOG === true) { logger.write("[INFO] physicsLoop -> floatingObject added to invisibleFloatingObjects"); } + if (INTENSIVE_LOG === true) { logger.write("[INFO] physicsLoop -> invisibleFloatingObjects.length = " + invisibleFloatingObjects.length); } visibleFloatingObjects.splice(i, 1); // Delete item from array. - if (INFO_LOG === true) { logger.write("[INFO] physicsLoop -> floatingObject.handle = " + floatingObject.handle); } - if (INFO_LOG === true) { logger.write("[INFO] physicsLoop -> floatingObject removed from visibleFloatingObjects"); } - if (INFO_LOG === true) { logger.write("[INFO] physicsLoop -> visibleFloatingObjects.length = " + visibleFloatingObjects.length); } + if (INTENSIVE_LOG === true) { logger.write("[INFO] physicsLoop -> floatingObject.handle = " + floatingObject.handle); } + if (INTENSIVE_LOG === true) { logger.write("[INFO] physicsLoop -> floatingObject removed from visibleFloatingObjects"); } + if (INTENSIVE_LOG === true) { logger.write("[INFO] physicsLoop -> visibleFloatingObjects.length = " + visibleFloatingObjects.length); } return; // Only one at the time. diff --git a/FloatingSpace/NoteSets.js b/FloatingSpace/NoteSets.js index 512c297fb..c75aaa118 100644 --- a/FloatingSpace/NoteSets.js +++ b/FloatingSpace/NoteSets.js @@ -16,6 +16,7 @@ function newNoteSets() { const MODULE_NAME = "Note Sets"; const INFO_LOG = false; + const INFO_WARN = true; const ERROR_LOG = true; const logger = newWebDebugLog(); logger.fileName = MODULE_NAME; @@ -142,10 +143,21 @@ function newNoteSets() { Each time we identify a floatingObject that is not at the raw data anymore, we request the floatinglayer to kill it. */ - floatingLayer.killFloatingObject(floatingNote.floatingHandle); + floatingLayer.killFloatingObject(floatingNote.floatingHandle, onObjectKilled); - if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> floatingNote.floatingHandle = " + floatingNote.floatingHandle); } - if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> Removed from Layer."); } + function onObjectKilled(err) { + + if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { + + if (ERROR_LOG === true) { logger.write("[ERROR] createNoteSet -> onNotesChanged -> Remove old Notes -> Floating Object Not Found."); } + if (ERROR_LOG === true) { logger.write("[ERROR] createNoteSet -> onNotesChanged -> Remove old Notes -> Floating Object cannot be killed."); } + if (ERROR_LOG === true) { logger.write("[ERROR] createNoteSet -> onNotesChanged -> Remove old Notes -> floatingNote.floatingHandle = " + floatingNote.floatingHandle); } + return; + } + + if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> floatingNote.floatingHandle = " + floatingNote.floatingHandle); } + if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> Removed from Layer."); } + } } else { @@ -155,6 +167,10 @@ function newNoteSets() { if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> Added to newFloatingNotes."); } if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> newFloatingNotes.length = " + newFloatingNotes.length); } + /* + We set a property at each floatingObject of which is the index of the note at the raw data array, so that it can later evaluate its position or its visibility. + */ + let floatingObject = floatingLayer.getFloatingObject(floatingNote.floatingHandle); floatingObject.payloadNoteIndex = i; @@ -182,6 +198,13 @@ function newNoteSets() { newFloatingNotes = []; // We will create a new array of Floating Notes as a result of this operation. + /* + We are using the date and rate as a unique key to identify each note. To prevent the cases of duplicate keys, we will check that at + least to consecutive records dont have the same key, and if they do, will ignore the second one. + */ + + let lastPlotterKey = ""; + for (let i = 0; i < pNewNotes.length; i++) { found = false; @@ -191,6 +214,15 @@ function newNoteSets() { let floatingNote; let floatingNoteKey; + if (lastPlotterKey === plotterNoteKey) { + + if (INFO_WARN=== true) { logger.write("[WARN] createNoteSet -> onNotesChanged -> Add new Notes -> Duplicate record detected. Discarding it."); } + if (INFO_WARN === true) { logger.write("[WARN] createNoteSet -> onNotesChanged -> Add new Notes -> i = " + i); } + continue; + } + + lastPlotterKey = plotterNoteKey; + if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> i = " + i); } for (let j = 0; j < noteSet.floatingNotes.length; j++) { diff --git a/server.js b/server.js index ffeee582a..3553404dd 100644 --- a/server.js +++ b/server.js @@ -948,15 +948,22 @@ function respondWithFile(fileName, response) { function returnEmptyArray() { - if (CONSOLE_LOG === true) { console.log("[INFO] server -> respondWithFile -> returnEmptyArray -> Entering function."); } + try { - response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1. - response.setHeader("Pragma", "no-cache"); // HTTP 1.0. - response.setHeader("Expires", "0"); // Proxies. + if (CONSOLE_LOG === true) { console.log("[INFO] server -> respondWithFile -> returnEmptyArray -> Entering function."); } - response.writeHead(200, { 'Content-Type': 'text/html' }); - response.write("[]"); - response.end("\n"); + response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1. + response.setHeader("Pragma", "no-cache"); // HTTP 1.0. + response.setHeader("Expires", "0"); // Proxies. + response.writeHead(200, { 'Content-Type': 'text/html' }); + response.write("[]"); + response.end("\n"); + + } catch (err) { + + console.log("[ERROR] server -> returnEmptyArray -> err.message " + err.message); + + } }