<commit_before>// populate population table from Census API
var request = require('request-promise');
var baseCensus = 'https://api.census.gov/data/2015/pep/';
var DATES = require('./utils').DATES;
var PERIODS = require('./utils').PERIODS;
var fipsToState = require('./utils').fipsToState;
var stateToFips = require('./utils').stateToFips;

function initPopulationsTable(Population, State) {
  var promisedDates = [];
    
  // generate population stats for each year
  for (var date in DATES) {
    
    // capture date
    (function(date) {
      
      promisedDate = promisedDates.concat(
        
        // query for population
        request(baseCensus + 'population?get=POP&for=state:*&DATE=' + DATES[date] + '&key=' + process.env.KEY)
          .then(function(data) {

            var populations = JSON.parse(data).slice(1);
                      
            var promisedPops = populations.map(function(population) {
              
              // capture population in year (date)
              return (function(total, fips, date) {
                
                // query for state (fips) growth in year (date)
                return request(baseCensus + 'components?get=BIRTHS,DEATHS&for=state:' + fips + '&PERIOD=' + PERIODS[date] + '&key=' + process.env.KEY)
                  .then(function(data) {
                    var growth = JSON.parse(data).slice(1);
                    
                    // capture population, year, births, deaths, state capital
                    return (function(total, year, births, deaths, state) {
                      
                      return Population.create({population: total, year: year, births: births, deaths: deaths})
                        .then(function(pop) {
                          console.log('success population initialized:', pop);
                          return State.findAll({where: {capital: state}})
                            .then(function(stateModel) {
                              console.log('state found for population', JSON.stringify(stateModel));
                              return stateModel ? pop.setState(stateModel[0]): pop.setState('Non-Continental');
                            });<commit_msg>(fix) Appropriate null check on population model<commit_after>// populate population table from Census API
var request = require('request-promise');
var baseCensus = 'https://api.census.gov/data/2015/pep/';
var DATES = require('./utils').DATES;
var PERIODS = require('./utils').PERIODS;
var fipsToState = require('./utils').fipsToState;
var stateToFips = require('./utils').stateToFips;

function initPopulationsTable(Population, State) {
  var promisedDates = [];
    
  // generate population stats for each year
  for (var date in DATES) {
    
    // capture date
    (function(date) {
      
      promisedDate = promisedDates.concat(
        
        // query for population
        request(baseCensus + 'population?get=POP&for=state:*&DATE=' + DATES[date] + '&key=' + process.env.KEY)
          .then(function(data) {

            var populations = JSON.parse(data).slice(1);
                      
            var promisedPops = populations.map(function(population) {
              
              // capture population in year (date)
              return (function(total, fips, date) {
                
                // query for state (fips) growth in year (date)
                return request(baseCensus + 'components?get=BIRTHS,DEATHS&for=state:' + fips + '&PERIOD=' + PERIODS[date] + '&key=' + process.env.KEY)
                  .then(function(data) {
                    var growth = JSON.parse(data).slice(1);
                    
                    // capture population, year, births, deaths, state capital
                    return (function(total, year, births, deaths, state) {
                      
                      return Population.create({population: total, year: year, births: births, deaths: deaths})
                        .then(function(pop) {
                          console.log('success population initialized:', pop);
                          return State.findAll({where: {capital: state}})
                            .then(function(stateModel) {
                              return stateModel[0] ? pop.setState(stateModel[0]): pop.setState('Non-Continental');
                            });
{'fraction_non_alphanumeric': 0.1207095139368809, 'fraction_numerical': 0.0034554250172771253, 'mean_word_length': 1.852825229960578, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '1190933', 'n_tokens_mistral': 1168, 'n_tokens_neox': 1113, 'n_words': 263}