Delete Exec History code implemented

This commit is contained in:
Luis Fernando Molina committed 2018-06-25 20:14:24 +02:00
1 parent 8888d47394
commit 239ae5191a
7 files changed
+271 -15

No files matched your search

+1 -1
View File
@@ -89,7 +89,7 @@
let container = "aaplatform";
let readPermission = storageAccessManager.getPermission(container, "READ", MAX_STORAGE_PERMISSION_DAYS);
userProfile.storagePermissions.push(["AAPlatform" + "." + "READ", readPermission]);
callBackFunction(global.DEFAULT_OK_RESPONSE, userProfile);
}
+241
View File
@@ -0,0 +1,241 @@
function newDeleteTradingHistory() {
var thisObject = {
container: undefined,
draw: draw,
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
initialize: initialize
};
var container = newContainer();
container.initialize();
thisObject.container = container;
thisObject.container.frame.width = 150;
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT;
container.frame.position.x = 0;
container.frame.position.y = 0;
container.isDraggeable = false;
container.isClickeable = true;
let icon;
let canDrawIcon = false;
return thisObject;
function initialize() {
icon = new Image();
icon.onload = onImageLoad;
function onImageLoad() {
canDrawIcon = true;
}
icon.src = "Images/trash.png";
thisObject.container.eventHandler.listenToEvent("onMouseClick", onClick);
}
function onClick() {
/*
To delete the trading history we will follow these steps:
1. Get the status report of that bot.
2. Iterate through all the entries for the startMode received by parameters.
3. For each entry, get the execution history file belonging to that entry.
4. Iterate on each entry of each execution history file to get the date of each execution that we will use to locate the
execution context file.
6. Delete every execution context file found.
7. Delete the execution history file after finishing the interation.
8. Delete the Sequence file belonging to the received Start Mode.
9. Save the Status Report without the records of this Start Mode.
*/
let storage = AzureStorage.Blob;
let readOnlyBlobService;
let writeOnlyBlobService;
let readConnectionString = window.USER_PROFILE.storagePermissions.get(window.DEV_TEAM + "." + "READ");
if (readConnectionString !== undefined) {
readOnlyBlobService = storage.createBlobService(readConnectionString);
}
let writeConnectionString = window.USER_PROFILE.storagePermissions.get(window.DEV_TEAM + "." + "WRITE");
if (writeConnectionString !== undefined) {
writeOnlyBlobService = storage.createBlobService(writeConnectionString);
}
let containerName = window.DEV_TEAM.toLowerCase();
let filePath = window.DEV_TEAM + "/" + window.CURRENT_BOT_CODE_NAME + "/" + "AACloud.1.1" + "/" + "Ploniex" + "/" + "dataSet.V1" + "/" + "Reports" + "/" + "Trading-Process";
let fileName = "Status.Report.USDT_BTC.json";
readOnlyBlobService.getBlobToText(containerName, filePath + "/" + fileName, onStatusReport);
function onStatusReport(err, text, response) {
let statusReport = JSON.parse(text);
let runs;
switch (window.CURRENT_START_MODE) {
case "Live": {
runs = statusReport.liveRuns;
break;
}
case "Backtest": {
runs = statusReport.backtestRuns;
break;
}
case "Competition": {
runs = statusReport.competitionRuns;
break;
}
}
for (let i = 0; i < runs.lenght; i++) {
/* For each record, we will get the execution history file. */
let filePath = window.DEV_TEAM + "/" + window.CURRENT_BOT_CODE_NAME + "/" + "AACloud.1.1" + "/" + "Ploniex" + "/" + "dataSet.V1" + "/" + "Output" + "/" + "Trading-Process";
let fileName = "Execution.History." + window.CURRENT_START_MODE + "." + i + ".json";
readOnlyBlobService.getBlobToText(containerName, filePath + "/" + fileName, onExecutionHistory);
function onExecutionHistory(err, text, response) {
let executionHistory = JSON.parse(text);
for (let i = 0; i < executionHistory.lenght; i++) {
let executionDate = new Date(executionHistory[i]);
let datePath = dateTime.getUTCFullYear() + "/" + pad(dateTime.getUTCMonth() + 1, 2) + "/" + pad(dateTime.getUTCDate(), 2) + "/" + pad(dateTime.getUTCHours(), 2) + "/" + pad(dateTime.getUTCMinutes(), 2);
let filePath = window.DEV_TEAM + "/" + window.CURRENT_BOT_CODE_NAME + "/" + "AACloud.1.1" + "/" + "Ploniex" + "/" + "dataSet.V1" + "/" + "Output" + "/" + "Trading-Process" + "/" + datePath;
let fileName = "Execution.Context." + window.CURRENT_START_MODE + "." + i + ".json";
readOnlyBlobService.deleteBlob(containerName, filePath + "/" + fileName, onDeleted);
function onDeleted(err, text, response) {
console.log(filePath + "/" + fileName + " deleted.");
}
}
/* Now we delete the execution history file. */
readOnlyBlobService.deleteBlob(containerName, filePath + "/" + fileName, onDeleted);
function onDeleted(err, text, response) {
console.log(filePath + "/" + fileName + " deleted.");
}
}
}
switch (window.CURRENT_START_MODE) {
case "Live": {
statusReport.liveRuns = [];
break;
}
case "Backtest": {
statusReport.backtestRuns= [];
break;
}
case "Competition": {
statusReport.competitionRuns = [];
break;
}
}
/* Here is where we update the current Status Report file with the new version without records for the current Start Mode. */
let fileContent = JSON.stringify(statusReport);
writeOnlyBlobService.createBlockBlobFromText(containerName, filePath + "/" + fileName, fileContent, onStatusReportUpdated);
function onStatusReportUpdated() (err, text, response) {
console.log(filePath + "/" + fileName + " updated.");
}
/* Finally we delete the sequence file. */
let filePath = window.DEV_TEAM + "/" + window.CURRENT_BOT_CODE_NAME + "/" + "AACloud.1.1" + "/" + "Ploniex" + "/" + "dataSet.V1" + "/" + "Output" + "/" + "Trading-Process";
let fileName = "Execution.History." + window.CURRENT_START_MODE + "." + "Sequence" + ".json";
readOnlyBlobService.deleteBlob(containerName, filePath + "/" + fileName, onDeleted);
function onDeleted(err, text, response) {
console.log(filePath + "/" + fileName + " deleted.");
}
}
function pad(str, max) {
str = str.toString();
return str.length < max ? pad("0" + str, max) : str;
}
}
function getContainer(point) {
let container;
/* First we check if this point is inside this object UI. */
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
return this.container;
} else {
/* This point does not belong to this space. */
return undefined;
}
}
function draw() {
thisObject.container.frame.draw(false, false);
if (canDrawIcon === false) { return; }
let imageHeight = 45;
let imageWidth = 45;
let imagePoint = {
x: 10,
y: thisObject.container.frame.height / 2 - imageHeight / 2
};
imagePoint = thisObject.container.frame.frameThisPoint(imagePoint);
browserCanvasContext.drawImage(icon, imagePoint.x, imagePoint.y, imageWidth, imageHeight);
}
}
+3
View File
@@ -37,6 +37,9 @@
</Compile>
<Compile Include="Animation.js" />
<Compile Include="Azure\azure-storage.blob.js" />
<Compile Include="BottomSpace\DeleteTradingHistory.js">
<SubType>Code</SubType>
</Compile>
<Compile Include="BreakpointsBar.js">
<SubType>Code</SubType>
</Compile>
+6 -2
View File
@@ -2,6 +2,7 @@
function newBottomSpace() {
var thisObject = {
deleteTradingHistory: undefined,
container: undefined,
draw: draw,
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
@@ -24,7 +25,8 @@ function newBottomSpace() {
function initialize() {
thisObject.deleteTradingHistory = newDeleteTradingHistory();
thisObject.deleteTradingHistory.initialize();
}
@@ -32,7 +34,8 @@ function newBottomSpace() {
let container;
container = thisObject.deleteTradingHistory.getContainer(point);
if (container !== undefined) { return container; }
/* The point does not belong to any inner container, so we return the current container. */
@@ -45,6 +48,7 @@ function newBottomSpace() {
thisObject.container.frame.draw(false, false);
drawBackground();
thisObject.deleteTradingHistory.draw();
}
+16 -8
View File
@@ -32,15 +32,17 @@ function newCurrentBot() {
sharedStatus = pSharedStatus;
if (window.USER_PROFILE.devTeams.length === 0) {
window.CURRENT_BOT = NOT_FOUND;
window.CURRENT_BOT_DISPLAY_NAME = NOT_FOUND;
} else {
if (window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots.length === 0) {
window.CURRENT_BOT = NOT_FOUND;
window.CURRENT_BOT_DISPLAY_NAME = NOT_FOUND;
window.CURRENT_BOT_REPO = "NO REPO";
window.CURRENT_BOT_CODE_NAME = "";
} else {
window.CURRENT_BOT = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].displayName;
window.CURRENT_BOT_DISPLAY_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].displayName;
window.CURRENT_BOT_REPO = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].repo;
window.CURRENT_BOT_CODE_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].codeName;
}
}
@@ -53,13 +55,15 @@ function newCurrentBot() {
if (window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots.length > 0) {
sharedStatus.currentUserBotIndex = 0;
window.CURRENT_BOT = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].displayName;
window.CURRENT_BOT_DISPLAY_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].displayName;
window.CURRENT_BOT_REPO = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].repo;
window.CURRENT_BOT_CODE_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].codeName;
sharedStatus.eventHandler.raiseEvent("userBot Changed");
} else {
window.CURRENT_BOT = NOT_FOUND;
window.CURRENT_BOT_DISPLAY_NAME = NOT_FOUND;
}
}
@@ -69,8 +73,10 @@ function newCurrentBot() {
if (sharedStatus.currentUserBotIndex + 1 === window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots.length) {
sharedStatus.currentUserBotIndex = 0;
window.CURRENT_BOT = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].displayName;
window.CURRENT_BOT_DISPLAY_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].displayName;
window.CURRENT_BOT_REPO = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].repo;
window.CURRENT_BOT_CODE_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].codeName;
sharedStatus.eventHandler.raiseEvent("userBot Changed");
return;
}
@@ -78,8 +84,10 @@ function newCurrentBot() {
if (sharedStatus.currentUserBotIndex + 1 < window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots.length) {
sharedStatus.currentUserBotIndex++;
window.CURRENT_BOT = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].displayName;
window.CURRENT_BOT_DISPLAY_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].displayName;
window.CURRENT_BOT_REPO = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].repo;
window.CURRENT_BOT_CODE_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].codeName;
sharedStatus.eventHandler.raiseEvent("userBot Changed");
return;
}
@@ -109,7 +117,7 @@ function newCurrentBot() {
thisObject.container.frame.draw(false, false);
let fontSize = 12;
let label = window.CURRENT_BOT;
let label = window.CURRENT_BOT_DISPLAY_NAME;
let point = {
x: thisObject.container.frame.width * 1 / 3,
+2 -2
View File
@@ -36,7 +36,7 @@ function newCurrentStartMode() {
function onClick() {
if (window.CURRENT_BOT === "") { return; }
if (window.CURRENT_BOT_DISPLAY_NAME === "") { return; }
switch (window.CURRENT_START_MODE) {
@@ -76,7 +76,7 @@ function newCurrentStartMode() {
function draw() {
if (window.CURRENT_BOT === "") { return;}
if (window.CURRENT_BOT_DISPLAY_NAME === "") { return;}
thisObject.container.frame.draw(false, false);
+2 -2
View File
@@ -59,7 +59,7 @@ function newPlayStopButton() {
function onClick() {
if (window.CURRENT_BOT === "") { return; }
if (window.CURRENT_BOT_DISPLAY_NAME === "") { return; }
switch (showing) {
@@ -122,7 +122,7 @@ function newPlayStopButton() {
function draw() {
if (window.CURRENT_BOT === "") { return; }
if (window.CURRENT_BOT_DISPLAY_NAME === "") { return; }
thisObject.container.frame.draw(false, false);