<commit_before>var _ = require('lodash');
var moment = require('moment');

var requestedVariables = require('../openfisca/mapping/common').requestedVariables;

module.exports = function extractResults(openfiscaResults, date) {
    var period = moment(date).format('YYYY-MM');

    var individuId = openfiscaResults.menages._.personne_de_reference[0];
    var aideEntity = _.assign({}, openfiscaResults.familles._, openfiscaResults.individus[individuId]);
    return _.reduce(requestedVariables, function(result, aide, aideId) {
        if (aide.type == 'string') {
            return result;
        }

        var non_calculable = (aideEntity[aideId + '_non_calculable'] && aideEntity[aideId + '_non_calculable'][period]);
        if (non_calculable) {
            result[aideId] = non_calculable;
            return result;
        }

        result[aideId] = aideEntity[aideId] && aideEntity[aideId][period];
        if (result[aideId] && ((! aide.type) || aide.type == 'float')) {
            result[aideId] = Number(result[aideId].toFixed(2));
        }
        return result;
    }, {});
};
<commit_msg>Manage new Enum syntax in Ludwig #783<commit_after>var _ = require('lodash');
var moment = require('moment');

var requestedVariables = require('../openfisca/mapping/common').requestedVariables;

module.exports = function extractResults(openfiscaResults, date) {
    var period = moment(date).format('YYYY-MM');

    var individuId = openfiscaResults.menages._.personne_de_reference[0];
    var aideEntity = _.assign({}, openfiscaResults.familles._, openfiscaResults.individus[individuId]);
    return _.reduce(requestedVariables, function(result, aide, aideId) {
        if (aide.type == 'string') {
            return result;
        }

        var non_calculable = (aideEntity[aideId + '_non_calculable'] && aideEntity[aideId + '_non_calculable'][period]);
        if (non_calculable && non_calculable != 'calculable') {
            result[aideId] = non_calculable;
            return result;
        }

        result[aideId] = aideEntity[aideId] && aideEntity[aideId][period];
        if (result[aideId] && ((! aide.type) || aide.type == 'float')) {
            result[aideId] = Number(result[aideId].toFixed(2));
        }
        return result;
    }, {});
};

{'fraction_non_alphanumeric': 0.14543057996485062, 'fraction_numerical': 0.0030755711775043936, 'mean_word_length': 3.370441458733205, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7373855', 'n_tokens_mistral': 746, 'n_tokens_neox': 721, 'n_words': 122}