app changes

This commit is contained in:
Martin Bauer
2020-06-02 17:19:09 +02:00
parent d0b81bb7fb
commit 2584d2249f
13 changed files with 606 additions and 46 deletions

27
state/ActionCreators.js Normal file
View File

@@ -0,0 +1,27 @@
export const NEW_DEVICE_DATA = "NEW_DEVICE_DATA";
export const CHANGE_USER_NAME = "SET_USERNAME";
export const CHANGE_THEME = "CHANGE_THEME";
export const START_SESSION = "START_SESSION";
export const reportDeviceData = (sessionId, newDataStart, data, analysis) => ({
type: NEW_DEVICE_DATA,
sessionId: sessionId,
newDataStart: newDataStart,
data: data,
analysis: analysis,
})
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
})

71
state/Reducer.js Normal file
View File

@@ -0,0 +1,71 @@
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,
});