<commit_before>var tF = require('./formatting.js');

function findQuery (ccExtractObj) {
  var query = {};
  query.charityNumber = tF.parseNumber(ccExtractObj.regno);
  query.subNumber = 0;
  if (ccExtractObj.hasOwnProperty('subno')) {
    query.subNumber = tF.parseNumber(ccExtractObj.subno);
  }
  return query;
}

var schemaConversion = {};

schemaConversion.extract_charity = function (ccCharityObj, openCharitiesModel) {
  var charity = {
    charityNumber : tF.parseNumber(ccCharityObj.regno),
    subNumber : tF.parseNumber(ccCharityObj.subno),
    name : tF.titleCase(ccCharityObj.name),
    registered : {'R': true, 'RM': false}[ccCharityObj.orgtype],
    govDoc : ccCharityObj.gd,
    areaOfBenefit : ccCharityObj.aob,
    contact : {
      correspondant : ccCharityObj.corr,
      phone : ccCharityObj.phone,
      fax : ccCharityObj.fax,
      address : [],
      postcode : ccCharityObj.postcode
    }
  };
  var addressKeys = ['add1', 'add2', 'add3', 'add4', 'add5'];
  for (var i=0; i<addressKeys.length; i++) {
    if (ccCharityObj[addressKeys[i]]) {
      charity.contact.address.push(ccCharityObj[addressKeys[i]]);
    }
  }
  var updateQuery = { '$set' : charity };
  return openCharitiesModel.find(findQuery(ccCharityObj)).upsert().updateOne(updateQuery); // use replaceOne for clean update
};

schemaConversion.extract_main_charity = function (ccExtractObj, openCharitiesModel) {
  var main = {
    companyNumber: ccExtractObj.coyno,
    trustees: {'T': true, 'F': false}[ccExtractObj.trustees],
    fyEnd : ccExtractObj.fyend,
    welsh : {'T': true, 'F': false}[ccExtractObj.welsh],
    incomeDate : tF.parseDate(ccExtractObj.incomedate),
    income : tF.parseNumber(ccExtractObj.income),<commit_msg>rename variable ccCharityObj -> ccExtractObj<commit_after>var tF = require('./formatting.js');

function findQuery (ccExtractObj) {
  var query = {};
  query.charityNumber = tF.parseNumber(ccExtractObj.regno);
  query.subNumber = 0;
  if (ccExtractObj.hasOwnProperty('subno')) {
    query.subNumber = tF.parseNumber(ccExtractObj.subno);
  }
  return query;
}

var schemaConversion = {};

schemaConversion.extract_charity = function (ccExtractObj, openCharitiesModel) {
  var charity = {
    charityNumber : tF.parseNumber(ccExtractObj.regno),
    subNumber : tF.parseNumber(ccExtractObj.subno),
    name : tF.titleCase(ccExtractObj.name),
    registered : {'R': true, 'RM': false}[ccExtractObj.orgtype],
    govDoc : ccExtractObj.gd,
    areaOfBenefit : ccExtractObj.aob,
    contact : {
      correspondant : ccExtractObj.corr,
      phone : ccExtractObj.phone,
      fax : ccExtractObj.fax,
      address : [],
      postcode : ccExtractObj.postcode
    }
  };
  var addressKeys = ['add1', 'add2', 'add3', 'add4', 'add5'];
  for (var i=0; i<addressKeys.length; i++) {
    if (ccExtractObj[addressKeys[i]]) {
      charity.contact.address.push(ccExtractObj[addressKeys[i]]);
    }
  }
  var updateQuery = { '$set' : charity };
  return openCharitiesModel.find(findQuery(ccExtractObj)).upsert().updateOne(updateQuery); // use replaceOne for clean update
};

schemaConversion.extract_main_charity = function (ccExtractObj, openCharitiesModel) {
  var main = {
    companyNumber: ccExtractObj.coyno,
    trustees: {'T': true, 'F': false}[ccExtractObj.trustees],
    fyEnd : ccExtractObj.fyend,
    welsh : {'T': true, 'F': false}[ccExtractObj.welsh],
    incomeDate : tF.parseDate(ccExtractObj.incomedate),
    income : tF.parseNumber(ccExtractObj.income),
{'fraction_non_alphanumeric': 0.13977566867989646, 'fraction_numerical': 0.004026459591601955, 'mean_word_length': 4.222222222222222, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, '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': '903696', 'n_tokens_mistral': 1188, 'n_tokens_neox': 1221, 'n_words': 204}