<commit_before>Bp  = require \babyparse
Fs  = require \fs
_   = require \lodash
Src = require \./source
Cfg = require \../config

module.exports = (req, res) ->
  err, csv <- Src.read
  return log err if err
  parsed = Bp.parse csv, skipEmptyLines:true
  txs = _.map parsed.data, ->
    [ date, code, payee, account, commodity, amount, status, notes ] = it
    tx =
      Year     : (dt = new Date date).getFullYear!
      Month    : <[Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec]>[dt.getMonth!]
      Day      : dt.getDate!
      Code     : code
      Payee    : payee
      Commodity: commodity
      Amount   : amount
      Status   : status
      Notes    : notes
    for i from 0 to 3 then tx[get-level-name i] = (account / \:)[i] or ''
    tx
  res.send options:Cfg.options, transactions:txs

function get-level-name n
  "Account-Level-#n"
  #function segment then if it is n then " Level #n " else '  '
  #  "#{segment 0}:#{segment 1}:#{segment 2}:#{segment 3}"<commit_msg>refactor<commit_after>Bp  = require \babyparse
Fs  = require \fs
_   = require \lodash
Src = require \./source
Cfg = require \../config

module.exports = (req, res) ->
  err, csv <- Src.read
  return log err if err
  parsed = Bp.parse csv, skipEmptyLines:true
  txs = _.map parsed.data, ->
    [ date, code, payee, account, commodity, amount, status, notes ] = it
    tx =
      Year     : (dt = new Date date).getFullYear!
      Month    : <[Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec]>[dt.getMonth!]
      Day      : dt.getDate!
      Code     : code
      Payee    : payee
      Commodity: commodity
      Amount   : amount
      Status   : status
      Notes    : notes
    for i from 0 to 3 then tx["Account-Level-#i"] = (account / \:)[i] or ''
    tx
  res.send options:Cfg.options, transactions:txs
{'fraction_non_alphanumeric': 0.12263099219620958, 'fraction_numerical': 0.004459308807134894, 'mean_word_length': 2.2755474452554743, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2931061', 'n_tokens_mistral': 622, 'n_tokens_neox': 599, 'n_words': 198}