diff options
| -rw-r--r-- | src/scripts/controllers/connection/api.ts | 62 | ||||
| -rw-r--r-- | src/scripts/controllers/mapcontroller.ts | 2 | ||||
| -rw-r--r-- | src/scripts/controllers/simulation/statecache.ts | 180 | ||||
| -rw-r--r-- | src/scripts/controllers/simulationcontroller.ts | 2 |
4 files changed, 189 insertions, 57 deletions
diff --git a/src/scripts/controllers/connection/api.ts b/src/scripts/controllers/connection/api.ts index 067e3ca0..c4eebf64 100644 --- a/src/scripts/controllers/connection/api.ts +++ b/src/scripts/controllers/connection/api.ts @@ -1067,8 +1067,15 @@ export class APIController { /// // METHOD: GET - public getMachineStatesByTick(simulationId: number, experimentId: number, tick: number, - machines: {[keys: number]: IMachine}): Promise<IMachineState[]> { + public getMachineStates(simulationId: number, experimentId: number, machines: {[keys: number]: IMachine}, + tick?: number): Promise<IMachineState[]> { + let query; + if (tick !== undefined) { + query = {tick}; + } else { + query = {}; + } + return ServerConnection.send({ path: "/simulations/{simulationId}/experiments/{experimentId}/machine-states", method: "GET", @@ -1078,9 +1085,7 @@ export class APIController { simulationId, experimentId }, - query: { - tick - } + query } }).then((data: any) => { data.forEach((item: any) => { @@ -1096,8 +1101,15 @@ export class APIController { /// // METHOD: GET - public getRackStatesByTick(simulationId: number, experimentId: number, tick: number, - racks: {[keys: number]: IRack}): Promise<IRackState[]> { + public getRackStates(simulationId: number, experimentId: number, racks: {[keys: number]: IRack}, + tick?: number): Promise<IRackState[]> { + let query; + if (tick !== undefined) { + query = {tick}; + } else { + query = {}; + } + return ServerConnection.send({ path: "/simulations/{simulationId}/experiments/{experimentId}/rack-states", method: "GET", @@ -1107,9 +1119,7 @@ export class APIController { simulationId, experimentId }, - query: { - tick - } + query: query } }).then((data: any) => { let promises = data.map((item: any) => { @@ -1127,8 +1137,15 @@ export class APIController { /// // METHOD: GET - public getRoomStatesByTick(simulationId: number, experimentId: number, tick: number, - rooms: {[keys: number]: IRoom}): Promise<IRoomState[]> { + public getRoomStates(simulationId: number, experimentId: number, rooms: {[keys: number]: IRoom}, + tick?: number): Promise<IRoomState[]> { + let query; + if (tick !== undefined) { + query = {tick}; + } else { + query = {}; + } + return ServerConnection.send({ path: "/simulations/{simulationId}/experiments/{experimentId}/room-states", method: "GET", @@ -1138,9 +1155,7 @@ export class APIController { simulationId, experimentId }, - query: { - tick - } + query } }).then((data: any) => { let promises = data.map((item: any) => { @@ -1158,8 +1173,15 @@ export class APIController { /// // METHOD: GET - public getTaskStatesByTick(simulationId: number, experimentId: number, tick: number, - tasks: {[keys: number]: ITask}): Promise<ITaskState[]> { + public getTaskStates(simulationId: number, experimentId: number, tasks: {[keys: number]: ITask}, + tick?: number): Promise<ITaskState[]> { + let query; + if (tick === undefined) { + query = {tick}; + } else { + query = {}; + } + return ServerConnection.send({ path: "/simulations/{simulationId}/experiments/{experimentId}/task-states", method: "GET", @@ -1169,9 +1191,7 @@ export class APIController { simulationId, experimentId }, - query: { - tick - } + query } }).then((data: any) => { let promises = data.map((item: any) => { @@ -1721,4 +1741,4 @@ export class APIController { return machine; }); } -}
\ No newline at end of file +} diff --git a/src/scripts/controllers/mapcontroller.ts b/src/scripts/controllers/mapcontroller.ts index d7458852..ca55683b 100644 --- a/src/scripts/controllers/mapcontroller.ts +++ b/src/scripts/controllers/mapcontroller.ts @@ -12,7 +12,7 @@ import {ObjectModeController} from "./modes/object"; import {NodeModeController} from "./modes/node"; import {ScaleIndicatorController} from "./scaleindicator"; -export var CELL_SIZE = 50; +export const CELL_SIZE = 50; export enum AppMode { diff --git a/src/scripts/controllers/simulation/statecache.ts b/src/scripts/controllers/simulation/statecache.ts index 32f8f4e4..6d34dc03 100644 --- a/src/scripts/controllers/simulation/statecache.ts +++ b/src/scripts/controllers/simulation/statecache.ts @@ -2,7 +2,7 @@ import {SimulationController} from "../simulationcontroller"; export class StateCache { - public static CACHE_INTERVAL = 3000; + public static CACHE_INTERVAL = 10000; private static PREFERRED_CACHE_ADVANCE = 5; public stateList: {[key: number]: ITickState}; @@ -22,7 +22,7 @@ export class StateCache { constructor(simulationController: SimulationController) { this.stateList = {}; - this.lastCachedTick = -1; + this.lastCachedTick = 0; this.cacheBlock = true; this.simulationController = simulationController; this.caching = false; @@ -81,16 +81,22 @@ export class StateCache { return; } - this.fetchAllStatesOfTick(tick).then((data: ITickState) => { - this.stateList[tick] = data; + this.fetchAllAvailableStates().then((data) => { + this.stateList = data; this.updateTasks(tick); + // Determine last cached tick + let ticks = Object.keys(this.stateList).sort((a, b) => { + return parseInt(a) - parseInt(b); + }); + if (ticks.length > 0) { + this.lastCachedTick = parseInt(ticks[ticks.length - 1]); + } + // Update chart cache this.simulationController.chartController.tickUpdated(tick); - this.lastCachedTick++; - if (!this.cacheBlock && this.lastCachedTick - this.simulationController.currentTick <= 0) { this.cacheBlock = true; return; @@ -160,6 +166,106 @@ export class StateCache { }); } + private fetchAllAvailableStates(): Promise<{[key: number]: ITickState}> { + let machineStates, rackStates, roomStates, taskStates; + const promises = []; + + promises.push( + this.simulationController.mapController.api.getMachineStates( + this.simulationController.mapView.simulation.id, this.simulationController.currentExperiment.id, + this.machineCache + ).then((states: IMachineState[]) => { + machineStates = states; + }) + ); + + promises.push( + this.simulationController.mapController.api.getRackStates( + this.simulationController.mapView.simulation.id, this.simulationController.currentExperiment.id, + this.rackCache + ).then((states: IRackState[]) => { + rackStates = states; + }) + ); + + promises.push( + this.simulationController.mapController.api.getRoomStates( + this.simulationController.mapView.simulation.id, this.simulationController.currentExperiment.id, + this.roomCache + ).then((states: IRoomState[]) => { + roomStates = states; + }) + ); + + promises.push( + this.simulationController.mapController.api.getTaskStates( + this.simulationController.mapView.simulation.id, this.simulationController.currentExperiment.id, + this.taskCache + ).then((states: ITaskState[]) => { + taskStates = states; + }) + ); + + return Promise.all(promises).then(() => { + let tickStates: {[key: number]: ITickState} = {}; + + machineStates.forEach((machineState: IMachineState) => { + if (tickStates[machineState.tick] === undefined) { + tickStates[machineState.tick] = { + tick: machineState.tick, + machineStates: [machineState], + rackStates: [], + roomStates: [], + taskStates: [] + }; + } else { + tickStates[machineState.tick].machineStates.push(machineState); + } + }); + rackStates.forEach((rackState: IRackState) => { + if (tickStates[rackState.tick] === undefined) { + tickStates[rackState.tick] = { + tick: rackState.tick, + machineStates: [], + rackStates: [rackState], + roomStates: [], + taskStates: [] + }; + } else { + tickStates[rackState.tick].rackStates.push(rackState); + } + }); + roomStates.forEach((roomState: IRoomState) => { + if (tickStates[roomState.tick] === undefined) { + tickStates[roomState.tick] = { + tick: roomState.tick, + machineStates: [], + rackStates: [], + roomStates: [roomState], + taskStates: [] + }; + } else { + tickStates[roomState.tick].roomStates.push(roomState); + } + }); + taskStates.forEach((taskState: ITaskState) => { + if (tickStates[taskState.tick] === undefined) { + tickStates[taskState.tick] = { + tick: taskState.tick, + machineStates: [], + rackStates: [], + roomStates: [], + taskStates: [taskState] + }; + } else { + tickStates[taskState.tick].taskStates.push(taskState); + } + }); + + return tickStates; + }); + } + private fetchAllStatesOfTick(tick: number): Promise<ITickState> { let tickState: ITickState = { tick, @@ -170,33 +276,41 @@ export class StateCache { }; const promises = []; - promises.push(this.simulationController.mapController.api.getMachineStatesByTick( - this.simulationController.mapView.simulation.id, this.simulationController.currentExperiment.id, - tick, this.machineCache - ).then((states: IMachineState[]) => { - tickState.machineStates = states; - })); - - promises.push(this.simulationController.mapController.api.getRackStatesByTick( - this.simulationController.mapView.simulation.id, this.simulationController.currentExperiment.id, - tick, this.rackCache - ).then((states: IRackState[]) => { - tickState.rackStates = states; - })); - - promises.push(this.simulationController.mapController.api.getRoomStatesByTick( - this.simulationController.mapView.simulation.id, this.simulationController.currentExperiment.id, - tick, this.roomCache - ).then((states: IRoomState[]) => { - tickState.roomStates = states; - })); - - promises.push(this.simulationController.mapController.api.getTaskStatesByTick( - this.simulationController.mapView.simulation.id, this.simulationController.currentExperiment.id, - tick, this.taskCache - ).then((states: ITaskState[]) => { - tickState.taskStates = states; - })); + promises.push( + this.simulationController.mapController.api.getMachineStates( + this.simulationController.mapView.simulation.id, this.simulationController.currentExperiment.id, + this.machineCache, tick + ).then((states: IMachineState[]) => { + tickState.machineStates = states; + }) + ); + + promises.push( + this.simulationController.mapController.api.getRackStates( + this.simulationController.mapView.simulation.id, this.simulationController.currentExperiment.id, + this.rackCache, tick + ).then((states: IRackState[]) => { + tickState.rackStates = states; + }) + ); + + promises.push( + this.simulationController.mapController.api.getRoomStates( + this.simulationController.mapView.simulation.id, this.simulationController.currentExperiment.id, + this.roomCache, tick + ).then((states: IRoomState[]) => { + tickState.roomStates = states; + }) + ); + + promises.push( + this.simulationController.mapController.api.getTaskStates( + this.simulationController.mapView.simulation.id, this.simulationController.currentExperiment.id, + this.taskCache, tick + ).then((states: ITaskState[]) => { + tickState.taskStates = states; + }) + ); return Promise.all(promises).then(() => { return tickState; diff --git a/src/scripts/controllers/simulationcontroller.ts b/src/scripts/controllers/simulationcontroller.ts index 418b5437..baab21bf 100644 --- a/src/scripts/controllers/simulationcontroller.ts +++ b/src/scripts/controllers/simulationcontroller.ts @@ -504,8 +504,6 @@ export class SimulationController { return; } - console.log(this.stateCache); - let html; let container = $(".building-stats-list"); |
