Optimization
This commit is contained in:
1 parent
01369dd7c5
commit
89f8e0574f
5 files changed
+175
-11
No files matched your search
@@ -42,6 +42,9 @@
|
||||
<Compile Include="FileCloud.js">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="FileCursor.js">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Panels\BotsLayersPanel.js">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
function getSideDays(timePeriod) {
|
||||
|
||||
let daysOnSides;
|
||||
|
||||
if (timePeriod < _1_HOUR_IN_MILISECONDS) {
|
||||
daysOnSides = 1;
|
||||
}
|
||||
|
||||
+14
-11
@@ -33,12 +33,16 @@ function newFileCache() {
|
||||
let fileCache = {
|
||||
getMarketFile: getMarketFile,
|
||||
getFileCursor: getFileCursor,
|
||||
setDatetime: setDatetime,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
let fileCloud;
|
||||
|
||||
let marketFiles = new Map;
|
||||
let fileCursors = new Map;
|
||||
|
||||
let datetime;
|
||||
|
||||
return fileCache;
|
||||
|
||||
@@ -71,8 +75,6 @@ function newFileCache() {
|
||||
fileCloud = newFileCloud();
|
||||
fileCloud.initialize(pTeamCodeName, pBotCodeName);
|
||||
|
||||
let filesReceived = 0;
|
||||
|
||||
for (i = 0; i < marketFilesPeriods.length; i++) {
|
||||
|
||||
let periodTime = marketFilesPeriods[i][0];
|
||||
@@ -86,13 +88,8 @@ function newFileCache() {
|
||||
|
||||
marketFiles.set(periodTime, file);
|
||||
|
||||
filesReceived++;
|
||||
callBackFunction(); // Note that the call back is called for every file loaded.
|
||||
|
||||
if (filesReceived === layer.validPeriods.length) {
|
||||
|
||||
callBackFunction();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,10 +103,16 @@ function newFileCache() {
|
||||
}
|
||||
|
||||
|
||||
function getFileCursor(pPeriod, pDatetime) {
|
||||
|
||||
|
||||
function getFileCursor(pPeriod) {
|
||||
|
||||
return fileCursors.get(pPeriod);
|
||||
|
||||
}
|
||||
|
||||
function setDatetime(newDatetime) {
|
||||
|
||||
datetime = newDatetime;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+155
@@ -0,0 +1,155 @@
|
||||
|
||||
function newFileCursor() {
|
||||
|
||||
|
||||
|
||||
let dailyFiles = new Map;
|
||||
let cursorDate = new Date(INITIAL_DATE);
|
||||
|
||||
let fileCursor = {
|
||||
setDatetime: setDatetime,
|
||||
dailyFiles: undefined,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
fileCursor.dailyFiles = dailyFiles;
|
||||
|
||||
let market;
|
||||
let exchange;
|
||||
let cursorSize = 3;
|
||||
|
||||
let server = newFileServer();
|
||||
|
||||
return fileCursor;
|
||||
|
||||
function initialize(pExchange, pMarket, callBackFunction) {
|
||||
|
||||
market = pMarket;
|
||||
exchange = pExchange;
|
||||
|
||||
server.initialize();
|
||||
|
||||
getFiles(callBackFunction);
|
||||
|
||||
}
|
||||
|
||||
function setDatetime(datetime) {
|
||||
|
||||
if (datetime === undefined) { return; }
|
||||
|
||||
cursorDate = datetime;
|
||||
|
||||
getFiles();
|
||||
|
||||
collectGarbage();
|
||||
}
|
||||
|
||||
function getFiles(callBackFunction) {
|
||||
|
||||
let i = 0;
|
||||
let j = 0;
|
||||
|
||||
let dateString;
|
||||
|
||||
getNextFile();
|
||||
|
||||
function getNextFile() {
|
||||
|
||||
let targetDate = new Date(cursorDate);
|
||||
targetDate.setDate(targetDate.getDate() + j);
|
||||
|
||||
if (j === 0) { j++; }
|
||||
else {
|
||||
if (j < 0) {
|
||||
j = -j;
|
||||
j++;
|
||||
}
|
||||
else {
|
||||
j = -j;
|
||||
}
|
||||
}
|
||||
|
||||
dateString = targetDate.getUTCFullYear() + '-' + pad(targetDate.getUTCMonth() + 1, 2) + '-' + pad(targetDate.getUTCDate(), 2);
|
||||
|
||||
let currentDay = Math.trunc((new Date()).valueOf() / (24 * 60 * 60 * 1000));
|
||||
let targetDay = Math.trunc(targetDate.valueOf() / (24 * 60 * 60 * 1000));
|
||||
|
||||
if (targetDay > currentDay) {
|
||||
|
||||
controlLoop();
|
||||
|
||||
} else {
|
||||
|
||||
if (fileCursor.dailyFiles.get(dateString) === undefined) {
|
||||
|
||||
server.getDailyFile(exchange, market, targetDate, newDailyFilesReady)
|
||||
|
||||
} else {
|
||||
|
||||
controlLoop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function newDailyFilesReady(dailyFileReceived) {
|
||||
|
||||
fileCursor.dailyFiles.set(dateString, dailyFileReceived);
|
||||
|
||||
controlLoop();
|
||||
|
||||
}
|
||||
|
||||
|
||||
function controlLoop() {
|
||||
|
||||
if (j === 3) { // We call the callBack after we have the first few files.
|
||||
|
||||
if (callBackFunction !== undefined) {
|
||||
|
||||
callBackFunction();
|
||||
|
||||
if (market === INITIAL_DEFAULT_MARKET) { // This is when we dont need a splash screen anymore!
|
||||
|
||||
splashScreenNeeded = false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
i++;
|
||||
|
||||
if (i < cursorSize) {
|
||||
|
||||
getNextFile();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function collectGarbage() {
|
||||
|
||||
date = removeTime(cursorDate);
|
||||
|
||||
let minDate = date.valueOf() - cursorSize / 2 * 24 * 60 * 60 * 1000;
|
||||
let maxDate = date.valueOf() + cursorSize / 2 * 24 * 60 * 60 * 1000;
|
||||
|
||||
for (let key of fileCursor.dailyFiles.keys()) {
|
||||
|
||||
let keyDate = new Date(key);
|
||||
|
||||
if (keyDate.valueOf() < minDate || keyDate.valueOf() > maxDate) {
|
||||
|
||||
fileCursor.dailyFiles.delete(key);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
<script type="text/javascript" src="FileServer.js"></script>
|
||||
<script type="text/javascript" src="FileCloud.js"></script>
|
||||
<script type="text/javascript" src="FileCache.js"></script>
|
||||
<script type="text/javascript" src="FileCursor.js"></script>
|
||||
<script type="text/javascript" src="SplashScreen.js"></script>
|
||||
<script type="text/javascript" src="Canvas.js"></script>
|
||||
<script type="text/javascript" src="Button.js"></script>
|
||||
|
||||
Reference in new issue
Block a user