swimtracker-app/state/Reducer.js

66 lines
1.7 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 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 = {
theme: "hot",
username: "",
2020-07-26 14:58:22 +02:00
//swimTrackerHost: "192.168.178.107", // am pool
swimTrackerHost: "192.168.42.1", // testgeraet
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
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
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
});