Restarting Simulation at right date and timePeriod

This commit is contained in:
Luis Fernando Molina committed 2019-05-15 17:50:26 +02:00
1 parent e0db4ec80b
commit 562bc0dc52
7 files changed
+106 -37

No files matched your search

+31 -29
View File
@@ -11,15 +11,15 @@ each one with it own charts, and each one positioned at an especific point in ti
function newTimeMachine () {
const MODULE_NAME = 'Time Machine'
const INFO_LOG = false
const logger = newWebDebugLog()
logger.fileName = MODULE_NAME
let thisObject = {
container: undefined,
charts: [],
physics: physics,
drawBackground: drawBackground,
draw: draw,
charts: [],
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
initialize: initialize,
finalize: finalize
@@ -41,28 +41,20 @@ function newTimeMachine () {
const SEPARATION_BETWEEN_TIMELINE_CHARTS = 1.5
let timeScale
let rigthScale
let rateScale
let timeLineCoordinateSystem = newTimeLineCoordinateSystem()
return thisObject
function finalize () {
try {
if (INFO_LOG === true) { logger.write('[INFO] finalize -> Entering function.') }
for (let i = 0; i < thisObject.charts.length; i++) {
let chart = thisObject.charts[i]
chart.finalize()
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] finalize -> err = ' + err.stack) }
for (let i = 0; i < thisObject.charts.length; i++) {
let chart = thisObject.charts[i]
chart.finalize()
}
}
function initialize (callBackFunction) {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
/* Each Time Machine has a Control Panel. */
let panelOwner = 'Global'
@@ -114,21 +106,19 @@ function newTimeMachine () {
timeScale.initialize(timeLineCoordinateSystem)
rigthScale = newRateScale()
rigthScale.container.connectToParent(thisObject.container, false, false, false, true, true, true)
rigthScale.container.eventHandler.listenToEvent('Height Percentage Changed', function (event) {
rateScale = newRateScale()
rateScale.container.connectToParent(thisObject.container, false, false, false, true, true, true)
rateScale.container.eventHandler.listenToEvent('Height Percentage Changed', function (event) {
thisObject.container.frame.height = TIME_MACHINE_HEIGHT * event.heightPercentage / 100
thisObject.container.eventHandler.raiseEvent('Dimmensions Changed', event)
})
rigthScale.initialize(timeLineCoordinateSystem)
rateScale.initialize(timeLineCoordinateSystem)
initializeTheRest()
}
function initializeTheRest () {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> initializeTheRest -> Entering function.') }
let leftToInitialize = SUPPORTED_EXCHANGES.length * SUPPORTED_MARKETS.length - 1 // The default exchange and market was already initialized.
let alreadyInitialized = 0
@@ -153,8 +143,6 @@ function newTimeMachine () {
}
function initializeTimelineChart (exchange, market) {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> initializeTheRest -> initializeTimelineChart -> Entering function.') }
let timelineChart = newTimelineChart()
timelineChart.container.connectToParent(thisObject.container, true, true, false, true, true, true)
@@ -169,8 +157,6 @@ function newTimeMachine () {
timelineChart.initialize(exchange, market, timeLineCoordinateSystem, finalSteps)
function finalSteps () {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> initializeTheRest -> initializeTimelineChart -> finalSteps -> Entering function.') }
thisObject.charts.push(timelineChart)
controlPanel.container.eventHandler.listenToEvent('Datetime Changed', timelineChart.setDatetime, undefined)
@@ -198,8 +184,8 @@ function newTimeMachine () {
}
}
if (rigthScale !== undefined) {
container = rigthScale.getContainer(point)
if (rateScale !== undefined) {
container = rateScale.getContainer(point)
if (container !== undefined) {
if (container.isForThisPurpose(purpose)) {
return container
@@ -228,6 +214,24 @@ function newTimeMachine () {
}
}
function physics () {
thisObjectPhysics()
childrenPhysics()
}
function thisObjectPhysics () {
}
function childrenPhysics () {
timeScale.physics()
rateScale.physics()
for (let i = 0; i < thisObject.charts.length; i++) {
let chart = thisObject.charts[i]
chart.physics()
}
}
function drawBackground () {
thisBackground()
@@ -247,7 +251,7 @@ function newTimeMachine () {
}
if (timeScale !== undefined) { timeScale.draw() }
if (rigthScale !== undefined) { rigthScale.draw() }
if (rateScale !== undefined) { rateScale.draw() }
// thisObject.container.frame.draw(false, true, false)
}
@@ -269,8 +273,6 @@ function newTimeMachine () {
}
function recalculateScale () {
if (INFO_LOG === true) { logger.write('[INFO] recalculateScale -> Entering function.') }
let minValue = {
x: MIN_PLOTABLE_DATE.valueOf(),
y: 0
+14
View File
@@ -14,6 +14,7 @@ function newTimelineChart () {
let thisObject = {
container: undefined,
fitFunction: undefined,
physics: physics,
setDatetime: setDatetime,
drawBackground: drawBackground,
draw: draw,
@@ -239,6 +240,19 @@ function newTimelineChart () {
return container
}
function physics () {
thisObjectPhysics()
childrenPhysics()
}
function thisObjectPhysics () {
}
function childrenPhysics () {
}
function tooTiny () {
if (viewPort.zoomLevel < Math.trunc(-28.25 * 100) / 100) {
return true
+26 -4
View File
@@ -71,11 +71,32 @@ function newRestartSimulation () {
}
async function onMouseClick (event) {
let dateAtScreenCorner = new Date(window.localStorage.getItem('Date @ Screen Corner'))
let currentTimePeriod = JSON.parse(window.localStorage.getItem('Current Time Period'))
let timePeriodsMasterArray = [marketFilesPeriods, dailyFilePeriods]
let timePeriodArray = timePeriodsMasterArray[currentTimePeriod.filePeriodIndex]
let timePeriod = timePeriodArray[currentTimePeriod.timePeriodIndex][1]
let timePeriodDailyArray = []
let timePeriodMarketArray = []
switch (currentTimePeriod.filePeriodIndex) {
case 0: {
timePeriodMarketArray.push(timePeriod)
break
}
case 1: {
timePeriodDailyArray.push(timePeriod)
break
}
}
let simulationParams = {
beginDatetime: 1554087600,
resumeExecution: true,
timePeriodDailyArray: ['05-min', '10-min'],
timePeriodMarketArray: ['01-hs', '02-hs']
beginDatetime: dateAtScreenCorner.valueOf() / 1000 | 0,
resumeExecution: false,
timePeriodDailyArray: timePeriodDailyArray,
timePeriodMarketArray: timePeriodMarketArray
}
let result = await graphQlRestartSimulation(simulationParams)
@@ -136,3 +157,4 @@ function newRestartSimulation () {
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y)
}
}
+7 -2
View File
@@ -2,11 +2,12 @@ function newRateScale () {
const MODULE_NAME = 'Right Scale'
let thisObject = {
heightPercentage: 100,
container: undefined,
physics: physics,
draw: draw,
getContainer: getContainer,
initialize: initialize,
heightPercentage: 100
initialize: initialize
}
const HEIGHT_PERCENTAGE_DEFAULT_VALUE = 50
@@ -101,6 +102,10 @@ function newRateScale () {
}
}
function physics () {
}
function draw () {
if (visible === false) { return }
+1
View File
@@ -292,6 +292,7 @@ to be visible at the top of the viewPort. */
let event = {}
event.timePeriod = thisObject.timePeriod
thisObject.container.eventHandler.raiseEvent('Time Period Changed', event)
window.localStorage.setItem('Current Time Period', JSON.stringify({filePeriodIndex: filePeriodIndex, timePeriodIndex: timePeriodIndex}))
}
}
+15 -2
View File
@@ -2,11 +2,12 @@ function newTimeScale () {
const MODULE_NAME = 'Time Scale'
let thisObject = {
lenghtPercentage: undefined,
container: undefined,
physics: physics,
draw: draw,
getContainer: getContainer,
initialize: initialize,
lenghtPercentage: undefined
initialize: initialize
}
const LENGHT_PERCENTAGE_DEFAULT_VALUE = 5
@@ -96,6 +97,17 @@ function newTimeScale () {
}
}
function physics () {
let point = {
x: 0,
y: 0
}
let date = getDateFromPoint(point, thisObject.container.parentContainer, timeLineCoordinateSystem)
date = new Date(date)
window.localStorage.setItem('Date @ Screen Corner', date.toUTCString())
}
function draw () {
if (visible === false) { return }
@@ -206,3 +218,4 @@ to be visible at the top of the viewPort. */
browserCanvasContext.stroke()
}
}
+12
View File
@@ -149,6 +149,11 @@ function newChartSpace () {
}
function physics () {
thisObjectPhysics()
childrenPhysics()
}
function thisObjectPhysics () {
thisObject.container.frame.height = COCKPIT_SPACE_POSITION
if (thisObject.container.frame.height <= 0 / 100) {
@@ -160,6 +165,13 @@ function newChartSpace () {
viewPort.resize()
}
function childrenPhysics () {
for (let i = 0; i < thisObject.timeMachines.length; i++) {
let timeMachine = thisObject.timeMachines[i]
timeMachine.physics()
}
}
function drawBackground () {
if (thisObject.visible !== true) { return }