swimtracker-app/state/Reducer.js

66 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-06-02 17:19:09 +02:00
import { combineReducers } from 'redux';
import { deviceStateReducer } from "./DeviceReduxCoupling";
2020-06-02 17:19:09 +02:00
2020-06-28 22:10:54 +02:00
export const CHANGE_USER_NAME = "SET_USERNAME";
export const CHANGE_THEME = "CHANGE_THEME";
export const RESET_DEVICE_DATA = "RESET_DEVICE_DATA";
export const changeUsername = newUsername => ({
type: CHANGE_USER_NAME,
newUserName: newUsername,
});
export const changeTheme = newThemeName => ({
type: CHANGE_THEME,
newThemeName: newThemeName
});
export const startSession = () => ({
type: START_SESSION
});
export const stopSession = () => ({
type: STOP_SESSION
});
2020-06-02 17:19:09 +02:00
const INITIAL_SETTINGS = {
theme: "hot",
username: "",
swimTrackerHost: "192.168.178.110",
2020-06-02 17:19:09 +02:00
analysis: {
2020-07-15 15:53:16 +02:00
peaksPerLap: 30,
windowSizeInSecs: 5,
numMeasurementsPerSec: 10,
2020-06-02 17:19:09 +02:00
2020-07-15 15:53:16 +02:00
kgFactor: 1.0 / 701.0,
2020-06-28 22:10:54 +02:00
peakDetector: 'SIMPLE', // either 'SIMPLE' or 'ZSCORE'
2020-06-30 18:06:37 +02:00
peakDetectorSimpleThreshold: 2000,
2020-06-02 17:19:09 +02:00
peakDetectorZScoreLag: 8, // peak detector z-score values
peakDetectorZScoreThreshold: 2,
peakDetectorZScoreInfluence: 0.1,
2020-07-15 15:53:16 +02:00
activeTimeThreshold: 300,
movingAverageWindowSize: 10*5,
2020-06-02 17:19:09 +02:00
}
};
2020-06-02 17:19:09 +02:00
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
}
};
export default combineReducers({
settings: settingsReducer,
deviceState: deviceStateReducer,
2020-06-02 17:19:09 +02:00
});