<commit_before>/*jshint maxparams: 6 */
'use strict';

var Census = require('../models/census');

var exists = require('../lib/queryUtil').exists;

var isValidCombination = function(activityYear, censusparams, callback) {
    var query = {'activity_year': activityYear};

    for (var param in censusparams) {
        if (censusparams[param]!==undefined && censusparams[param]!=='NA') {
            query[param] = censusparams[param];
        }
    }
        
    // check that state, county exist
    Census.findOne(query, function(err, data) {
        if (err) {
            return callback(err, null);
        }
        if (data === null || (censusparams.tract === 'NA' && data.small_county!=='1')) {
            return callback(null, {result: false});
        }
        return callback(null, {result: true});
    });
};

module.exports = {
    isValidMSA: function(activityYear, msa, callback) {
        var query = { 'activity_year': activityYear, 'msa_code' : msa };
        return exists ('Census', query, callback);
    },

    isValidStateCounty: function(activityYear, state, county, callback) {
        return isValidCombination (activityYear, {'state_code':state, 'county_code':county}, callback);
    },

    isValidCensusCombination: function(activityYear, censusparams, callback) {
       isValidCombination (activityYear, censusparams, callback);
    },

    isValidCensusTractCombo: function(activityYear, state, county, metroArea, tract, callback) {
        return isValidCombination (activityYear, {'msa_code':metroArea, 'tract': tract,
            'state_code':state, 'county_code':county}, callback);
    }
};<commit_msg>added msa_code return for isValidCensusCombination<commit_after>/*jshint maxparams: 6 */
'use strict';

var Census = require('../models/census');

var exists = require('../lib/queryUtil').exists;

var isValidCombination = function(activityYear, censusparams, callback) {
    var query = {'activity_year': activityYear};

    for (var param in censusparams) {
        if (censusparams[param]!==undefined && censusparams[param]!=='NA') {
            query[param] = censusparams[param];
        }
    }
        
    // check that state, county exist
    Census.findOne(query, function(err, data) {
        if (err) {
            return callback(err, null);
        }
        if (data === null || (censusparams.tract === 'NA' && data.small_county!=='1')) {
            return callback(null, {result: false});
        }
        return callback(null, {result: true, msa_code: data.msa_code});
    });
};

module.exports = {
    isValidMSA: function(activityYear, msa, callback) {
        var query = { 'activity_year': activityYear, 'msa_code' : msa };
        return exists ('Census', query, callback);
    },

    isValidStateCounty: function(activityYear, state, county, callback) {
        return isValidCombination (activityYear, {'state_code':state, 'county_code':county}, callback);
    },

    isValidCensusCombination: function(activityYear, censusparams, callback) {
       isValidCombination (activityYear, censusparams, callback);
    },

    isValidCensusTractCombo: function(activityYear, state, county, metroArea, tract, callback) {
        return isValidCombination (activityYear, {'msa_code':metroArea, 'tract': tract,
            'state_code':state, 'county_code':county}, callback);
    }
};
{'fraction_non_alphanumeric': 0.14076509264793782, 'fraction_numerical': 0.001195457262402869, 'mean_word_length': 3.3694516971279374, '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': '4860611', 'n_tokens_mistral': 991, 'n_tokens_neox': 978, 'n_words': 222}