<commit_before>"use strict";
var _ = require('lodash'),
  redis = require('redis'),
  when = require('when'),
  moment = require('moment'),
  url = require('url'),
  redisClient, redisURL;
if (process.env.NODE_ENV === 'production') {
  redisURL = url.parse(process.env.REDISCLOUD_URL);
  redisClient = redis.createClient(redisURL.port, redisURL.hostname, {no_ready_check: true});
  redisClient.auth(redisURL.auth.split(":")[1]);
} else {
  redisClient = redis.createClient();
}


// Transaction Models

// incremental key to set the transaction id
// hashes to store the actual transactions
// lists with weekly keys to store the transactions keys
// report on the last weeks list .. still stores historical datanpm


function Transaction(obj, client) {
  this.client = client || redisClient;

  this.key = (obj) ? obj.key : null;
  this.date = (obj) ? obj.date : null;
  this.time = (obj) ? obj.time : null;
  this.name = (obj) ? obj.name : null;
  this.amount = (obj) ? obj.amount : null;
}

Transaction.prototype.save = function() {

  if (_.any([this.time, this.date, this.amount, this.name], function (item) {
    return _.isNull(item);
  })) {
    return when.reject(new Error('Transaction fields must be set before saving.'));
  }

  var promise, multi = this.client.multi(),
    week = 'w' + moment().isoWeek();

  promise = when.promise(function (resolve, reject) {
    this.client.incr('tkey', function (err, reply) {
      if (err || (reply === null)) reject(new Error('No trans key?'));

      this.key = reply;
      console.log('w'+week);
      multi.hmset(this.key, {
        key: this.key,
        date: this.date,
        time: this.time,
        name: this.name,
        amount: this.amount
      });
      multi.rpush(week, this.key);

      multi.exec(function (err, replies) {
        console.log(replies);
        if (err) {
          console.log('save trans ' + this.key + ': FAIL');
          reject(new Error(err));
          return false;
        }<commit_msg>fix typo<commit_after>"use strict";
var _ = require('lodash'),
  redis = require('redis'),
  when = require('when'),
  moment = require('moment'),
  url = require('url'),
  redisClient, redisURL;
if (process.env.NODE_ENV === 'production') {
  redisURL = url.parse(process.env.REDISCLOUD_URL);
  redisClient = redis.createClient(redisURL.port, redisURL.hostname, {no_ready_check: true});
  redisClient.auth(redisURL.auth.split(":")[1]);
} else {
  redisClient = redis.createClient();
}


// Transaction Models

// incremental key to set the transaction id
// hashes to store the actual transactions
// lists with weekly keys to store the transactions keys
// report on the last weeks list .. still stores historical datanpm


function Transaction(obj, client) {
  this.client = client || redisClient;

  this.key = (obj) ? obj.key : null;
  this.date = (obj) ? obj.date : null;
  this.time = (obj) ? obj.time : null;
  this.name = (obj) ? obj.name : null;
  this.amount = (obj) ? obj.amount : null;
}

Transaction.prototype.save = function() {

  if (_.any([this.time, this.date, this.amount, this.name], function (item) {
    return _.isNull(item);
  })) {
    return when.reject(new Error('Transaction fields must be set before saving.'));
  }

  var promise, multi = this.client.multi(),
    week = 'w' + moment().isoWeek();

  promise = when.promise(function (resolve, reject) {
    this.client.incr('tkey', function (err, reply) {
      if (err || (reply === null)) reject(new Error('No trans key?'));

      this.key = reply;
      console.log(week);
      multi.hmset(this.key, {
        key: this.key,
        date: this.date,
        time: this.time,
        name: this.name,
        amount: this.amount
      });
      multi.rpush(week, this.key);

      multi.exec(function (err, replies) {
        console.log(replies);
        if (err) {
          console.log('save trans ' + this.key + ': FAIL');
          reject(new Error(err));
          return false;
        }
{'fraction_non_alphanumeric': 0.15619480191773907, 'fraction_numerical': 0.0005046681806712087, 'mean_word_length': 3.0121457489878543, 'pattern_counts': {'":': 2, '<': 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': '4510315', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1269, 'n_words': 323}