<commit_before>"use strict";
var AppDispatcher = require('../dispatcher/AppDispatcher');
var AppConstants = require('../constants/AppConstants');
var {EventEmitter} = require('events');
var assign = require('object-assign');
var WebAPIUtils = require("../utils/WebAPIUtils");

var {ActionTypes} = AppConstants;
var CHANGE_EVENT = 'change';
var _current = null;
var _candidates = {
  '5': {
    id: 5,
    name: '馮光遠',
    avatar: '/assets/images/candidates/5.jpg', //require("../../client/images/candidates/5.jpg")
    avatar_square: '/assets/images/candidates_avatar/5.jpg',
    status: false
  },
  '6': {
    id: 6,
    name: '連勝文',
    avatar: '/assets/images/candidates/6.jpg', //require("../../client/images/candidates/6.jpg")
    avatar_square: '/assets/images/candidates_avatar/6.jpg',
    status: false
  },
  '7': {
    id: 7,
    name: '柯文哲',
    avatar: '/assets/images/candidates/7.jpg', //require("../../client/images/candidates/7.jpg")
    avatar_square: '/assets/images/candidates_avatar/7.jpg',
    status: false
  }
};

var CandidateStore = assign({}, EventEmitter.prototype, {

  emitChange () {
    this.emit(CHANGE_EVENT);
  },

  addChangeListener (callback) {
    this.on(CHANGE_EVENT, callback);
  },

  removeChangeListener (callback) {
    this.removeListener(CHANGE_EVENT, callback);
  },

  getStatus () {
    var result = {};
    Object.keys(_candidates).map(function (c) {
      return result[c] = _candidates[c].status;
    });
    return result;
  },

  getCurrentCandidate () {
    return _current;
  },

  get (id) {
    return _candidates[id];
  },

  getAll () {
    return Object.keys(_candidates).map((c) => {
      return _candidates[c];
    });
  }
});

CandidateStore.dispatchToken = AppDispatcher.register((payload) => {
  var {action} = payload;
  switch(action.type) {
    case ActionTypes.CHOOSE_CANDIDATE:
      _current=action.id;
      CandidateStore.emitChange();
      break;
    case ActionTypes.STATUS:
      WebAPIUtils.checkStatus(function (err, res) {
        if (err) {
          return console.log(err);
        }
        Object.keys(_candidates).map(function(c, i){
          var allStatus = res.body.data;
          if(allStatus)
             _candidates[c]['status'] = allStatus[i];
        });
        CandidateStore.emitChange();
      });
      break;
    default:
  }

});

module.exports = CandidateStore;<commit_msg>add workaround comment<commit_after>"use strict";
var AppDispatcher = require('../dispatcher/AppDispatcher');
var AppConstants = require('../constants/AppConstants');
var {EventEmitter} = require('events');
var assign = require('object-assign');
var WebAPIUtils = require("../utils/WebAPIUtils");

var {ActionTypes} = AppConstants;
var CHANGE_EVENT = 'change';
var _current = null;
var _candidates = {
  '5': {
    id: 5,
    name: '馮光遠',
    avatar: '/assets/images/candidates/5.jpg', //require("../../client/images/candidates/5.jpg")
    avatar_square: '/assets/images/candidates_avatar/5.jpg',
    status: false
  },
  '6': {
    id: 6,
    name: '連勝文',
    avatar: '/assets/images/candidates/6.jpg', //require("../../client/images/candidates/6.jpg")
    avatar_square: '/assets/images/candidates_avatar/6.jpg',
    status: false
  },
  '7': {
    id: 7,
    name: '柯文哲',
    avatar: '/assets/images/candidates/7.jpg', //require("../../client/images/candidates/7.jpg")
    avatar_square: '/assets/images/candidates_avatar/7.jpg',
    status: false
  }
};

var CandidateStore = assign({}, EventEmitter.prototype, {

  emitChange () {
    this.emit(CHANGE_EVENT);
  },

  addChangeListener (callback) {
    this.on(CHANGE_EVENT, callback);
  },

  removeChangeListener (callback) {
    this.removeListener(CHANGE_EVENT, callback);
  },

  getStatus () {
    var result = {};
    Object.keys(_candidates).map(function (c) {
      return result[c] = _candidates[c].status;
    });
    return result;
  },

  getCurrentCandidate () {
    return _current;
  },

  get (id) {
    return _candidates[id];
  },

  getAll () {
    return Object.keys(_candidates).map((c) => {
      return _candidates[c];
    });
  }
});

CandidateStore.dispatchToken = AppDispatcher.register((payload) => {
  var {action} = payload;
  switch(action.type) {
    case ActionTypes.CHOOSE_CANDIDATE:
      _current=action.id;
      CandidateStore.emitChange();
      break;
    case ActionTypes.STATUS:
      WebAPIUtils.checkStatus(function (err, res) {
        if (err) {
          return console.log(err);
        }
        Object.keys(_candidates).map(function(c, i){
          var allStatus = res.body.data;
          if(allStatus)//this is a workaround
             _candidates[c]['status'] = allStatus[i];
        });
        CandidateStore.emitChange();
      });
      break;
    default:
  }

});

module.exports = CandidateStore;
{'fraction_non_alphanumeric': 0.16475495307612095, 'fraction_numerical': 0.006256517205422315, 'mean_word_length': 2.963636363636364, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5690807', 'n_tokens_mistral': 1638, 'n_tokens_neox': 1594, 'n_words': 270}