app changes
This commit is contained in:
27
state/ActionCreators.js
Normal file
27
state/ActionCreators.js
Normal 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
71
state/Reducer.js
Normal 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,
|
||||
});
|
||||
Reference in New Issue
Block a user