summaryrefslogtreecommitdiff
path: root/src/reducers
diff options
context:
space:
mode:
authorGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-09-17 17:55:04 +0200
committerGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-09-23 10:06:03 +0200
commiteb208a7e2fd020ab5d07d11cc6d52d1e3dcfcc7c (patch)
treed2ec8a20408b7b2880e62feaa70fe95a78c484dd /src/reducers
parent326b74fc39f63f47c71359276601ea93f7345dc6 (diff)
Add simulation mode framework
Includes object states in the store (by tick), charting, and progress bars.
Diffstat (limited to 'src/reducers')
-rw-r--r--src/reducers/construction-mode.js (renamed from src/reducers/construction.js)0
-rw-r--r--src/reducers/current-ids.js (renamed from src/reducers/topology.js)11
-rw-r--r--src/reducers/index.js18
-rw-r--r--src/reducers/simulation-mode.js50
-rw-r--r--src/reducers/simulations.js10
-rw-r--r--src/reducers/states.js33
6 files changed, 106 insertions, 16 deletions
diff --git a/src/reducers/construction.js b/src/reducers/construction-mode.js
index 3e0b7542..3e0b7542 100644
--- a/src/reducers/construction.js
+++ b/src/reducers/construction-mode.js
diff --git a/src/reducers/topology.js b/src/reducers/current-ids.js
index f98b50e7..c94d7861 100644
--- a/src/reducers/topology.js
+++ b/src/reducers/current-ids.js
@@ -1,3 +1,4 @@
+import {OPEN_SIMULATION_SUCCEEDED} from "../actions/simulations";
import {FETCH_LATEST_DATACENTER_SUCCEEDED, RESET_CURRENT_DATACENTER} from "../actions/topology/building";
export function currentDatacenterId(state = -1, action) {
@@ -10,3 +11,13 @@ export function currentDatacenterId(state = -1, action) {
return state;
}
}
+
+export function currentSimulationId(state = -1, action) {
+ switch (action.type) {
+ case OPEN_SIMULATION_SUCCEEDED:
+ return action.id;
+ default:
+ return state;
+ }
+}
+
diff --git a/src/reducers/index.js b/src/reducers/index.js
index 1f3aa8f2..a9b6bf34 100644
--- a/src/reducers/index.js
+++ b/src/reducers/index.js
@@ -1,24 +1,30 @@
import {combineReducers} from "redux";
import {auth} from "./auth";
-import {construction} from "./construction";
+import {construction} from "./construction-mode";
+import {currentDatacenterId, currentSimulationId} from "./current-ids";
import {interactionLevel} from "./interaction-level";
import {map} from "./map";
import {modals} from "./modals";
import {objects} from "./objects";
import {simulationList} from "./simulation-list";
-import {currentSimulationId} from "./simulations";
-import {currentDatacenterId} from "./topology";
+import {currentExperimentId, currentTick, isPlaying, loadMetric} from "./simulation-mode";
+import {states} from "./states";
const rootReducer = combineReducers({
- auth,
objects,
+ states,
modals,
simulationList,
+ construction,
+ map,
currentSimulationId,
currentDatacenterId,
+ currentExperimentId,
+ currentTick,
+ loadMetric,
+ isPlaying,
interactionLevel,
- construction,
- map,
+ auth,
});
export default rootReducer;
diff --git a/src/reducers/simulation-mode.js b/src/reducers/simulation-mode.js
new file mode 100644
index 00000000..da6aa94a
--- /dev/null
+++ b/src/reducers/simulation-mode.js
@@ -0,0 +1,50 @@
+import {OPEN_EXPERIMENT_SUCCEEDED} from "../actions/experiments";
+import {CHANGE_LOAD_METRIC} from "../actions/simulation/load-metric";
+import {SET_PLAYING} from "../actions/simulation/playback";
+import {GO_TO_TICK, SET_LAST_SIMULATED_TICK} from "../actions/simulation/tick";
+
+export function currentExperimentId(state = -1, action) {
+ switch (action.type) {
+ case OPEN_EXPERIMENT_SUCCEEDED:
+ return action.id;
+ default:
+ return state;
+ }
+}
+
+export function currentTick(state = 0, action) {
+ switch (action.type) {
+ case GO_TO_TICK:
+ return action.tick;
+ default:
+ return state;
+ }
+}
+
+export function loadMetric(state = "LOAD", action) {
+ switch (action.type) {
+ case CHANGE_LOAD_METRIC:
+ return action.metric;
+ default:
+ return state;
+ }
+}
+
+export function isPlaying(state = false, action) {
+ switch (action.type) {
+ case SET_PLAYING:
+ return action.playing;
+ default:
+ return state;
+ }
+}
+
+export function lastSimulatedTick(state = -1, action) {
+ switch (action.type) {
+ case SET_LAST_SIMULATED_TICK:
+ return action.tick;
+ default:
+ return state;
+ }
+}
+
diff --git a/src/reducers/simulations.js b/src/reducers/simulations.js
deleted file mode 100644
index e15c2d21..00000000
--- a/src/reducers/simulations.js
+++ /dev/null
@@ -1,10 +0,0 @@
-import {OPEN_SIMULATION_SUCCEEDED} from "../actions/simulations";
-
-export function currentSimulationId(state = -1, action) {
- switch (action.type) {
- case OPEN_SIMULATION_SUCCEEDED:
- return action.id;
- default:
- return state;
- }
-}
diff --git a/src/reducers/states.js b/src/reducers/states.js
new file mode 100644
index 00000000..a9eb4ce8
--- /dev/null
+++ b/src/reducers/states.js
@@ -0,0 +1,33 @@
+import {combineReducers} from "redux";
+import {ADD_TO_STATES} from "../actions/states";
+
+export const states = combineReducers({
+ task: objectStates("task"),
+ room: objectStates("room"),
+ rack: objectStates("rack"),
+ machine: objectStates("machine"),
+});
+
+function objectStates(type) {
+ return (state = {}, action) => {
+ if (action.objectType !== type) {
+ return state;
+ }
+
+ if (action.type === ADD_TO_STATES) {
+ return Object.assign(
+ {},
+ state,
+ {
+ [action.tick]: Object.assign(
+ {},
+ state[action.tick],
+ {[action.object.id]: action.object}
+ )
+ }
+ );
+ }
+
+ return state;
+ };
+}