<commit_before>
'use strict';

import Immutable, { Map, List } from 'immutable';

// import Interpreter from 'js-interpreter';

import { SESSION_FINISH, SESSION_SAVE } from '../actions/session';

import { CHALLENGE_START, CHALLENGE_NEXT } from '../actions/challenge';

import { TESTS_STARTED } from '../actions/test';

import { PLAYER_PASSED } from '../actions/playerstatus';

import { MODAL_OPEN } from '../actions/modal';

/* TODO: Returns score for completed challenge. */
const getScoreForChallenge = challenge => {
  return 100;
};

const initialState = Immutable.Map({
  isSessionFinished: false,
  isSessionStarted: false,
  isSessionSaved: false,
  sessionScore: 0,
  challengesCompleted: 0,
  totalAttempts: 0,
  streakMultiplier: 1,
  currSession: Map({
    challenges: List(),
    score: 0,
    time: 0
  })
});

export default function session (state = initialState, action) {
  switch (action.type) {
    case CHALLENGE_START:
      return state
        .set('isSessionFinished', false)
        .set('isSessionStarted', true)
        .set('isSessionSaved', false);
    case CHALLENGE_NEXT:
      return state
        .update('challengesCompleted', challengesCompleted => challengesCompleted + 1)
        .update('streakMultiplier', streakMultiplier => 1.25 * streakMultiplier)
        .update('sessionScore', sessionScore => Math.floor(sessionScore + state.get('streakMultiplier') * getScoreForChallenge(state.currChallenge)))
        .update('currSession', currSession =>
          currSession.set('challenges',
            currSession.get('challenges').push(action.currChallenge))
        );
    case SESSION_SAVE:
      return state
        .set('isSessionSaved', true);
    case SESSION_FINISH:
      return state
        .set('isSessionFinished', true)
        .set('isSessionStarted', false)
        .setIn(['currSession', 'score'], state.get('sessionScore'));
    case TESTS_STARTED:
      return state.update('totalAttempts', totalAttempts => totalAttempts + 1);
    case PLAYER_PASSED:
      return state.set('streakMultiplier', 1);
    case MODAL_OPEN:
      return initialState;
    default:
      return state;
  }
}<commit_msg>Added startTime and endTime for a session.<commit_after>
'use strict';

import Immutable, { Map, List } from 'immutable';

// import Interpreter from 'js-interpreter';

import { SESSION_FINISH, SESSION_SAVE } from '../actions/session';

import { CHALLENGE_START, CHALLENGE_NEXT } from '../actions/challenge';

import { TESTS_STARTED } from '../actions/test';

import { PLAYER_PASSED } from '../actions/playerstatus';

import { MODAL_OPEN } from '../actions/modal';

/* TODO: Returns score for completed challenge. */
const getScoreForChallenge = () => 100;

const initialState = Immutable.Map({
  isSessionFinished: false,
  isSessionStarted: false,
  isSessionSaved: false,
  sessionScore: 0,
  challengesCompleted: 0,
  totalAttempts: 0,
  streakMultiplier: 1,
  currSession: Map({
    challenges: List(),
    score: 0,
    time: 0,
    startTime: 0,
    endTime: 0
  })
});

export default function session (state = initialState, action) {
  switch (action.type) {
    case CHALLENGE_START:
      return state
        .set('isSessionFinished', false)
        .set('isSessionStarted', true)
        .set('isSessionSaved', false)
        .setIn(['currSession', 'startTime'], action.startTime);
    case CHALLENGE_NEXT:
      return state
        .update('challengesCompleted', challengesCompleted => challengesCompleted + 1)
        .update('streakMultiplier', streakMultiplier => 1.25 * streakMultiplier)
        .update('sessionScore', sessionScore => Math.floor(sessionScore + state.get('streakMultiplier') * getScoreForChallenge()))
        .update('currSession', currSession =>
          currSession.set('challenges',
            currSession.get('challenges').push(action.currChallenge.set('endTime', action.startTime))
          )
        );
    case SESSION_SAVE:
      return state
        .set('isSessionSaved', true);
    case SESSION_FINISH:
      return state
        .set('isSessionFinished', true)
        .set('isSessionStarted', false)
        .setIn(['currSession', 'score'], state.get('sessionScore'))
        .setIn(['currSession', 'endTime'], action.endTime);
    case TESTS_STARTED:
      return state.update('totalAttempts', totalAttempts => totalAttempts + 1);
    case PLAYER_PASSED:
      return state.set('streakMultiplier', 1);
    case MODAL_OPEN:
      return initialState;
    default:
      return state;
  }
}
{'fraction_non_alphanumeric': 0.12725250278086764, 'fraction_numerical': 0.007119021134593994, 'mean_word_length': 3.4514851485148514, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7382311', 'n_tokens_mistral': 1397, 'n_tokens_neox': 1352, 'n_words': 309}