<commit_before>var fs = require('fs');
var path = require('path');
var CSVParse = require('babyparse');
var _ = require('../server/libs/underscore.1.6.0.min');
var md5 = require('MD5');

var filePath = path.join(__dirname, 'guestlist.csv');

fs.readFile(filePath, "utf-8", function (err, data) {
  if (err) {
    console.log( err );
  }

  //console.log( data );

  var csvParse = CSVParse.parse( data, { header: true } );

  var addressJSON = mapContactInfo(csvParse.data);

  //console.log( addressJSON );

  var strAddressJSON = JSON.stringify(addressJSON, undefined, 2);

  var newJSONFile = path.join(__dirname, 'guestlist.json');

  fs.writeFile(newJSONFile, strAddressJSON, function (err) {
    if (err) return console.log(err);
  });

});


function mapContactInfo(addressJSON) {

  var rsvpCodes = [];

  var i = 0;

  var reservations = _.map(addressJSON, function(reservation) {

    reservation.id = i++;
    reservation.isInvitedToRehearsalDinner = false;
    reservation.isAttendingBigDay = false;
    reservation.isAttendingRehearsalDinner = false;

    reservation.addressArray = [reservation.addressTitle,
                                reservation.addressLineOne,
                                reservation.addressLineTwo,
                                reservation.addressCity,
                                reservation.addressState,
                                reservation.addressZipCode
                                ];

    reservation.rsvpCodeSource = reservation.addressArray.join('|');

    reservation.rsvpCode = md5(reservation.rsvpCodeSource).substring(0,6);

    rsvpCodes.push( reservation.rsvpCode );

    return reservation;
  });

  console.log( rsvpCodes );

  return reservations;
}<commit_msg>Handle pulling the contacts and making the subarray.<commit_after>var fs = require('fs');
var path = require('path');
var CSVParse = require('babyparse');
var _ = require('../server/libs/underscore.1.6.0.min');
var md5 = require('MD5');

var filePath = path.join(__dirname, 'guestlist.csv');

fs.readFile(filePath, "utf-8", function (err, data) {
  if (err) {
    console.log( err );
  }

  //console.log( data );

  var csvParse = CSVParse.parse( data, { header: true } );

  var addressJSON = mapContactInfo(csvParse.data);

  //console.log( addressJSON );

  var strAddressJSON = JSON.stringify(addressJSON, undefined, 2);

  var newJSONFile = path.join(__dirname, 'guestlist.json');

  fs.writeFile(newJSONFile, strAddressJSON, function (err) {
    if (err) return console.log(err);
  });

});


function mapContactInfo(addressJSON) {

  var rsvpCodes = [];

  var i = 0;

  var reservations = _.map(addressJSON, function(reservation) {

    reservation.id = i++;
    reservation.isInvitedToRehearsalDinner = false;
    reservation.isAttendingBigDay = false;
    reservation.isAttendingRehearsalDinner = false;

    reservation.addressArray = [reservation.addressTitle,
                                reservation.addressLineOne,
                                reservation.addressLineTwo,
                                reservation.addressCity,
                                reservation.addressState,
                                reservation.addressZipCode
                                ];


    var namesList = reservation.addressContacts.split(",");

    var contacts = _.map(namesList, function(reservationContactName) {
      var contact = {};

      contact.firstName = null;
      contact.lastName = null;
      contact.isInvitedToRehearsalDinner = false;
      contact.isAttendingBigDay = false;
      contact.isAttendingRehearsalDinner = false;

      var contactNameSplit = reservationContactName.split(" ");

      if (contactNameSplit.length == 0)
      {
        return null;
      }

      if (contactNameSplit.length == 1 && contactNameSplit[0] === "????")
      {
        contact.firstName = "(Fill Out First Name)";
        contact.lastName = "(Fill Out Last Name)";

        return contact;
      }

      if (contactNameSplit.length == 2)
      {
        contact.firstName = contactNameSplit[0] === "????" ? "(Fill Out First Name)" : contactNameSplit[0];
        contact.lastName = contactNameSplit[1] === "????" ? "(Fill Out Last Name)" : contactNameSplit[1];
        return contact
      }

    });

    reservation.contacts = contacts;

    reservation.rsvpCodeSource = reservation.addressArray.join('|');

    reservation.rsvpCode = md5(reservation.rsvpCodeSource).substring(0,6);

    rsvpCodes.push( reservation.rsvpCode );

    return reservation;
  });

  console.log( rsvpCodes );

  return reservations;
}
{'fraction_non_alphanumeric': 0.12363715656345399, 'fraction_numerical': 0.0065416484954208464, 'mean_word_length': 2.654980079681275, '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': '4804713', 'n_tokens_mistral': 1419, 'n_tokens_neox': 1327, 'n_words': 261}