<commit_before>/*
 This file is a part of libertysoil.org website
 Copyright (C) 2015  Loki Education (Social Enterprise)

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU Affero General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU Affero General Public License for more details.

 You should have received a copy of the GNU Affero General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
import i from 'immutable';
import _ from 'lodash';

import * as a from '../actions';


const initialState = i.Map({});

export default function reducer(state=initialState, action) {
  switch (action.type) {
    case a.ADD_SCHOOL: {
      const school = action.school;
      state = state.set(school.id, i.fromJS(school));

      break;
    }

    case a.SET_SCHOOLS: {
      const schools = _.keyBy(action.schools, 'id');
      state = state.merge(i.fromJS(schools));

      break;
    }
  }

  return state;
}
<commit_msg>Clean school data in redux<commit_after>/*
 This file is a part of libertysoil.org website
 Copyright (C) 2015  Loki Education (Social Enterprise)

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU Affero General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU Affero General Public License for more details.

 You should have received a copy of the GNU Affero General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
import i from 'immutable';
import { keyBy } from 'lodash';

import * as a from '../actions';


function cleanupSchoolObject(school) {
  if (school.description === null) {
    school.description = '';
  }

  if (school.lat === null) {
    school.lat = 0.0;
  }

  if (school.lon === null) {
    school.lon = 0.0;
  }

  return school;
}

const initialState = i.Map({});

export default function reducer(state=initialState, action) {
  switch (action.type) {
    case a.ADD_SCHOOL: {
      const school = cleanupSchoolObject(action.school);
      state = state.set(school.id, i.fromJS(school));

      break;
    }

    case a.SET_SCHOOLS: {
      const schools = keyBy(action.schools.map(school => cleanupSchoolObject(school)), 'id');
      state = state.merge(i.fromJS(schools));

      break;
    }
  }

  return state;
}

{'fraction_non_alphanumeric': 0.0913775334936448, 'fraction_numerical': 0.0048093438680865686, 'mean_word_length': 3.3987915407854983, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7017995', 'n_tokens_mistral': 856, 'n_tokens_neox': 813, 'n_words': 344}