From eb208a7e2fd020ab5d07d11cc6d52d1e3dcfcc7c Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Sun, 17 Sep 2017 17:55:04 +0200 Subject: Add simulation mode framework Includes object states in the store (by tick), charting, and progress bars. --- src/reducers/construction-mode.js | 35 +++++++++++++++++++++++++++ src/reducers/construction.js | 35 --------------------------- src/reducers/current-ids.js | 23 ++++++++++++++++++ src/reducers/index.js | 18 +++++++++----- src/reducers/simulation-mode.js | 50 +++++++++++++++++++++++++++++++++++++++ src/reducers/simulations.js | 10 -------- src/reducers/states.js | 33 ++++++++++++++++++++++++++ src/reducers/topology.js | 12 ---------- 8 files changed, 153 insertions(+), 63 deletions(-) create mode 100644 src/reducers/construction-mode.js delete mode 100644 src/reducers/construction.js create mode 100644 src/reducers/current-ids.js create mode 100644 src/reducers/simulation-mode.js delete mode 100644 src/reducers/simulations.js create mode 100644 src/reducers/states.js delete mode 100644 src/reducers/topology.js (limited to 'src/reducers') diff --git a/src/reducers/construction-mode.js b/src/reducers/construction-mode.js new file mode 100644 index 00000000..3e0b7542 --- /dev/null +++ b/src/reducers/construction-mode.js @@ -0,0 +1,35 @@ +import {combineReducers} from "redux"; +import { + CANCEL_NEW_ROOM_CONSTRUCTION_SUCCEEDED, + FINISH_NEW_ROOM_CONSTRUCTION, + START_NEW_ROOM_CONSTRUCTION_SUCCEEDED +} from "../actions/topology/building"; +import {START_RACK_CONSTRUCTION, STOP_RACK_CONSTRUCTION} from "../actions/topology/room"; + +export function currentRoomInConstruction(state = -1, action) { + switch (action.type) { + case START_NEW_ROOM_CONSTRUCTION_SUCCEEDED: + return action.roomId; + case CANCEL_NEW_ROOM_CONSTRUCTION_SUCCEEDED: + case FINISH_NEW_ROOM_CONSTRUCTION: + return -1; + default: + return state; + } +} + +export function inRackConstructionMode(state = false, action) { + switch (action.type) { + case START_RACK_CONSTRUCTION: + return true; + case STOP_RACK_CONSTRUCTION: + return false; + default: + return state; + } +} + +export const construction = combineReducers({ + currentRoomInConstruction, + inRackConstructionMode, +}); diff --git a/src/reducers/construction.js b/src/reducers/construction.js deleted file mode 100644 index 3e0b7542..00000000 --- a/src/reducers/construction.js +++ /dev/null @@ -1,35 +0,0 @@ -import {combineReducers} from "redux"; -import { - CANCEL_NEW_ROOM_CONSTRUCTION_SUCCEEDED, - FINISH_NEW_ROOM_CONSTRUCTION, - START_NEW_ROOM_CONSTRUCTION_SUCCEEDED -} from "../actions/topology/building"; -import {START_RACK_CONSTRUCTION, STOP_RACK_CONSTRUCTION} from "../actions/topology/room"; - -export function currentRoomInConstruction(state = -1, action) { - switch (action.type) { - case START_NEW_ROOM_CONSTRUCTION_SUCCEEDED: - return action.roomId; - case CANCEL_NEW_ROOM_CONSTRUCTION_SUCCEEDED: - case FINISH_NEW_ROOM_CONSTRUCTION: - return -1; - default: - return state; - } -} - -export function inRackConstructionMode(state = false, action) { - switch (action.type) { - case START_RACK_CONSTRUCTION: - return true; - case STOP_RACK_CONSTRUCTION: - return false; - default: - return state; - } -} - -export const construction = combineReducers({ - currentRoomInConstruction, - inRackConstructionMode, -}); diff --git a/src/reducers/current-ids.js b/src/reducers/current-ids.js new file mode 100644 index 00000000..c94d7861 --- /dev/null +++ b/src/reducers/current-ids.js @@ -0,0 +1,23 @@ +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) { + switch (action.type) { + case FETCH_LATEST_DATACENTER_SUCCEEDED: + return action.datacenterId; + case RESET_CURRENT_DATACENTER: + return -1; + default: + 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; + }; +} diff --git a/src/reducers/topology.js b/src/reducers/topology.js deleted file mode 100644 index f98b50e7..00000000 --- a/src/reducers/topology.js +++ /dev/null @@ -1,12 +0,0 @@ -import {FETCH_LATEST_DATACENTER_SUCCEEDED, RESET_CURRENT_DATACENTER} from "../actions/topology/building"; - -export function currentDatacenterId(state = -1, action) { - switch (action.type) { - case FETCH_LATEST_DATACENTER_SUCCEEDED: - return action.datacenterId; - case RESET_CURRENT_DATACENTER: - return -1; - default: - return state; - } -} -- cgit v1.2.3