summaryrefslogtreecommitdiff
path: root/src/scripts/controllers/simulation
diff options
context:
space:
mode:
authorGeorgios Andreadis <G.Andreadis@student.tudelft.nl>2017-01-27 10:26:54 +0100
committerGitHub <noreply@github.com>2017-01-27 10:26:54 +0100
commit50fcb0634c9ebe894988103184d50d372bc76907 (patch)
tree5af172c03599f7c680cd32205eab5329b841c85c /src/scripts/controllers/simulation
parent3ad08353d289720cf8f43e1dba078da43c35e97d (diff)
parentb462c9183ec7c2e41f14daad49f03d8afaa4ec59 (diff)
Merge pull request #4 from tudelft-atlarge/states-batch-fetch
Fetch experiment states in one batch
Diffstat (limited to 'src/scripts/controllers/simulation')
-rw-r--r--src/scripts/controllers/simulation/chart.ts12
-rw-r--r--src/scripts/controllers/simulation/statecache.ts192
-rw-r--r--src/scripts/controllers/simulation/timeline.ts14
3 files changed, 167 insertions, 51 deletions
diff --git a/src/scripts/controllers/simulation/chart.ts b/src/scripts/controllers/simulation/chart.ts
index 84009622..5f94f412 100644
--- a/src/scripts/controllers/simulation/chart.ts
+++ b/src/scripts/controllers/simulation/chart.ts
@@ -52,7 +52,7 @@ export class ChartController {
room.tiles.forEach((tile: ITile) => {
if (tile.object !== undefined && tile.objectType === "RACK" && this.rackSeries[tile.objectId] === undefined) {
- let objectName = (<IRack>tile.object).name;
+ const objectName = (<IRack>tile.object).name;
this.names["ra" + tile.objectId] = objectName === "" || objectName === undefined ?
"Unnamed rack" : objectName;
@@ -177,7 +177,7 @@ export class ChartController {
machineId = this.mapController.nodeModeController.currentMachine.id;
}
- let unloads: string[] = [];
+ const unloads: string[] = [];
for (let id in this.names) {
if (this.names.hasOwnProperty(id)) {
if (machineId === -1) {
@@ -211,17 +211,17 @@ export class ChartController {
}
public tickUpdated(tick: number): void {
- let roomStates: IRoomState[] = this.simulationController.stateCache.stateList[tick].roomStates;
+ const roomStates: IRoomState[] = this.simulationController.stateCache.stateList[tick].roomStates;
roomStates.forEach((roomState: IRoomState) => {
ChartController.insertAtIndex(this.roomSeries[roomState.roomId].loadFractions, tick + 1, roomState.loadFraction);
});
- let rackStates: IRackState[] = this.simulationController.stateCache.stateList[tick].rackStates;
+ const rackStates: IRackState[] = this.simulationController.stateCache.stateList[tick].rackStates;
rackStates.forEach((rackState: IRackState) => {
ChartController.insertAtIndex(this.rackSeries[rackState.rackId].loadFractions, tick + 1, rackState.loadFraction);
});
- let machineStates: IMachineState[] = this.simulationController.stateCache.stateList[tick].machineStates;
+ const machineStates: IMachineState[] = this.simulationController.stateCache.stateList[tick].machineStates;
machineStates.forEach((machineState: IMachineState) => {
ChartController.insertAtIndex(this.machineSeries[machineState.machineId].loadFractions, tick + 1, machineState.loadFraction);
});
@@ -238,4 +238,4 @@ export class ChartController {
list[index] = data;
}
-} \ No newline at end of file
+}
diff --git a/src/scripts/controllers/simulation/statecache.ts b/src/scripts/controllers/simulation/statecache.ts
index 32f8f4e4..092bfe32 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;
@@ -73,7 +73,7 @@ export class StateCache {
}
private cache(): void {
- let tick = this.lastCachedTick + 1;
+ const tick = this.lastCachedTick + 1;
this.updateLastTick().then(() => {
// Check if end of simulated region has been reached
@@ -81,15 +81,23 @@ 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
+ const 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);
+ for (let i = 1; i <= this.lastCachedTick; i++) {
+ this.updateTasksForNewTick(i);
- this.lastCachedTick++;
+ // Update chart cache
+ this.simulationController.chartController.tickUpdated(i);
+ }
if (!this.cacheBlock && this.lastCachedTick - this.simulationController.currentTick <= 0) {
this.cacheBlock = true;
@@ -105,7 +113,7 @@ export class StateCache {
});
}
- private updateTasks(tick: number): void {
+ private updateTasksForNewTick(tick: number): void {
const taskIDsInTick = [];
this.stateList[tick].taskStates.forEach((taskState: ITaskState) => {
@@ -160,8 +168,108 @@ 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(() => {
+ const 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 = {
+ const tickState: ITickState = {
tick,
machineStates: [],
rackStates: [],
@@ -170,33 +278,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/simulation/timeline.ts b/src/scripts/controllers/simulation/timeline.ts
index a558afe1..ec3d8cb4 100644
--- a/src/scripts/controllers/simulation/timeline.ts
+++ b/src/scripts/controllers/simulation/timeline.ts
@@ -45,8 +45,8 @@ export class TimelineController {
});
$(".timeline-container .timeline").on("click", (event: JQueryEventObject) => {
- let parentOffset = $(event.target).closest(".timeline").offset();
- let clickX = event.pageX - parentOffset.left;
+ const parentOffset = $(event.target).closest(".timeline").offset();
+ const clickX = event.pageX - parentOffset.left;
let newTick = Math.round(clickX / (this.timelineWidth * this.timeUnitFraction));
@@ -111,7 +111,7 @@ export class TimelineController {
private updateTaskIndicators(): void {
$(".task-indicator").remove();
- let tickStateTypes = {
+ const tickStateTypes = {
"queueEntryTick": "task-queued",
"startTick": "task-started",
"finishedTick": "task-finished"
@@ -121,7 +121,7 @@ export class TimelineController {
return;
}
- let indicatorCountList = new Array(this.simulationController.stateCache.lastCachedTick);
+ const indicatorCountList = new Array(this.simulationController.stateCache.lastCachedTick);
let indicator;
this.simulationController.currentExperiment.trace.tasks.forEach((task: ITask) => {
for (let tickStateType in tickStateTypes) {
@@ -153,9 +153,9 @@ export class TimelineController {
let correction = 0;
if (this.timeUnitFraction * this.timelineWidth > this.timeMarkerWidth) {
correction = (this.timeUnitFraction * this.timelineWidth - this.timeMarkerWidth) *
- (tick / this.simulationController.lastSimulatedTick);
+ ((tick - 1) / this.simulationController.lastSimulatedTick);
}
- return (100 * (this.timeUnitFraction * tick + correction / this.timelineWidth)) + "%";
+ return (100 * (this.timeUnitFraction * (tick - 1) + correction / this.timelineWidth)) + "%";
}
-} \ No newline at end of file
+}