80 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
			
		
		
	
	
			80 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
| import { combineReducers } from 'redux';
 | |
| import { List } from 'immutable';
 | |
| import { CHANGE_THEME, CHANGE_USER_NAME, NEW_DEVICE_DATA, START_SESSION, STOP_SESSION, RESET_DEVICE_DATA } from './ActionCreators';
 | |
| 
 | |
| const INITIAL_SETTINGS = {
 | |
|     theme: "hot",
 | |
|     username: "",
 | |
|     deviceURL: "http://192.168.178.107",
 | |
|     peaksPerLap: 30,
 | |
| 
 | |
|     // advanced
 | |
|     peakDetector: 'SIMPLE', // either 'SIMPLE' or 'ZSCORE'
 | |
|     peakDetectorSimpleThreshold: 2500,
 | |
| 
 | |
|     peakDetectorZScoreLag: 8, // peak detector z-score values
 | |
|     peakDetectorZScoreThreshold: 2,
 | |
|     peakDetectorZScoreInfluence: 0.1,
 | |
| };
 | |
| 
 | |
| const INITIAL_CURRENT_SESSION = {
 | |
|     running: false,
 | |
|     sessionId: 0,
 | |
|     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 STOP_SESSION:
 | |
|             return {
 | |
|                 running: false,
 | |
|                 rawData: List(),
 | |
|                 analysis: INITIAL_CURRENT_SESSION.analysis
 | |
|             };
 | |
|         case NEW_DEVICE_DATA:
 | |
|             return {
 | |
|                 running: action.data.size > 0,
 | |
|                 sessionId: action.sessionId,
 | |
|                 rawData: action.data,
 | |
|                 analysis: { ...state.analysis, ...action.analysis },
 | |
|             }
 | |
|         case RESET_DEVICE_DATA:
 | |
|             return INITIAL_CURRENT_SESSION
 | |
|         default:
 | |
|             return state
 | |
|     }
 | |
| };
 | |
| 
 | |
| export default combineReducers({
 | |
|     settings: settingsReducer,
 | |
|     session: currentSessionReducer,
 | |
| }); |