|
@@ -5,8 +5,16 @@ const initialState = Immutable.Map({
|
|
|
// Keep enough points for 24hrs at 30s resolution
|
|
|
maxPoints: 24 * 60 * 2,
|
|
|
// List of points for time series charts
|
|
|
- ram: Immutable.List(),
|
|
|
- nClients: Immutable.List()
|
|
|
+ ram: Immutable.Map({
|
|
|
+ data: Immutable.List(),
|
|
|
+ min: Infinity,
|
|
|
+ max: -Infinity
|
|
|
+ }),
|
|
|
+ nClients: Immutable.Map({
|
|
|
+ data: Immutable.List(),
|
|
|
+ min: Infinity,
|
|
|
+ max: -Infinity
|
|
|
+ })
|
|
|
});
|
|
|
|
|
|
const reducer = (state = initialState, {type, payload}) => {
|
|
@@ -17,16 +25,24 @@ const reducer = (state = initialState, {type, payload}) => {
|
|
|
// of last N points, up to `maxPoints`
|
|
|
// payload = {ram: [{x, y}], nClients: [{x, y}]}
|
|
|
case ActionTypes.INIT:
|
|
|
- newState = state
|
|
|
- .set('ram', state.get('ram')
|
|
|
+ payload.ram.forEach(p => {
|
|
|
+ if (p.y < state.getIn(['ram', 'min'])) {
|
|
|
+ newState = newState.setIn(['ram', 'min'], p.y);
|
|
|
+ }
|
|
|
+ if (p.y > state.getIn(['ram', 'max'])) {
|
|
|
+ newState = newState.setIn(['ram', 'max'], p.y);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ newState = newState
|
|
|
+ .setIn(['ram', 'data'], state.getIn(['ram', 'data'])
|
|
|
.push(...payload.ram))
|
|
|
- .set('nClients', state.get('nClients')
|
|
|
+ .setIn(['nClients', 'data'], state.getIn(['nClients', 'data'])
|
|
|
.push(...payload.nClients));
|
|
|
- if (newState.get('ram').count() > state.get('maxPoints')) {
|
|
|
+ if (newState.getIn(['ram', 'data']).count() > state.get('maxPoints')) {
|
|
|
newState = newState
|
|
|
- .set('ram', state.get('ram')
|
|
|
+ .setIn(['ram', 'data'], state.getIn(['ram', 'data'])
|
|
|
.shift())
|
|
|
- .set('nClients', state.get('nClients')
|
|
|
+ .setIn(['nClients', 'data'], state.getIn(['nClients', 'data'])
|
|
|
.shift());
|
|
|
}
|
|
|
return newState;
|
|
@@ -35,16 +51,22 @@ const reducer = (state = initialState, {type, payload}) => {
|
|
|
// chart. Removes oldest point if necessary to make space.
|
|
|
// payload = {ram: {x, y}, nClients: {x, y}}
|
|
|
case ActionTypes.TICK:
|
|
|
+ if (payload.ram.y < state.getIn(['ram', 'min'])) {
|
|
|
+ newState = newState.setIn(['ram', 'min'], payload.ram.y);
|
|
|
+ }
|
|
|
+ if (payload.ram.y > state.getIn(['ram', 'max'])) {
|
|
|
+ newState = newState.setIn(['ram', 'max'], payload.ram.y);
|
|
|
+ }
|
|
|
newState = state
|
|
|
- .set('ram', state.get('ram')
|
|
|
+ .setIn(['ram', 'data'], state.getIn(['ram', 'data'])
|
|
|
.push(payload.ram))
|
|
|
- .set('nClients', state.get('nClients')
|
|
|
+ .setIn(['nClients', 'data'], state.getIn(['nClients', 'data'])
|
|
|
.push(payload.nClients));
|
|
|
- if (newState.get('ram').count() > state.get('maxPoints')) {
|
|
|
+ if (newState.getIn(['ram', 'data']).count() > state.get('maxPoints')) {
|
|
|
newState = newState
|
|
|
- .set('ram', state.get('ram')
|
|
|
+ .setIn(['ram', 'data'], state.getIn(['ram', 'data'])
|
|
|
.shift())
|
|
|
- .set('nClients', state.get('nClients')
|
|
|
+ .setIn(['nClients', 'data'], state.getIn(['nClients', 'data'])
|
|
|
.shift());
|
|
|
}
|
|
|
return newState;
|