<commit_before>var _         = require('underscore')
, reltime     = require('reltime')
, Duration    = require('duration')
, Validate    = require('okdoki/lib/Validate').Validate
, Screen_Name = require('okdoki/lib/Screen_Name').Screen_Name
, UID         = require('okdoki/lib/UID').UID
, River       = require('okdoki/lib/River').River
, Arango      = require('okdoki/lib/ArangoDB').ArangoDB
, warn        = require('okdoki/lib/base').warn
, crypto      = require('crypto')
;


function encode_pass_phrase ( seed, pass_phrase ) {
  return crypto.createHash('sha512').update(seed + pass_phrase).digest('hex');
}

function add_s(v) {
  return (v > 1 ? 's' : '');
}

function human_durs(durs) {
  var msg = [];
  var d = durs.day;
  var h = durs.hour;
  var m = durs.minute;
  var v = null;

  if (d === 1 && h === 23 && m > 45) {
    d = 2;
    h = 0;
    m = 0;
  }

  v = d;
  if (v > 0)
    msg.push( v + " day" + add_s(v) );

  v = h;
  if (v > 0)
    msg.push(v + " hr" + add_s(v));

  v = m;
  if (v > 0)
    msg.push(v + " min" + add_s(v));

  return msg.join(', ');
}

// ****************************************************************
// *************** Main Object ************************************
// ****************************************************************


var Customer = exports.Customer = function () {
  this.is_new         = true;
  this.data           = {};
  this.sanitized_data = {};
  this.new_data       = {};
};

Customer.new = function () {
  var mem = new Customer();
  return mem;
};

// ****************************************************************
// *************** Settings ***************************************
// ****************************************************************

var TABLE_NAME = Customer.TABLE_NAME = 'customers';

// ****************************************************************
// *************** Helper Methods**********************************
// ****************************************************************

Customer.prototype.is = function (name) {
  return !!this.find_screen_name_row(name);
};

Customer.prototype.find_screen_name_row = function (raw_name) {
  if (!raw_name)
    throw new Error('Name must be specified: ' + raw_name);

  var name = (raw_name || '').toUpperCase();
  var rows = this.data.screen_name_rows;

  if (!rows)
    throw new Error('Screen name rows not found.');

  return _.find(rows, function (row) {
    return row.screen_name === name || row.display_name.toUpperCase() === name;
  });
};

Customer.prototype.push_sanitized_data = function (k, val) {
  if (!this.validator.has_errors()) {
    this.sanitized_data[k] = val;
  }
};

Customer.prototype.push_screen_name_row = function (r) {
  if (r.sanitized_data)
  throw new Error(r.toString());

  var me    = this;
  var rows  = me.data.screen_name_rows;
  var names = [];

  if (!rows) {
    me.data.screen_name_rows = rows = {};
  }

  if (r.old_screen_name) {
    delete rows[(r._id || r.id || r._key || r.key).split('/').pop()];
  }

  r.is_trashed = !!r.trashed_at;

  if (r.is_trashed)
    me.generate_trash_msg(r);

  r.world_read   = r.read_able === 'W';
  r.no_one_read  = r.read_able === 'N';
  r.specify_read = r.read_able === 'S';

  _.each('settings details'.split(' '), function (name, i) {
    if (r.hasOwnProperty(name)) {
      if (!r[name] || (r[name].trim && r[name] === ''))
        r[name] = {};
      else
        r[name] = JSON.parse(r[name]);
    }
  });

  rows[r.id] = r;<commit_msg>Fixed: .id of row was not being set after update.<commit_after>var _         = require('underscore')
, reltime     = require('reltime')
, Duration    = require('duration')
, Validate    = require('okdoki/lib/Validate').Validate
, Screen_Name = require('okdoki/lib/Screen_Name').Screen_Name
, UID         = require('okdoki/lib/UID').UID
, River       = require('okdoki/lib/River').River
, Arango      = require('okdoki/lib/ArangoDB').ArangoDB
, warn        = require('okdoki/lib/base').warn
, crypto      = require('crypto')
;


function encode_pass_phrase ( seed, pass_phrase ) {
  return crypto.createHash('sha512').update(seed + pass_phrase).digest('hex');
}

function add_s(v) {
  return (v > 1 ? 's' : '');
}

function human_durs(durs) {
  var msg = [];
  var d = durs.day;
  var h = durs.hour;
  var m = durs.minute;
  var v = null;

  if (d === 1 && h === 23 && m > 45) {
    d = 2;
    h = 0;
    m = 0;
  }

  v = d;
  if (v > 0)
    msg.push( v + " day" + add_s(v) );

  v = h;
  if (v > 0)
    msg.push(v + " hr" + add_s(v));

  v = m;
  if (v > 0)
    msg.push(v + " min" + add_s(v));

  return msg.join(', ');
}

// ****************************************************************
// *************** Main Object ************************************
// ****************************************************************


var Customer = exports.Customer = function () {
  this.is_new         = true;
  this.data           = {};
  this.sanitized_data = {};
  this.new_data       = {};
};

Customer.new = function () {
  var mem = new Customer();
  return mem;
};

// ****************************************************************
// *************** Settings ***************************************
// ****************************************************************

var TABLE_NAME = Customer.TABLE_NAME = 'customers';

// ****************************************************************
// *************** Helper Methods**********************************
// ****************************************************************

Customer.prototype.is = function (name) {
  return !!this.find_screen_name_row(name);
};

Customer.prototype.find_screen_name_row = function (raw_name) {
  if (!raw_name)
    throw new Error('Name must be specified: ' + raw_name);

  var name = (raw_name || '').toUpperCase();
  var rows = this.data.screen_name_rows;

  if (!rows)
    throw new Error('Screen name rows not found.');

  return _.find(rows, function (row) {
    return row.screen_name === name || row.display_name.toUpperCase() === name;
  });
};

Customer.prototype.push_sanitized_data = function (k, val) {
  if (!this.validator.has_errors()) {
    this.sanitized_data[k] = val;
  }
};

Customer.prototype.push_screen_name_row = function (r) {
  var me    = this;
  var rows  = me.data.screen_name_rows;
  var names = [];

  if (!r.id && r._key)
    r.id = r._key;

  if (!rows) {
    me.data.screen_name_rows = rows = {};
  }

  r.is_trashed = !!r.trashed_at;

  if (r.is_trashed)
    me.generate_trash_msg(r);

  r.world_read   = r.read_able === 'W';
  r.no_one_read  = r.read_able === 'N';
  r.specify_read = r.read_able === 'S';

  _.each('settings details'.split(' '), function (name, i) {
    if (r.hasOwnProperty(name)) {
      if (!r[name] || (r[name].trim && r[name] === ''))
        r[name] = {};
      else
        r[name] = JSON.parse(r[name]);
    }
  });

  rows[r.id] = r;
{'fraction_non_alphanumeric': 0.31132487975513773, 'fraction_numerical': 0.004372540445999125, 'mean_word_length': 3.407193320488118, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '2705906', 'n_tokens_mistral': 2348, 'n_tokens_neox': 2251, 'n_words': 447}