Improvements needed to deal correctly with Data Ranges
When outside the range, files are not requsted to the server, then there is no async operation as usual, and these modules where not expecting that. Now fixed.
This commit is contained in:
1 parent
cb17dc10dd
commit
2d51354a0c
3 files changed
+165
-29
No files matched your search
+94
-9
@@ -147,15 +147,85 @@ function newDailyFiles() {
|
||||
let periodTime = dailyFilePeriods[i][0];
|
||||
let periodName = dailyFilePeriods[i][1];
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> periodTime = " + periodTime); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> periodName = " + periodName); }
|
||||
|
||||
if (pSet.validPeriods.includes(periodName) === true) {
|
||||
|
||||
let fileCursor = newFileCursor();
|
||||
fileCursor.initialize(fileCloud, pDevTeam, pBot, pSet, exchange, pMarket, periodName, periodTime, pDatetime, pTimePeriod, beginDateRange, endDateRange, onFileReceived);
|
||||
fileCursor.initialize(fileCloud, pDevTeam, pBot, pSet, exchange, pMarket, periodName, periodTime, pDatetime, pTimePeriod, beginDateRange, endDateRange, onInitialized);
|
||||
|
||||
fileCursors.set(periodTime, fileCursor);
|
||||
function onInitialized(err) {
|
||||
|
||||
expectedFiles = expectedFiles + fileCursor.getExpectedFiles();
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> onInitialized -> Entering function."); }
|
||||
|
||||
switch (err.result) {
|
||||
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> onInitialized -> Received OK Response."); }
|
||||
break;
|
||||
}
|
||||
|
||||
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> onInitialized -> Received FAIL Response."); }
|
||||
callBackWhenFileReceived(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
default: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> onInitialized -> Received Unexpected Response."); }
|
||||
callBackWhenFileReceived(err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
fileCursors.set(periodTime, fileCursor);
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> onInitialized -> expectedFiles = " + expectedFiles); }
|
||||
|
||||
expectedFiles = expectedFiles + fileCursor.getExpectedFiles();
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> onInitialized -> expectedFiles = " + expectedFiles); }
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> onFileReceived -> onInitialized -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loadThemAll();
|
||||
|
||||
function loadThemAll() {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> loadThemAll -> Entering function."); }
|
||||
|
||||
for (i = 0; i < dailyFilePeriods.length; i++) {
|
||||
|
||||
let periodTime = dailyFilePeriods[i][0];
|
||||
let periodName = dailyFilePeriods[i][1];
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> loadThemAll -> periodTime = " + periodTime); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> loadThemAll -> periodName = " + periodName); }
|
||||
|
||||
if (pSet.validPeriods.includes(periodName) === true) {
|
||||
|
||||
let fileCursor = fileCursors.get(periodTime);
|
||||
fileCursor.reload(onFileReceived);
|
||||
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> onFileReceived -> loadThemAll -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,6 +281,9 @@ function newDailyFiles() {
|
||||
}
|
||||
|
||||
filesLoaded++;
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] onFileReceived -> filesLoaded = " + filesLoaded); }
|
||||
|
||||
callBackWhenFileReceived(GLOBAL.DEFAULT_OK_RESPONSE, thisObject); // Note that the call back is called for every file loaded at each cursor.
|
||||
|
||||
} catch (err) {
|
||||
@@ -248,12 +321,17 @@ function newDailyFiles() {
|
||||
|
||||
function setDatetimeToEach(fileCursor, key, map) {
|
||||
|
||||
fileCursor.setDatetime(pDatetime, onFileReceived);
|
||||
fileCursor.setDatetime(pDatetime);
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setDatetime -> expectedFiles = " + expectedFiles); }
|
||||
|
||||
expectedFiles = expectedFiles + fileCursor.getExpectedFiles();
|
||||
|
||||
}
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setDatetime -> expectedFiles = " + expectedFiles); }
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setDatetime -> expectedFiles = " + expectedFiles); }
|
||||
fileCursor.reload(onFileReceived);
|
||||
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
@@ -275,12 +353,17 @@ function newDailyFiles() {
|
||||
|
||||
function setTimePeriodToEach(fileCursor, key, map) {
|
||||
|
||||
fileCursor.setTimePeriod(pTimePeriod, pDatetime, onFileReceived);
|
||||
fileCursor.setTimePeriod(pTimePeriod, pDatetime);
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> expectedFiles = " + expectedFiles); }
|
||||
|
||||
expectedFiles = expectedFiles + fileCursor.getExpectedFiles();
|
||||
|
||||
}
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> expectedFiles = " + expectedFiles); }
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> expectedFiles = " + expectedFiles); }
|
||||
fileCursor.reload(onFileReceived);
|
||||
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
@@ -292,6 +375,7 @@ function newDailyFiles() {
|
||||
function getExpectedFiles() {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getExpectedFiles -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getExpectedFiles -> expectedFiles = " + expectedFiles); }
|
||||
|
||||
return expectedFiles;
|
||||
|
||||
@@ -300,6 +384,7 @@ function newDailyFiles() {
|
||||
function getFilesLoaded() {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFilesLoaded -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFilesLoaded -> filesLoaded = " + filesLoaded); }
|
||||
|
||||
return filesLoaded;
|
||||
|
||||
|
||||
+32
-14
@@ -11,6 +11,7 @@ function newFileCursor() {
|
||||
let cursorDate;
|
||||
|
||||
let thisObject = {
|
||||
reload: reload,
|
||||
setDatetime: setDatetime,
|
||||
setTimePeriod: setTimePeriod,
|
||||
files: undefined,
|
||||
@@ -85,10 +86,12 @@ function newFileCursor() {
|
||||
beginDateRange = pBeginDateRange;
|
||||
endDateRange = pEndDateRange;
|
||||
|
||||
setTimePeriod(pCurrentTimePeriod, pCursorDate, callBackFunction);
|
||||
setTimePeriod(pCurrentTimePeriod, pCursorDate);
|
||||
|
||||
intervalHandle = setInterval(updateFiles , timePeriod);
|
||||
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE);
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err); }
|
||||
@@ -197,7 +200,7 @@ function newFileCursor() {
|
||||
}
|
||||
}
|
||||
|
||||
function setTimePeriod(pTimePeriod, pDatetime, callBackFunction) {
|
||||
function setTimePeriod(pTimePeriod, pDatetime) {
|
||||
|
||||
try {
|
||||
|
||||
@@ -237,20 +240,22 @@ function newFileCursor() {
|
||||
|
||||
if (Math.abs(positionB - positionA) <= 1) {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> Will EXIT Saving Mode."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> pTimePeriod = " + convertTimePeriodToName(pTimePeriod)); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> timePeriod = " + convertTimePeriodToName(timePeriod)); }
|
||||
|
||||
exitSavingMode();
|
||||
//console.log("File Cursor with period " + periodName + " EXITED saving mode after being notified the user is at period " + convertTimePeriodToName(pTimePeriod));
|
||||
|
||||
} else {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> Will ENTER Saving Mode."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> pTimePeriod = " + convertTimePeriodToName(pTimePeriod)); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> timePeriod = " + convertTimePeriodToName(timePeriod)); }
|
||||
|
||||
enterSavingMode();
|
||||
//console.log("File Cursor with period " + periodName + " ENTERED saving mode after being notified the user is at period " + convertTimePeriodToName(pTimePeriod));
|
||||
|
||||
}
|
||||
|
||||
getFiles(callBackFunction);
|
||||
|
||||
collectGarbage(callBackFunction);
|
||||
|
||||
function enterSavingMode() {
|
||||
|
||||
try {
|
||||
@@ -331,7 +336,6 @@ function newFileCursor() {
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> enterSavingMode -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,34 +419,48 @@ function newFileCursor() {
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> exitSavingMode -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function setDatetime(pDatetime, callBackFunction) {
|
||||
function setDatetime(pDatetime) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setDatetime -> Entering function."); }
|
||||
|
||||
if (pDatetime === undefined) { return; }
|
||||
if (pDatetime === undefined) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] setDatetime -> Received undefined datetime."); }
|
||||
return;
|
||||
}
|
||||
|
||||
cursorDate = pDatetime;
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] setDatetime -> err = " + err); }
|
||||
}
|
||||
}
|
||||
|
||||
function reload(callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] reload -> Entering function."); }
|
||||
|
||||
getFiles(callBackFunction);
|
||||
|
||||
collectGarbage(callBackFunction);
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] setDatetime -> err = " + err); }
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] reload -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
+39
-6
@@ -94,6 +94,10 @@ function newProductStorage(pName) {
|
||||
let dataSetsToLoad = 0;
|
||||
let dataSetsLoaded = 0;
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> dataSetsToLoad = " + dataSetsToLoad); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> dataSetsLoaded = " + dataSetsLoaded); }
|
||||
|
||||
|
||||
for (let i = 0; i < pProduct.dataSets.length; i++) {
|
||||
|
||||
let thisSet = pProduct.dataSets[i];
|
||||
@@ -103,10 +107,13 @@ function newProductStorage(pName) {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> Market Files -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); }
|
||||
|
||||
dataSetsToLoad++;
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> dataSetsToLoad = " + dataSetsToLoad); }
|
||||
|
||||
let marketFiles = newMarketFiles();
|
||||
marketFiles.initialize(pDevTeam, pBot, pProduct, thisSet, pExchange, pMarket, onMarketFileReady);
|
||||
thisObject.marketFiles.push(marketFiles);
|
||||
dataSetsToLoad++;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -114,10 +121,13 @@ function newProductStorage(pName) {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> Daily Files -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); }
|
||||
|
||||
dataSetsToLoad++;
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> dataSetsToLoad = " + dataSetsToLoad); }
|
||||
|
||||
let dailyFiles = newDailyFiles();
|
||||
dailyFiles.initialize(pDevTeam, pBot, pProduct, thisSet, pExchange, pMarket, pDatetime, pTimePeriod, onDailyFileReady);
|
||||
thisObject.dailyFiles.push(dailyFiles);
|
||||
dataSetsToLoad++;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -125,10 +135,13 @@ function newProductStorage(pName) {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> Single File -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); }
|
||||
|
||||
dataSetsToLoad++;
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> dataSetsToLoad = " + dataSetsToLoad); }
|
||||
|
||||
let singleFile = newSingleFile();
|
||||
singleFile.initialize(pDevTeam, pBot, pProduct, thisSet, pExchange, pMarket, onSingleFileReady);
|
||||
thisObject.singleFile.push(singleFile);
|
||||
dataSetsToLoad++;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -136,10 +149,13 @@ function newProductStorage(pName) {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> File Sequence -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); }
|
||||
|
||||
dataSetsToLoad++;
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> dataSetsToLoad = " + dataSetsToLoad); }
|
||||
|
||||
let fileSequence = newFileSequence();
|
||||
fileSequence.initialize(pDevTeam, pBot, pProduct, thisSet, pExchange, pMarket, onFileSequenceReady);
|
||||
thisObject.fileSequence.push(fileSequence);
|
||||
dataSetsToLoad++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -189,10 +205,15 @@ function newProductStorage(pName) {
|
||||
|
||||
thisObject.eventHandler.raiseEvent('Market File Loaded', event);
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onMarketFileReady -> event.currentValue = " + event.currentValue); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onMarketFileReady -> event.totalValue = " + event.totalValue); }
|
||||
|
||||
if (event.currentValue === event.totalValue) {
|
||||
|
||||
dataSetsLoaded++;
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onMarketFileReady -> dataSetsLoaded = " + dataSetsLoaded); }
|
||||
|
||||
checkInitializeComplete();
|
||||
}
|
||||
|
||||
@@ -248,10 +269,15 @@ function newProductStorage(pName) {
|
||||
|
||||
thisObject.eventHandler.raiseEvent('Daily File Loaded', event);
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onDailyFileReady -> event.currentValue = " + event.currentValue); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onDailyFileReady -> event.totalValue = " + event.totalValue); }
|
||||
|
||||
if (event.currentValue === event.totalValue) {
|
||||
|
||||
dataSetsLoaded++;
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onDailyFileReady -> dataSetsLoaded = " + dataSetsLoaded); }
|
||||
|
||||
checkInitializeComplete();
|
||||
}
|
||||
|
||||
@@ -311,6 +337,8 @@ function newProductStorage(pName) {
|
||||
|
||||
dataSetsLoaded++;
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSingleFileReady -> dataSetsLoaded = " + dataSetsLoaded); }
|
||||
|
||||
checkInitializeComplete();
|
||||
}
|
||||
|
||||
@@ -370,6 +398,8 @@ function newProductStorage(pName) {
|
||||
|
||||
dataSetsLoaded++;
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady = " + dataSetsLoaded); }
|
||||
|
||||
checkInitializeComplete();
|
||||
}
|
||||
|
||||
@@ -384,8 +414,11 @@ function newProductStorage(pName) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] checkInitializeComplete -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] checkInitializeComplete -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> checkInitializeComplete -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> checkInitializeComplete -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); }
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> checkInitializeComplete -> dataSetsToLoad = " + dataSetsToLoad); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> checkInitializeComplete -> dataSetsLoaded = " + dataSetsLoaded); }
|
||||
|
||||
if (dataSetsLoaded === dataSetsToLoad) {
|
||||
|
||||
|
||||
Reference in new issue
Block a user