<commit_before>var Promise = require('bluebird')
var log = require('npmlog')
var moment = require('moment-timezone')
var _ = require('lodash')
var config = require('config')
var questrade = require('../questrade').init(config.get('authorization_cron'))
var db = require('../db').connect()

function publishToDb (number, balances) {
  return new Promise(function (resolve, reject) {
    db.serialize(function () {
      var now = moment.tz('America/Toronto')
      now.millisecond(0)
      now.second(0)
      now.minute(0)
      now.hour(0)
      now.add(1, 'day')

      var delStmt = db.prepare('DELETE FROM mv WHERE number = ? AND date = ?')
      delStmt.run(number, now.add(1, 'day').unix(), function (err) {
        if (err) {
          reject(err)
        }
      })

      var insStmt = db.prepare('INSERT INTO mv VALUES(?, ?, ?, ?, ?, ?)')
      Promise.map(['CAD', 'USD'], function (cur) {
        return new Promise(function (resolve, reject) {
          log.info('sync', 'Storing market value for %s into db', cur)

          insStmt.run(
            number,
            now.unix(),
            cur,
            balances[cur].cash,
            balances[cur].totalEquity,
            balances[cur].cost,
            function (err) {
              if (err) {
                reject(err)
              }
            })
        }).then(resolve).error(reject)
      }).then(resolve).error(reject)
    })
  })
}

function storeDailyAccountMV (number, positions, balances) {
  var cash = {}<commit_msg>Don't skip forward another day. Fixes #15.<commit_after>var Promise = require('bluebird')
var log = require('npmlog')
var moment = require('moment-timezone')
var _ = require('lodash')
var config = require('config')
var questrade = require('../questrade').init(config.get('authorization_cron'))
var db = require('../db').connect()

function publishToDb (number, balances) {
  return new Promise(function (resolve, reject) {
    db.serialize(function () {
      var now = moment.tz('America/Toronto')
      now.millisecond(0)
      now.second(0)
      now.minute(0)
      now.hour(0)
      now.add(1, 'day')

      var delStmt = db.prepare('DELETE FROM mv WHERE number = ? AND date = ?')
      delStmt.run(number, now.unix(), function (err) {
        if (err) {
          reject(err)
        }
      })

      var insStmt = db.prepare('INSERT INTO mv VALUES(?, ?, ?, ?, ?, ?)')
      Promise.map(['CAD', 'USD'], function (cur) {
        return new Promise(function (resolve, reject) {
          log.info('sync', 'Storing market value for %s into db', cur)

          insStmt.run(
            number,
            now.unix(),
            cur,
            balances[cur].cash,
            balances[cur].totalEquity,
            balances[cur].cost,
            function (err) {
              if (err) {
                reject(err)
              }
            })
        }).then(resolve).error(reject)
      }).then(resolve).error(reject)
    })
  })
}

function storeDailyAccountMV (number, positions, balances) {
  var cash = {}
{'fraction_non_alphanumeric': 0.15516672169032683, 'fraction_numerical': 0.004291845493562232, 'mean_word_length': 2.2199787460148777, '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': '2949287', 'n_tokens_mistral': 942, 'n_tokens_neox': 919, 'n_words': 207}