Merge pull request #55 from AAMasters/develop

Bug Fixes when daily or market are not calculated
This commit is contained in:
benme authored and GitHub committed 2019-05-19 09:37:37 -03:00
commit fd8ea67160
11 files changed
+160 -457

No files matched your search

+6
View File
@@ -229,6 +229,11 @@ function newCanvas () {
return
}
if (container !== undefined && container.isClickeable === true) {
/* We dont want to mess up with the click */
return
}
/* We check if the mouse is over a panel/ */
container = thisObject.panelsSpace.getContainer(point)
@@ -641,3 +646,4 @@ function newCanvas () {
}
}
}
+7 -198
View File
@@ -1,7 +1,5 @@
function newPlottersManager () {
const MODULE_NAME = 'Plotters Manager'
const INFO_LOG = false
const INTENSIVE_LOG = false
const ERROR_LOG = true
const logger = newWebDebugLog()
logger.fileName = MODULE_NAME
@@ -36,57 +34,40 @@ function newPlottersManager () {
function finalize (callBackFunction) {
try {
if (INFO_LOG === true) { logger.write('[INFO] finalize -> Entering function.') }
for (let i = 0; i < productPlotters.length; i++) {
if (productPlotters[i].profile !== undefined) {
canvas.floatingSpace.profileBalls.destroyProfileBall(productPlotters[i].profile)
}
/* Destroyd the Note Set */
canvas.floatingSpace.noteSets.destroyNoteSet(productPlotters[i].noteSet)
/* Then the panels. */
for (let j = 0; j < productPlotters[i].panels.length; j++) {
canvas.panelsSpace.destroyPanel(productPlotters[i].panels[j])
}
/* Finally the Storage Objects */
productPlotters[i].storage.finalize()
if (productPlotters[i].plotter.finalize !== undefined) {
productPlotters[i].plotter.finalize()
}
productPlotters.splice(i, 1) // Delete item from array.
}
for (let i = 0; i < competitionPlotters.length; i++) {
if (competitionPlotters[i].profile !== undefined) {
canvas.floatingSpace.profileBalls.destroyProfileBall(competitionPlotters[i].profile)
}
/* Destroyd the Note Set */
canvas.floatingSpace.noteSets.destroyNoteSet(competitionPlotters[i].noteSet)
/* Then the panels. */
if (competitionPlotters[i].panels !== undefined) {
for (let j = 0; j < competitionPlotters[i].panels.length; j++) {
canvas.panelsSpace.destroyPanel(competitionPlotters[i].panels[j])
}
}
/* Finally the Storage Objects */
competitionPlotters[i].storage.finalize()
if (competitionPlotters[i].plotter.finalize !== undefined) {
competitionPlotters[i].plotter.finalize()
}
competitionPlotters.splice(i, 1) // Delete item from array.
}
} catch (err) {
@@ -97,38 +78,25 @@ function newPlottersManager () {
function initialize (pProductsPanel, pExchange, pMarket, callBackFunction) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
/* Remember the Products Panel */
productsPanel = pProductsPanel
exchange = pExchange
market = pMarket
/* Listen to the event of change of status */
productsPanel.container.eventHandler.listenToEvent('Product Card Status Changed', onProductCardStatusChanged)
initializeCompetitionPlotters(onCompetitionPlottersInitialized)
function onCompetitionPlottersInitialized (err) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onCompetitionPlottersInitialized -> Entering function.') }
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onCompetitionPlottersInitialized -> Received OK Response.') }
break
}
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onCompetitionPlottersInitialized -> Received FAIL Response.') }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
return
}
default: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileCursorReady -> Received Unexpected Response.') }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
return
}
@@ -138,25 +106,19 @@ function newPlottersManager () {
function onProductPlottersInitialized (err) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onCompetitionPlottersInitialized -> onProductPlottersInitialized -> Entering function.') }
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onCompetitionPlottersInitialized -> onProductPlottersInitialized -> Received OK Response.') }
initializationReady = true
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE)
break
}
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onCompetitionPlottersInitialized -> onProductPlottersInitialized -> Received FAIL Response.') }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
return
}
default: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onCompetitionPlottersInitialized -> onProductPlottersInitialized -> Received Unexpected Response.') }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
return
}
@@ -179,8 +141,6 @@ function newPlottersManager () {
function initializeCompetitionPlotters (callBack) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initializeCompetitionPlotters -> Entering function.') }
/* At this current version of the platform, we will support only one competition with only one plotter. */
const COMPETITION_HOST = 'AAArena'
@@ -188,7 +148,6 @@ function newPlottersManager () {
let objName = COMPETITION_HOST + '-' + COMPETITION
let storage = newCompetitionStorage(objName)
let host = ecosystem.getHost(COMPETITION_HOST)
let competition = ecosystem.getCompetition(host, COMPETITION)
@@ -196,99 +155,69 @@ function newPlottersManager () {
function onCompetitionStorageInitialized (err) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initializeCompetitionPlotters -> onCompetitionStorageInitialized -> Entering function.') }
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initializeCompetitionPlotters -> onCompetitionStorageInitialized -> Received OK Response.') }
break
}
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initializeCompetitionPlotters -> onCompetitionStorageInitialized -> Received FAIL Response.') }
callBack(GLOBAL.DEFAULT_FAIL_RESPONSE)
return
}
default: {
if (INFO_LOG === true) { logger.write('[INFO] initializeCompetitionPlotters -> onCompetitionStorageInitialized -> Received Unexpected Response.') }
callBack(GLOBAL.DEFAULT_FAIL_RESPONSE)
return
}
}
/* Now we have all the initial data loaded and ready to be delivered to the new instance of the plotter. */
let plotter = getNewPlotter(competition.plotter.host, competition.plotter.codeName, competition.plotter.moduleName)
plotter.container.connectToParent(thisObject.container, true, true, false, true, true, true)
plotter.container.frame.position.x = thisObject.container.frame.width / 2 - plotter.container.frame.width / 2
plotter.container.frame.position.y = thisObject.container.frame.height / 2 - plotter.container.frame.height / 2
/* We add the profile picture of each participant, because the plotter will need it. */
for (let k = 0; k < competition.participants.length; k++) {
let participant = competition.participants[k]
let devTeam = ecosystem.getTeam(participant.devTeam)
let bot = ecosystem.getBot(devTeam, participant.bot)
participant.profilePicture = bot.profilePicture
}
plotter.initialize(competition, storage, datetime, timePeriod, onPlotterInizialized)
function onPlotterInizialized (err) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initializeCompetitionPlotters -> onCompetitionStorageInitialized -> onPlotterInizialized -> Entering function.') }
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initializeCompetitionPlotters -> onCompetitionStorageInitialized -> onPlotterInizialized -> Received OK Response.') }
break
}
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initializeCompetitionPlotters -> onCompetitionStorageInitialized -> onPlotterInizialized -> Received FAIL Response.') }
callBack(GLOBAL.DEFAULT_FAIL_RESPONSE)
return
}
default: {
if (INFO_LOG === true) { logger.write('[INFO] initializeCompetitionPlotters -> onCompetitionStorageInitialized -> onPlotterInizialized -> Received Unexpected Response.') }
callBack(GLOBAL.DEFAULT_FAIL_RESPONSE)
return
}
}
let competitionPlotter = {
plotter: plotter,
storage: storage
}
/* Add the new Active Protter to the Array */
competitionPlotters.push(competitionPlotter)
/* Create The Profie Picture FloatingObject */
if (competitionPlotter.plotter.payload !== undefined) {
for (let k = 0; k < competition.participants.length; k++) {
let participant = competition.participants[k]
let devTeam = ecosystem.getTeam(participant.devTeam)
let bot = ecosystem.getBot(devTeam, participant.bot)
let imageId = participant.devTeam + '.' + participant.profilePicture
const TEAM = devTeam.codeName.toLowerCase()
const BOT = bot.codeName.toLowerCase()
let botAvatar = new Image()
botAvatar.src = window.canvasApp.context.fbProfileImages.get(TEAM + '-' + BOT)
competitionPlotter.plotter.payload[k].profile.title = bot.displayName
competitionPlotter.plotter.payload[k].profile.imageId = imageId
competitionPlotter.plotter.payload[k].profile.botAvatar = botAvatar
canvas.floatingSpace.profileBalls.createNewProfileBall(competitionPlotter.plotter.payload[k], onProfileBallCreated)
function onProfileBallCreated (err, pProfileHandle) {
@@ -296,7 +225,6 @@ function newPlottersManager () {
}
}
}
callBack(GLOBAL.DEFAULT_OK_RESPONSE)
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] initializeCompetitionPlotters -> onCompetitionStorageInitialized -> onPlotterInizialized -> err = ' + err.stack) }
@@ -316,8 +244,6 @@ function newPlottersManager () {
function initializeProductPlotters (callBack) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initializeProductPlotters -> Entering function.') }
/* Lets get all the cards that needs to be loaded. */
let initializationCounter = 0
@@ -329,49 +255,30 @@ function newPlottersManager () {
callBack(GLOBAL.DEFAULT_OK_RESPONSE)
return
}
for (let i = 0; i < loadingProductCards.length; i++) {
/* For each one, we will initialize the associated plotter. */
initializeProductPlotter(loadingProductCards[i], onProductPlotterInitialized)
function onProductPlotterInitialized (err) {
if (INFO_LOG === true) { logger.write('[INFO] initializeProductPlotters -> onProductPlotterInitialized -> Entering function.') }
initializationCounter++
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initializeProductPlotters -> onProductPlotterInitialized -> onProductPlotterInitialized -> Received OK Response.') }
okCounter++
break
}
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initializeProductPlotters -> onProductPlotterInitialized -> onProductPlotterInitialized -> Received FAIL Response.') }
failCounter++
break
}
default: {
if (INFO_LOG === true) { logger.write('[INFO] initializeProductPlotters -> onProductPlotterInitialized -> onProductPlotterInitialized -> Received Unexpected Response.') }
failCounter++
break
}
}
if (INFO_LOG === true) { logger.write('[INFO] initializeProductPlotters -> onProductPlotterInitialized -> onProductPlotterInitialized -> initializationCounter = ' + initializationCounter) }
if (INFO_LOG === true) { logger.write('[INFO] initializeProductPlotters -> onProductPlotterInitialized -> onProductPlotterInitialized -> okCounter = ' + okCounter) }
if (INFO_LOG === true) { logger.write('[INFO] initializeProductPlotters -> onProductPlotterInitialized -> onProductPlotterInitialized -> failCounter = ' + failCounter) }
if (INFO_LOG === true) { logger.write('[INFO] initializeProductPlotters -> onProductPlotterInitialized -> onProductPlotterInitialized -> loadingProductCards.length = ' + loadingProductCards.length) }
if (initializationCounter === loadingProductCards.length) {
// This was the last one.
if (INFO_LOG === true) { logger.write('[INFO] initializeProductPlotters -> onProductPlotterInitialized -> onProductPlotterInitialized -> Last Product Loaded.') }
/* If less than 50% of plotters are initialized then we return FAIL. */
// This was the last one.
/* If less than 50% of plotters are initialized then we return FAIL. */
if (okCounter >= 1) {
callBack(GLOBAL.DEFAULT_OK_RESPONSE)
} else {
@@ -388,22 +295,15 @@ function newPlottersManager () {
function initializeProductPlotter (pProductCard, callBack) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initializeProductPlotter -> Entering function.') }
/* Before Initializing a Plotter, we need the Storage it will use, loaded with the files it will initially need. */
let objName = pProductCard.devTeam.codeName + '-' + pProductCard.bot.codeName + '-' + pProductCard.product.codeName
let storage = newProductStorage(objName)
if (INFO_LOG === true) { logger.write('[INFO] initializeProductPlotter -> objName = ' + objName) }
/*
Before Initializing the Storage, we will put the Product Card to listen to the events the storage will raise every time a file is loaded,
so that the UI can somehow show this. There are different types of events.
*/
for (let i = 0; i < pProductCard.product.dataSets.length; i++) {
let thisSet = pProductCard.product.dataSets[i]
@@ -412,17 +312,14 @@ function newPlottersManager () {
storage.eventHandler.listenToEvent('Market File Loaded', pProductCard.onMarketFileLoaded)
}
break
case 'Daily Files': {
storage.eventHandler.listenToEvent('Daily File Loaded', pProductCard.onDailyFileLoaded)
}
break
case 'Single File': {
storage.eventHandler.listenToEvent('Single File Loaded', pProductCard.onSingleFileLoaded)
}
break
case 'File Sequence': {
storage.eventHandler.listenToEvent('File Sequence Loaded', pProductCard.onFileSequenceLoaded)
}
@@ -434,53 +331,29 @@ function newPlottersManager () {
function onProductStorageInitialized (err) {
try {
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 -> 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 -> onProductStorageInitialized -> Received FAIL Response.') }
if (INFO_LOG === true) { logger.write('[INFO] initializeProductPlotter -> onProductStorageInitialized -> The plotter will not be started.') }
callBack(GLOBAL.DEFAULT_FAIL_RESPONSE)
return
}
default: {
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.') }
callBack(GLOBAL.DEFAULT_FAIL_RESPONSE)
return
}
}
/* Now we have all the initial data loaded and ready to be delivered to the new instance of the plotter. */
let plotter = getNewPlotter(pProductCard.product.plotter.devTeam, pProductCard.product.plotter.codeName, pProductCard.product.plotter.moduleName)
plotter.container.connectToParent(thisObject.container, true, true, false, true, true, true)
plotter.container.frame.position.x = thisObject.container.frame.width / 2 - plotter.container.frame.width / 2
plotter.container.frame.position.y = thisObject.container.frame.height / 2 - plotter.container.frame.height / 2
plotter.initialize(storage, exchange, market, datetime, timePeriod, onPlotterInizialized)
function onPlotterInizialized () {
try {
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.codeName + '-' + pProductCard.product.plotter.moduleName) }
try {
// plotter.positionAtDatetime(NEW_SESSION_INITIAL_DATE);
} catch (err) {
// If the plotter does not implement this function its ok.
}
let productPlotter = {
productCard: pProductCard,
plotter: plotter,
@@ -488,13 +361,9 @@ function newPlottersManager () {
profile: undefined,
notes: undefined
}
/* Let the Plotter listen to the event of Cursor Files loaded, so that it can reack recalculating if needed. */
storage.eventHandler.listenToEvent('Daily File Loaded', plotter.onDailyFileLoaded)
/* Lets load now this plotter panels. */
productPlotter.panels = []
for (let i = 0; i < pProductCard.product.plotter.module.panels.length; i++) {
@@ -506,53 +375,37 @@ function newPlottersManager () {
moduleCodeName: pProductCard.product.plotter.moduleName,
panelCodeName: panelConfig.codeName
}
let panelOwner = exchange + ' ' + market.assetB + '/' + market.assetA
let plotterPanelHandle = canvas.panelsSpace.createNewPanel('Plotter Panel', parameters, panelOwner)
let plotterPanel = canvas.panelsSpace.getPanel(plotterPanelHandle, panelOwner)
/* Connect Panel to the Plotter via an Event. */
if (panelConfig.event !== undefined) {
productPlotter.plotter.container.eventHandler.listenToEvent(panelConfig.event, plotterPanel.onEventRaised)
}
productPlotter.panels.push(plotterPanelHandle)
}
/* Create The Profie Picture FloatingObject */
if (productPlotter.plotter.payload !== undefined) {
let imageId = pProductCard.bot.devTeam + '.' + pProductCard.bot.profilePicture
productPlotter.plotter.payload.profile.subTitle = pProductCard.product.shortDisplayName
productPlotter.plotter.payload.profile.title = pProductCard.bot.displayName
productPlotter.plotter.payload.profile.imageId = imageId
productPlotter.plotter.payload.profile.botAvatar = pProductCard.bot.avatar
canvas.floatingSpace.profileBalls.createNewProfileBall(productPlotter.plotter.payload, onProfileBallCreated)
function onProfileBallCreated (err, pProfileHandle) {
productPlotter.profile = pProfileHandle
/* There is no policy yet of what to do if this fails. */
}
/* Create the Text Notes */
canvas.floatingSpace.noteSets.createNoteSet(productPlotter.plotter.payload, productPlotter.plotter.container.eventHandler, onNoteSetCreated)
function onNoteSetCreated (err, pNoteSetHandle) {
productPlotter.noteSet = pNoteSetHandle
/* There is no policy yet of what to do if this fails. */
}
}
/* Add the new Active Protter to the Array */
productPlotters.push(productPlotter)
callBack(GLOBAL.DEFAULT_OK_RESPONSE)
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] initializeProductPlotter -> onProductStorageInitialized -> onPlotterInizialized -> err = ' + err.stack) }
@@ -571,60 +424,41 @@ function newPlottersManager () {
}
function onProductCardStatusChanged (pProductCard) {
if (INFO_LOG === true) { logger.write('[INFO] onProductCardStatusChanged -> Entering function.') }
if (pProductCard.status === PRODUCT_CARD_STATUS.LOADING) {
/* Lets see if we can find the Plotter of this card on our Active Plotters list, other wise we will initialize it */
let found = false
for (let i = 0; i < productPlotters.length; i++) {
if (productPlotters[i].productCard.code === pProductCard.code) {
found = true
}
}
if (found === false) {
initializeProductPlotter(pProductCard, onProductPlotterInitialized)
function onProductPlotterInitialized (err) {
if (INFO_LOG === true) { logger.write('[INFO] initializeProductPlotters -> onProductPlotterInitialized -> Entering function.') }
/* There is no policy yet of what to do if this fails. */
}
}
}
if (pProductCard.status === PRODUCT_CARD_STATUS.OFF) {
/* If the plotter of this card is not on our Active Plotters list, then we remove it. */
for (let i = 0; i < productPlotters.length; i++) {
if (productPlotters[i].productCard.code === pProductCard.code) {
if (productPlotters[i].profile !== undefined) {
canvas.floatingSpace.profileBalls.destroyProfileBall(productPlotters[i].profile)
}
/* Destroyd the Note Set */
canvas.floatingSpace.noteSets.destroyNoteSet(productPlotters[i].noteSet)
/* Then the panels. */
for (let j = 0; j < productPlotters[i].panels.length; j++) {
canvas.panelsSpace.destroyPanel(productPlotters[i].panels[j])
}
/* Finally the Storage Objects */
productPlotters[i].storage.finalize()
if (productPlotters[i].plotter.finalize !== undefined) {
productPlotters[i].plotter.container.finalize()
productPlotters[i].plotter.finalize()
}
productPlotters.splice(i, 1) // Delete item from array.
return // We already found the product woth changes and processed it.
}
}
@@ -632,53 +466,38 @@ function newPlottersManager () {
}
function setTimePeriod (pTimePeriod) {
if (INFO_LOG === true) { logger.write('[INFO] setTimePeriod -> Entering function.') }
timePeriod = pTimePeriod
if (initializationReady === true) {
for (let i = 0; i < productPlotters.length; i++) {
let productPlotter = productPlotters[i]
productPlotter.productCard.setTimePeriod(timePeriod)
productPlotter.storage.setTimePeriod(timePeriod)
productPlotter.plotter.setTimePeriod(timePeriod)
}
for (let i = 0; i < competitionPlotters.length; i++) {
let competitionPlotter = competitionPlotters[i]
competitionPlotter.plotter.setTimePeriod(timePeriod)
}
}
}
function setDatetime (pDatetime) {
if (INFO_LOG === true) { logger.write('[INFO] setDatetime -> Entering function.') }
datetime = pDatetime
for (let i = 0; i < productPlotters.length; i++) {
let productPlotter = productPlotters[i]
productPlotter.productCard.setDatetime(pDatetime)
productPlotter.storage.setDatetime(pDatetime)
productPlotter.plotter.setDatetime(pDatetime)
}
for (let i = 0; i < competitionPlotters.length; i++) {
let competitionPlotter = competitionPlotters[i]
competitionPlotter.plotter.setDatetime(datetime)
for (let i = 0; i < competitionPlotters.length; i++) {
let competitionPlotter = competitionPlotters[i]
competitionPlotter.plotter.setDatetime(datetime)
}
}
}
function positionAtDatetime (pDatetime) {
if (INFO_LOG === true) { logger.write('[INFO] positionAtDatetime -> Entering function.') }
for (let i = 0; i < productPlotters.length; i++) {
let productPlotter = productPlotters[i]
if (productPlotter.plotter.positionAtDatetime !== undefined) {
productPlotter.plotter.positionAtDatetime(pDatetime)
}
@@ -686,30 +505,20 @@ function newPlottersManager () {
}
function getContainer (point) {
if (INFO_LOG === true) { logger.write('[INFO] getContainer -> Entering function.') }
let container
return container
}
function draw () {
if (INTENSIVE_LOG === true) { logger.write('[INFO] draw -> Entering function.') }
if (productPlotters === undefined) { return } // We need to wait
/* First the Product Plotters. */
for (let i = 0; i < productPlotters.length; i++) {
let productPlotter = productPlotters[i]
productPlotter.plotter.draw()
}
/* Then the competition plotters. */
for (let i = 0; i < competitionPlotters.length; i++) {
let competitionPlotter = competitionPlotters[i]
competitionPlotter.plotter.draw()
}
}
}
+4
View File
@@ -18,6 +18,7 @@ function newTimeMachine () {
container: undefined,
timeScale: undefined,
rateScale: undefined,
fitFunction: undefined,
charts: [],
physics: physics,
drawBackground: drawBackground,
@@ -65,6 +66,7 @@ function newTimeMachine () {
thisObject.timeScale = undefined
thisObject.rateScale.finalize()
thisObject.rateScale = undefined
thisObject.fitFunction = undefined
}
function initialize (callBackFunction) {
@@ -106,6 +108,7 @@ function newTimeMachine () {
/* Each Time Machine has a Time Scale and a Right Scale. */
thisObject.timeScale = newTimeScale()
thisObject.timeScale.fitFunction = thisObject.fitFunction
thisObject.timeScale.container.eventHandler.listenToEvent('Lenght Percentage Changed', function (event) {
thisObject.container.frame.width = TIME_MACHINE_WIDTH * event.lenghtPercentage / 100
@@ -117,6 +120,7 @@ function newTimeMachine () {
thisObject.timeScale.initialize()
thisObject.rateScale = newRateScale()
thisObject.rateScale.fitFunction = thisObject.fitFunction
thisObject.rateScale.container.eventHandler.listenToEvent('Height Percentage Changed', function (event) {
thisObject.container.frame.height = TIME_MACHINE_HEIGHT * event.heightPercentage / 100
+50 -8
View File
@@ -28,6 +28,7 @@ function newRestartSimulation () {
let isMouseOver = false
let counterTillNextState = 0
let productCardsToTurnOn = []
return thisObject
function finalize () {
@@ -103,16 +104,47 @@ function newRestartSimulation () {
timePeriodMarketArray: timePeriodMarketArray
}
try {
thisObject.status = 'Restarting'
await graphQlRestartSimulation(simulationParams)
thisObject.status = 'Calculating'
counterTillNextState = 1000
thisObject.status = 'Saving'
let result = await canvas.strategySpace.workplace.saveToStrategyzer()
if (result === true) {
thisObject.status = 'Restarting'
await graphQlRestartSimulation(simulationParams)
thisObject.status = 'Calculating'
counterTillNextState = 2000
turnOffProductCards()
} else {
thisObject.status = 'Error'
counterTillNextState = 500
}
} catch (err) {
thisObject.status = 'Error'
counterTillNextState = 500
}
}
function turnOffProductCards () {
for (let i = 0; i < canvas.panelsSpace.panels.length; i++) {
let panel = canvas.panelsSpace.panels[i]
if (panel.name === 'Products Panel') {
for (j = 0; j < panel.productCards.length; j++) {
let productCard = panel.productCards[j]
if (productCard.product.relatedToTradingEngine === true && productCard.status !== PRODUCT_CARD_STATUS.OFF) {
productCard.turnOff()
productCardsToTurnOn.push(productCard)
}
}
}
}
}
function turnOnProductCards () {
for (let i = 0; i < productCardsToTurnOn.length; i++) {
let productCard = productCardsToTurnOn[i]
productCard.turnOn()
}
productCardsToTurnOn = []
}
function physics () {
if (counterTillNextState > 0) {
counterTillNextState--
@@ -121,12 +153,16 @@ function newRestartSimulation () {
switch (thisObject.status) {
case 'Ready':
break
case 'Saving':
break
case 'Restarting':
break
case 'Calculating':
thisObject.status = 'Ready'
turnOnProductCards()
break
case 'Error':
thisObject.status = 'Ready'
@@ -161,6 +197,9 @@ function newRestartSimulation () {
}
break
}
case 'Saving':
params.backgroundColor = UI_COLOR.GREY
break
case 'Restarting':
params.backgroundColor = UI_COLOR.GREY
break
@@ -191,21 +230,24 @@ function newRestartSimulation () {
switch (thisObject.status) {
case 'Ready':
label = 'RESTART SIMULATION'
label = 'RE-CALCULATE'
break
case 'Saving':
label = 'SAVING STRATEGIES CHANGES...'
break
case 'Restarting':
label = 'RESTARTING...'
label = 'RESTARTING TRADING ENGINE...'
break
case 'Calculating':
label = 'CALCULATING...'
break
case 'Error':
label = 'NOT POSSIBLE NOW'
label = 'ERROR, RETRY LATER'
break
}
let labelPoint = {
x: thisObject.container.frame.width / 2 - label.length / 2 * fontSize * FONT_ASPECT_RATIO - 15,
x: thisObject.container.frame.width / 2 - label.length / 2 * fontSize * FONT_ASPECT_RATIO - 25,
y: thisObject.container.frame.height - 9
}
labelPoint = thisObject.container.frame.frameThisPoint(labelPoint)
+48 -113
View File
@@ -1,22 +1,20 @@
function newProductCard () {
const CONSOLE_LOG = false
const MODULE_NAME = 'Product Card'
const INFO_LOG = false
const ERROR_LOG = true
const INTENSIVE_LOG = false
const logger = newWebDebugLog()
logger.fileName = MODULE_NAME
let thisObject = {
container: undefined,
draw: draw,
status: 'off',
status: PRODUCT_CARD_STATUS.OFF,
devTeam: undefined,
bot: undefined,
product: undefined,
code: undefined,
fitFunction: undefined,
turnOff: turnOff,
turnOn: turnOn,
setDatetime: setDatetime,
setTimePeriod: setTimePeriod,
onMarketFileLoaded: onMarketFileLoaded,
@@ -109,8 +107,6 @@ function newProductCard () {
function initialize () {
/* Create this objects continer */
try {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
thisObject.container = newContainer()
thisObject.container.initialize(MODULE_NAME + thisObject.code)
thisObject.container.detectMouseOver = true
@@ -159,7 +155,7 @@ function newProductCard () {
*/
const DEFAULT_ON_PRODUCT = 'AAMasters-AAOlivia-Candles'
const DEFAULT_ON_PRODUCT = 'Poloniex-BTC/USDT-AAMasters-AAOlivia-Candles'
if (thisObject.code === DEFAULT_ON_PRODUCT) {
changeStatusTo(PRODUCT_CARD_STATUS.LOADING)
@@ -170,7 +166,7 @@ function newProductCard () {
/* Lets listen to our own events to react when we have a Mouse Click */
thisObject.container.eventHandler.listenToEvent('onMouseClick', buttonPressed)
thisObject.container.eventHandler.listenToEvent('onMouseClick', onMouseClick)
thisObject.container.eventHandler.listenToEvent('onMouseOver', onMouseOver)
/* WARNING THIS IS TEMPORARY CODE */
@@ -285,10 +281,6 @@ function newProductCard () {
if (currentDate !== newDate) {
if (timePeriod <= _1_HOUR_IN_MILISECONDS) {
dailyFileProgressBar.animatedValue = 0
if (CONSOLE_LOG === true) {
console.log('ProductCard -> onDayChanged -> dailyFileProgressBar.animatedValue = ' + dailyFileProgressBar.animatedValue)
}
}
}
}
@@ -306,10 +298,6 @@ function newProductCard () {
if (timePeriod <= _1_HOUR_IN_MILISECONDS) {
dailyFileProgressBar.animatedValue = 0
if (CONSOLE_LOG === true) {
console.log('ProductCard -> onTimePeriodChanged -> dailyFileProgressBar.animatedValue = ' + dailyFileProgressBar.animatedValue)
}
}
}
}
@@ -320,10 +308,6 @@ function newProductCard () {
marketFileProgressBar.strokeStyle = LOADING_STROKE_STYLE
if (marketFileProgressBar.value > 100) { marketFileProgressBar.value = 100 }
if (CONSOLE_LOG === true) {
console.log('ProductCard onMarketFileLoaded Value = ' + marketFileProgressBar.value + '% for ' + thisObject.code + '. Event = ' + JSON.stringify(event))
}
}
function onDailyFileLoaded (event) {
@@ -332,10 +316,6 @@ function newProductCard () {
dailyFileProgressBar.strokeStyle = LOADING_STROKE_STYLE
if (dailyFileProgressBar.value > 100) { dailyFileProgressBar.value = 100 }
if (CONSOLE_LOG === true) {
console.log('ProductCard onDailyFileLoaded Value = ' + dailyFileProgressBar.value + '% for ' + thisObject.code + '. Event = ' + JSON.stringify(event))
}
}
function onSingleFileLoaded (event) {
@@ -344,10 +324,6 @@ function newProductCard () {
singleFileProgressBar.strokeStyle = LOADING_STROKE_STYLE
if (singleFileProgressBar.value > 100) { singleFileProgressBar.value = 100 }
if (CONSOLE_LOG === true) {
console.log('ProductCard onSingleFileLoaded Value = ' + singleFileProgressBar.value + '% for ' + thisObject.code + '. Event = ' + JSON.stringify(event))
}
}
function onFileSequenceLoaded (event) {
@@ -356,50 +332,55 @@ function newProductCard () {
fileSequenceProgressBar.strokeStyle = LOADING_STROKE_STYLE
if (fileSequenceProgressBar.value > 100) { fileSequenceProgressBar.value = 100 }
}
if (CONSOLE_LOG === true) {
console.log('ProductCard onFileSequenceLoaded Value = ' + fileSequenceProgressBar.value + '% for ' + thisObject.code + '. Event = ' + JSON.stringify(event))
function turnOff () {
if (thisObject.status !== PRODUCT_CARD_STATUS.OFF) {
resetProgressBars()
changeStatusTo(PRODUCT_CARD_STATUS.OFF)
}
}
function buttonPressed (event) {
switch (thisObject.status) {
case PRODUCT_CARD_STATUS.ON:
changeStatusTo(PRODUCT_CARD_STATUS.OFF)
marketFileProgressBar.animatedValue = 0
marketFileProgressBar.value = 0
marketFileProgressBar.fillStyle = UNLOADED_FILL_STYLE
marketFileProgressBar.strokeStyle = UNLOADED_STROKE_STYLE
dailyFileProgressBar.animatedValue = 0
dailyFileProgressBar.value = 0
dailyFileProgressBar.fillStyle = UNLOADED_FILL_STYLE
dailyFileProgressBar.strokeStyle = UNLOADED_STROKE_STYLE
singleFileProgressBar.animatedValue = 0
singleFileProgressBar.value = 0
singleFileProgressBar.fillStyle = UNLOADED_FILL_STYLE
singleFileProgressBar.strokeStyle = UNLOADED_STROKE_STYLE
fileSequenceProgressBar.animatedValue = 0
fileSequenceProgressBar.value = 0
fileSequenceProgressBar.fillStyle = UNLOADED_FILL_STYLE
fileSequenceProgressBar.strokeStyle = UNLOADED_STROKE_STYLE
break
case PRODUCT_CARD_STATUS.OFF:
changeStatusTo(PRODUCT_CARD_STATUS.LOADING)
break
function turnOn () {
if (thisObject.status === PRODUCT_CARD_STATUS.OFF) {
changeStatusTo(PRODUCT_CARD_STATUS.LOADING)
}
}
function onMouseClick (event) {
switch (thisObject.status) {
case PRODUCT_CARD_STATUS.ON:
resetProgressBars()
changeStatusTo(PRODUCT_CARD_STATUS.OFF)
break
case PRODUCT_CARD_STATUS.OFF:
changeStatusTo(PRODUCT_CARD_STATUS.LOADING)
break
}
}
function resetProgressBars () {
marketFileProgressBar.animatedValue = 0
marketFileProgressBar.value = 0
marketFileProgressBar.fillStyle = UNLOADED_FILL_STYLE
marketFileProgressBar.strokeStyle = UNLOADED_STROKE_STYLE
dailyFileProgressBar.animatedValue = 0
dailyFileProgressBar.value = 0
dailyFileProgressBar.fillStyle = UNLOADED_FILL_STYLE
dailyFileProgressBar.strokeStyle = UNLOADED_STROKE_STYLE
singleFileProgressBar.animatedValue = 0
singleFileProgressBar.value = 0
singleFileProgressBar.fillStyle = UNLOADED_FILL_STYLE
singleFileProgressBar.strokeStyle = UNLOADED_STROKE_STYLE
fileSequenceProgressBar.animatedValue = 0
fileSequenceProgressBar.value = 0
fileSequenceProgressBar.fillStyle = UNLOADED_FILL_STYLE
fileSequenceProgressBar.strokeStyle = UNLOADED_STROKE_STYLE
}
function onMouseOver (event) {
lastMouseOver = 25
}
@@ -407,11 +388,8 @@ function newProductCard () {
function changeStatusTo (pNewStatus) {
if (thisObject.status !== pNewStatus) {
thisObject.status = pNewStatus
let eventData = thisObject
thisObject.container.eventHandler.raiseEvent('Status Changed', eventData)
window.localStorage.setItem(thisObject.code, thisObject.status)
}
}
@@ -422,9 +400,7 @@ function newProductCard () {
function drawProductCard () {
/*
Put images on the card.
*/
let fitImagePoint = {
@@ -443,30 +419,23 @@ function newProductCard () {
if (lastMouseOver > 0) {
/* First the Dev Team Profile Picture. */
let teamImagePoint = {
x: 2,
y: thisObject.container.frame.height / 2 - devTeamImageSize / 2
}
teamImagePoint = thisObject.container.frame.frameThisPoint(teamImagePoint)
fitImagePoint = thisObject.fitFunction(teamImagePoint)
let teamImage
if (legacyTeamAvatarLoaded === true) {
teamImage = legacyTeamAvatar
}
if (teamAvatarLoaded === true) {
teamImage = teamAvatar
}
if (teamImage !== undefined && teamImagePoint.y === fitImagePoint.y) {
if (teamImage.naturalHeight !== 0) {
/* The image is rounded before being displayed. */
browserCanvasContext.save()
browserCanvasContext.beginPath()
browserCanvasContext.arc(teamImagePoint.x + devTeamImageSize / 2, teamImagePoint.y + devTeamImageSize / 2, devTeamImageSize / 2, 0, Math.PI * 2, true)
@@ -482,27 +451,21 @@ function newProductCard () {
}
/* Second the Bot's Profile Picture. */
if (thisObject.bot.profilePicture !== undefined) {
let botImagePoint = {
x: thisObject.container.frame.width - botImageSize / 2 - 8,
y: thisObject.container.frame.height / 2 - botImageSize / 2
}
botImagePoint = thisObject.container.frame.frameThisPoint(botImagePoint)
fitImagePoint = thisObject.fitFunction(botImagePoint)
let imageId = thisObject.bot.devTeam + '.' + thisObject.bot.profilePicture
/* TODO Temporary code */
let botImage
botImage = thisObject.bot.avatar
if (botImage !== undefined && botImagePoint.y === fitImagePoint.y) {
if (botImage.naturalHeight !== 0) {
/* The image is rounded before being displayed. */
browserCanvasContext.save()
browserCanvasContext.beginPath()
browserCanvasContext.arc(botImagePoint.x + botImageSize / 2, botImagePoint.y + botImageSize / 2, botImageSize / 2, 0, Math.PI * 2, true)
@@ -518,33 +481,26 @@ function newProductCard () {
}
}
}
/* Third the Plotter's Profile Picture. */
if (thisObject.product.plotter.profilePicture !== undefined) {
let plotterImagePoint = {
x: thisObject.container.frame.width / 2 - plotterImageSize.width / 2,
y: thisObject.container.frame.height / 2 - plotterImageSize.height / 2
}
plotterImagePoint = thisObject.container.frame.frameThisPoint(plotterImagePoint)
fitImagePoint = {
x: 0,
y: plotterImagePoint.y + plotterImageSize.height
}
fitImagePoint = thisObject.fitFunction(fitImagePoint)
let imageId = thisObject.product.plotter.devTeam + '.' + thisObject.product.plotter.codeName + '.' + thisObject.product.plotter.moduleName + '.' + thisObject.product.plotter.profilePicture
let plotterImage = legacyPlotterBanner
if (plotterImage !== undefined && plotterImagePoint.y + plotterImageSize.height === fitImagePoint.y) {
if (plotterImage.naturalHeight !== 0) {
browserCanvasContext.drawImage(plotterImage, plotterImagePoint.x, plotterImagePoint.y, plotterImageSize.width, plotterImageSize.height)
}
}
}
drawProductLoadStatus()
function drawProductLoadStatus () {
@@ -553,19 +509,15 @@ function newProductCard () {
let loadingFillStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 0.40)'
switch (thisObject.status) {
case PRODUCT_CARD_STATUS.ON:
browserCanvasContext.fillStyle = onFillStyle
break
case PRODUCT_CARD_STATUS.OFF:
browserCanvasContext.fillStyle = offFillStyle
break
case PRODUCT_CARD_STATUS.LOADING:
browserCanvasContext.fillStyle = loadingFillStyle
break
}
let centerPoint = {
@@ -592,9 +544,7 @@ function newProductCard () {
x: centerPoint.x - plotterImageSize.width / 2,
y: centerPoint.y - plotterImageSize.height / 2 + 7
}
/* Now the transformations. */
point1 = thisObject.container.frame.frameThisPoint(point1)
point2 = thisObject.container.frame.frameThisPoint(point2)
point3 = thisObject.container.frame.frameThisPoint(point3)
@@ -611,28 +561,21 @@ function newProductCard () {
browserCanvasContext.lineTo(point3.x, point3.y)
browserCanvasContext.lineTo(point4.x, point4.y)
browserCanvasContext.closePath()
browserCanvasContext.fill()
browserCanvasContext.strokeStyle = 'rgba(150, 150, 150, 1)'
browserCanvasContext.lineWidth = 0.1
browserCanvasContext.stroke()
}
/*
print the text
*/
let labelPoint
let fontSize = 10
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY
let label
if (lastMouseOver > 0) {
/* devTeam */
label = thisObject.devTeam.displayName
if (label.length > 10) { label = label.substring(1, 8) + '...' }
@@ -643,13 +586,10 @@ function newProductCard () {
labelPoint = thisObject.container.frame.frameThisPoint(labelPoint)
labelPoint = thisObject.fitFunction(labelPoint)
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY
browserCanvasContext.fillStyle = 'rgba(60, 60, 60, 0.50)'
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y)
/* bot */
label = thisObject.bot.displayName
if (label.length > 10) { label = label.substring(1, 8) + '...' }
@@ -665,23 +605,17 @@ function newProductCard () {
browserCanvasContext.fillStyle = 'rgba(60, 60, 60, 0.50)'
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y)
}
/* product */
fontSize = 10
label = thisObject.product.displayName
labelPoint = {
x: 65,
y: thisObject.container.frame.height / 2 + 15
}
labelPoint = {
x: thisObject.container.frame.width / 2 - label.length / 2 * fontSize * FONT_ASPECT_RATIO,
y: thisObject.container.frame.height / 2 - devTeamImageSize / 2 - fontSize * FONT_ASPECT_RATIO - 20
}
labelPoint = thisObject.container.frame.frameThisPoint(labelPoint)
labelPoint = thisObject.fitFunction(labelPoint)
@@ -969,3 +903,4 @@ function newProductCard () {
browserCanvasContext.stroke()
}
}
+15 -14
View File
@@ -1,7 +1,9 @@
function newProductsPanel () {
let thisObject = {
name: 'Products Panel',
fitFunction: undefined,
container: undefined,
productCards: [],
getLoadingProductCards: getLoadingProductCards,
draw: draw,
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
@@ -20,7 +22,6 @@ function newProductsPanel () {
thisObject.container = container
let isInitialized = false
let productCards = []
let visibleProductCards = []
let firstVisibleCard = 1
@@ -65,7 +66,7 @@ function newProductsPanel () {
userTeams = JSON.parse(storedTeams)
}
/* First thing is to build the productCards array */
/* First thing is to build the thisObject.productCards array */
let devTeams = ecosystem.getTeams()
@@ -119,7 +120,7 @@ function newProductsPanel () {
/* Add to the Product Array */
productCards.push(productCard)
thisObject.productCards.push(productCard)
/* Add to Visible Product Array */
@@ -153,14 +154,14 @@ function newProductsPanel () {
let availableSlots = visibleProductCards.length
if (firstVisibleCard < 1) { firstVisibleCard = 1 }
if (firstVisibleCard > (productCards.length - availableSlots + 1)) { firstVisibleCard = productCards.length - availableSlots + 1 }
if (firstVisibleCard > (thisObject.productCards.length - availableSlots + 1)) { firstVisibleCard = thisObject.productCards.length - availableSlots + 1 }
visibleProductCards = []
let lastY = 5
for (let i = 0; i < productCards.length; i++) {
for (let i = 0; i < thisObject.productCards.length; i++) {
if (i + 1 >= firstVisibleCard && i + 1 < firstVisibleCard + availableSlots) {
let productCard = productCards[i]
let productCard = thisObject.productCards[i]
/* Positioning within thisObject Panel */
@@ -185,13 +186,13 @@ function newProductsPanel () {
}
function getLoadingProductCards () {
/* Returns all productCards which status is LOADING */
/* Returns all thisObject.productCards which status is LOADING */
let onProducts = []
for (let i = 0; i < productCards.length; i++) {
if (productCards[i].status === PRODUCT_CARD_STATUS.LOADING) {
onProducts.push(productCards[i])
for (let i = 0; i < thisObject.productCards.length; i++) {
if (thisObject.productCards[i].status === PRODUCT_CARD_STATUS.LOADING) {
onProducts.push(thisObject.productCards[i])
}
}
@@ -253,16 +254,16 @@ function newProductsPanel () {
panelTabButton.draw()
}
function isUserTeam(team, userTeams){
if(userTeams === undefined)
function isUserTeam (team, userTeams) {
if (userTeams === undefined) {
return false
}
for (let index = 0; index < userTeams.length; index++) {
if(team === userTeams[index].slug){
if (team === userTeams[index].slug) {
return true
}
}
return false
}
}
+14 -119
View File
@@ -1,7 +1,6 @@

function newProductStorage (pName) {
const MODULE_NAME = 'Product Storage'
const INFO_LOG = false
const ERROR_LOG = true
const logger = newWebDebugLog()
logger.fileName = MODULE_NAME
@@ -26,19 +25,15 @@ function newProductStorage (pName) {
*/
let thisObject = {
eventHandler: undefined,
marketFiles: [],
dailyFiles: [],
singleFile: [],
fileSequences: [],
setDatetime: setDatetime,
setTimePeriod: setTimePeriod,
eventHandler: undefined,
initialize: initialize,
finalize: finalize
}
thisObject.eventHandler = newEventHandler()
@@ -54,8 +49,6 @@ function newProductStorage (pName) {
function finalize () {
try {
if (INFO_LOG === true) { logger.write('[INFO] finalize -> Entering function.') }
for (let i = 0; i < thisObject.marketFiles.length; i++) {
let marketFile = thisObject.marketFiles[i]
marketFile.finalize()
@@ -83,29 +76,19 @@ function newProductStorage (pName) {
function initialize (pDevTeam, pBot, pProduct, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> key = ' + pDevTeam.codeName + '-' + pBot.codeName + '-' + pProduct.codeName) }
datetime = pDatetime
timePeriod = pTimePeriod
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]
switch (thisSet.type) {
case 'Market Files': {
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)
@@ -113,12 +96,8 @@ function newProductStorage (pName) {
break
case 'Daily Files': {
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)
@@ -126,12 +105,8 @@ function newProductStorage (pName) {
break
case 'Single File': {
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)
@@ -139,12 +114,8 @@ function newProductStorage (pName) {
break
case 'File Sequence': {
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 fileSequences = newFileSequence()
fileSequences.initialize(pDevTeam, pBot, pProduct, thisSet, pExchange, pMarket, onFileSequenceReady)
thisObject.fileSequences.push(fileSequences)
@@ -154,36 +125,15 @@ function newProductStorage (pName) {
function onMarketFileReady (err, pCaller) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onMarketFileReady -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onMarketFileReady -> key = ' + pDevTeam.codeName + '-' + pBot.codeName + '-' + pProduct.codeName) }
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onMarketFileReady -> Received OK Response.') }
break
}
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onMarketFileReady -> Received FAIL Response.') }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
return
}
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onMarketFileReady -> Received CUSTOM FAIL Response.') }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onMarketFileReady -> err= ' + err.stack) }
callBackFunction(err)
return
}
default: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onMarketFileReady -> Received Unexpected Response.') }
callBackFunction(err)
return
}
}
let event = {
totalValue: pCaller.getExpectedFiles(),
currentValue: pCaller.getFilesLoaded(),
@@ -192,49 +142,44 @@ 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.filesNotLoaded === event.totalValue) {
dataSetsToLoad--
checkInitializeComplete()
return
}
if (event.currentValue + event.filesNotLoaded === event.totalValue) {
dataSetsLoaded++
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onMarketFileReady -> dataSetsLoaded = ' + dataSetsLoaded) }
checkInitializeComplete()
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onMarketFileReady -> err = ' + err.stack) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
function onDailyFileReady (err, pCaller) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onDailyFileReady -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onDailyFileReady -> key = ' + pDevTeam.codeName + '-' + pBot.codeName + '-' + pProduct.codeName) }
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onDailyFileReady -> Received OK Response.') }
break
}
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onDailyFileReady -> Received FAIL Response.') }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
return
}
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onDailyFileReady -> Received CUSTOM FAIL Response.') }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onDailyFileReady -> err= ' + err.stack) }
callBackFunction(err)
return
if (err.message === 'Dataset Unavailable.') {
dataSetsToLoad--
checkInitializeComplete()
return
} else {
callBackFunction(err)
return
}
}
default: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onDailyFileReady -> Received Unexpected Response.') }
callBackFunction(err)
return
}
@@ -247,134 +192,88 @@ 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()
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onDailyFileReady -> err = ' + err.stack) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
function onSingleFileReady (err, pCaller) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSingleFileReady -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSingleFileReady -> key = ' + pDevTeam.codeName + '-' + pBot.codeName + '-' + pProduct.codeName) }
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSingleFileReady -> Received OK Response.') }
break
}
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSingleFileReady -> Received FAIL Response.') }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
return
}
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSingleFileReady -> Received CUSTOM FAIL Response.') }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSingleFileReady -> err= ' + err.stack) }
callBackFunction(err)
return
}
default: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSingleFileReady -> Received Unexpected Response.') }
callBackFunction(err)
return
}
}
let event = {
totalValue: 1,
currentValue: 1
}
thisObject.eventHandler.raiseEvent('Single File Loaded', event)
if (event.currentValue === event.totalValue) {
dataSetsLoaded++
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSingleFileReady -> dataSetsLoaded = ' + dataSetsLoaded) }
checkInitializeComplete()
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onSingleFileReady -> err = ' + err.stack) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
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 = ' + pDevTeam.codeName + '-' + pBot.codeName + '-' + pProduct.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= ' + err.stack) }
callBackFunction(err)
return
}
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++
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileSequenceReady = ' + dataSetsLoaded) }
checkInitializeComplete()
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onFileSequenceReady -> err = ' + err.stack) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
function checkInitializeComplete () {
try {
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) {
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE)
}
@@ -391,8 +290,6 @@ function newProductStorage (pName) {
}
function setDatetime (pDatetime) {
if (INFO_LOG === true) { logger.write('[INFO] setDatetime -> Entering function.') }
/* If there is a change in the day, then we take some actions, otherwise, we dont. */
let currentDate = Math.trunc(datetime.valueOf() / ONE_DAY_IN_MILISECONDS)
@@ -410,8 +307,6 @@ function newProductStorage (pName) {
}
function setTimePeriod (pTimePeriod) {
if (INFO_LOG === true) { logger.write('[INFO] setTimePeriod -> Entering function.') }
/* We are going to filter out the cases in which the timePeriod received is the same that the one we already know. */
if (timePeriod !== pTimePeriod) {
+8 -2
View File
@@ -1,5 +1,5 @@
function drawScaleDisplay (label1, label2, xExtraOffSet1, xExtraOffSet2, container) {
function drawScaleDisplay (label1, label2, xExtraOffSet1, xExtraOffSet2, container, fitFunction) {
let fontSize1 = 20
let fontSize2 = 10
@@ -13,7 +13,8 @@ function drawScaleDisplay (label1, label2, xExtraOffSet1, xExtraOffSet2, contain
borderColor: UI_COLOR.RUSTED_RED,
castShadow: false,
backgroundColor: UI_COLOR.DARK,
opacity: OPACITY
opacity: OPACITY,
fitFunction: fitFunction
}
roundedCornersBackground(params)
@@ -28,6 +29,9 @@ function drawScaleDisplay (label1, label2, xExtraOffSet1, xExtraOffSet2, contain
}
labelPoint1 = container.frame.frameThisPoint(labelPoint1)
let x = labelPoint1.x
labelPoint1 = fitFunction(labelPoint1)
labelPoint1.x = x
browserCanvasContext.font = fontSize1 + 'px ' + UI_FONT.PRIMARY
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 1)'
@@ -42,9 +46,11 @@ function drawScaleDisplay (label1, label2, xExtraOffSet1, xExtraOffSet2, contain
}
labelPoint2 = container.frame.frameThisPoint(labelPoint2)
labelPoint2 = fitFunction(labelPoint2)
browserCanvasContext.font = fontSize2 + 'px ' + UI_FONT.PRIMARY
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 1)'
browserCanvasContext.fillText(label2, labelPoint2.x, labelPoint2.y)
}
+4 -2
View File
@@ -2,10 +2,11 @@ function newRateScale () {
const MODULE_NAME = 'Right Scale'
let thisObject = {
heightPercentage: 100,
container: undefined,
rate: undefined,
fitFunction: undefined,
visible: true,
heightPercentage: 100,
physics: physics,
draw: draw,
getContainer: getContainer,
@@ -34,6 +35,7 @@ function newRateScale () {
function finalize () {
thisObject.container.finalize()
thisObject.container = undefined
thisObject.fitFunction = undefined
}
function initialize () {
@@ -201,7 +203,7 @@ function newRateScale () {
let label1 = (Math.trunc(thisObject.rate)).toLocaleString()
let label2 = labelArray[1]
drawScaleDisplay(label1, label2, 10, 40, thisObject.container)
drawScaleDisplay(label1, label2, 10, 40, thisObject.container, thisObject.fitFunction)
}
}
+3 -1
View File
@@ -5,6 +5,7 @@ function newTimeScale () {
lenghtPercentage: undefined,
container: undefined,
date: undefined,
fitFunction: undefined,
visible: true,
physics: physics,
draw: draw,
@@ -34,6 +35,7 @@ function newTimeScale () {
function finalize () {
thisObject.container.finalize()
thisObject.container = undefined
thisObject.fitFunction = undefined
}
function initialize () {
@@ -202,7 +204,7 @@ function newTimeScale () {
let label1 = labelArray[1] + ' ' + labelArray[2] + ' ' + labelArray[3]
let label2 = labelArray[4]
drawScaleDisplay(label1, label2, 10, 60, thisObject.container)
drawScaleDisplay(label1, label2, 10, 60, thisObject.container, thisObject.fitFunction)
}
}
+1
View File
@@ -57,6 +57,7 @@ function newChartSpace () {
timeMachine.container.frame.position.x = thisObject.container.frame.width / 2 - timeMachine.container.frame.width / 2
timeMachine.container.frame.position.y = thisObject.container.frame.height / 2 - timeMachine.container.frame.height / 2
timeMachine.container.fitFunction = fitIntoVisibleArea
timeMachine.fitFunction = fitIntoVisibleArea
timeMachine.initialize(onTimeMachineInitialized)
function onTimeMachineInitialized (err) {