swimtracker-app/SwimTracker/state/Reducer.js

64 lines
1.7 KiB
JavaScript
Raw Permalink 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 RESET_DEVICE_DATA = "RESET_DEVICE_DATA";
2021-07-22 18:39:02 +02:00
export const CHANGE_SWIMTRACKER_HOSTNAME = "CHANGE_SWIMTRACKER_HOSTNAME";
2020-06-28 22:10:54 +02:00
export const changeUsername = newUsername => ({
type: CHANGE_USER_NAME,
newUserName: newUsername,
});
export const changeSwimTrackerHostname = newSwimTrackerHost => ({
2021-07-22 18:39:02 +02:00
type: CHANGE_SWIMTRACKER_HOSTNAME,
newSwimTrackerHost: newSwimTrackerHost,
});
2020-06-28 22:10:54 +02:00
export const startSession = () => ({
type: START_SESSION
});
export const stopSession = () => ({
type: STOP_SESSION
});
2020-06-02 17:19:09 +02:00
const INITIAL_SETTINGS = {
username: "",
2021-07-28 16:00:34 +02:00
swimTrackerHost: "swimtracker",
2020-06-02 17:19:09 +02:00
analysis: {
2020-08-09 21:53:38 +02:00
peaksPerLap: 30,
windowSizeInSecs: 5,
numMeasurementsPerSec: 10,
2020-06-02 17:19:09 +02:00
2021-07-28 16:00:34 +02:00
kgFactor: 1.0 / (701.0 * 2.4),
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
2020-07-15 18:17:12 +02:00
activeTimeThreshold: 700,
movingAverageWindowSize: 10 * 3,
2020-06-02 17:19:09 +02:00
}
};
const settingsReducer = (state = INITIAL_SETTINGS, action) => {
2020-06-02 17:19:09 +02:00
switch (action.type) {
case CHANGE_USER_NAME:
return { ...state, username: action.newUsername };
2021-07-22 18:39:02 +02:00
case CHANGE_SWIMTRACKER_HOSTNAME:
return { ...state, swimTrackerHost: action.newSwimTrackerHost };
2020-06-02 17:19:09 +02:00
default:
2021-07-22 18:39:02 +02:00
return state;
2020-06-02 17:19:09 +02:00
}
};
export default combineReducers({
settings: settingsReducer,
deviceState: deviceStateReducer,
2020-06-02 17:19:09 +02:00
});