swimtracker-app/state/Reducer.js

71 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-06-02 17:19:09 +02:00
import { combineReducers } from 'redux';
import { List } from 'immutable';
import { CHANGE_THEME, CHANGE_USER_NAME, NEW_DEVICE_DATA, START_SESSION } from './ActionCreators';
const INITIAL_SETTINGS = {
theme: "hot",
username: "",
deviceURL: "192.168.178.105",
peaksPerLap: 30,
// advanced
peakDetector: 'SIMPLE', // either 'SIMPLE' or 'ZSCORE'
peakDetectorSimpleThreshold: 500,
peakDetectorZScoreLag: 8, // peak detector z-score values
peakDetectorZScoreThreshold: 2,
peakDetectorZScoreInfluence: 0.1,
};
const INITIAL_CURRENT_SESSION = {
running: false,
rawData: List(),
analysis: {
'peaks': List(),
'totalTime': null,
'activeTime': null,
'totalMomentum': null,
'peakFrequency': null,
'peakMax': null,
// windowed quantities
'momentumWindow': null,
'frequencyWindow': null,
'peakMaxWindow': null,
}
};
const settingsReducer = (state = INITIAL_SETTINGS, action) => {
switch (action.type) {
case CHANGE_THEME:
return { ...state, theme: action.newThemeName };
case CHANGE_USER_NAME:
return { ...state, username: action.newUsername };
default:
return state
}
};
const currentSessionReducer = (state = INITIAL_CURRENT_SESSION, action) => {
switch (action.type) {
case START_SESSION:
return {
running: true,
rawData: List(),
analysis: INITIAL_CURRENT_SESSION.analysis
};
case NEW_DEVICE_DATA:
return {
running: action.data.length > 0,
rawData: action.data,
analysis: { ...state.analysis, ...analysis },
}
default:
return state
}
};
export default combineReducers({
settings: settingsReducer,
session: currentSessionReducer,
});