<commit_before>// npm
var chalk = require('chalk')
var Decimal = require('decimal.js')

// local
var Copper = require('../copper')
var copper = new Copper

module.exports = function(config, wallet, keys, args) {
  if(!keys) {
    if(args._.length > 0) {
      var firstWord = args._.shift()
      keys = [ copper.keyFromAddress(firstWord) ]
    } else {
      keys = wallet.keys
    }
  }

  console.log('gathering balances for', keys.length, 'keys')
  copper.balances(keys).then(function(balances, idx){
    var rows = []
    for(var idx in keys) {
      rows.push({pub:keys[idx].pub, satoshis:balances[idx]})
    }
    if(rows.length > 24) {
      rows.sort(function(a,b){return a.satoshis.minus(b.satoshis).toFixed()})
      rows = rows.filter(function(row){return row.satoshis > 0})
    }
    rows.forEach(function(row){
      var wkey = wallet.keys.filter(function(key){return key.pub == row.pub})[0]
      var parts = [row.pub]
      if(wkey) { parts.push(JSON.stringify(wkey.name))}
      parts.push(row.satoshis.div(100000000).toString())
      parts.push('BTC')
      console.log.apply(null, parts)
    })
    var total = balances.reduce(function(memo, balance){return memo.plus(balance)}, new Decimal(0))
    console.log('Total:', chalk.green(total.div(100000000)), 'BTC')
  })
}<commit_msg>make columns with fixed width floats<commit_after>// npm
var chalk = require('chalk')
var Decimal = require('decimal.js')

// local
var Copper = require('../copper')
var copper = new Copper

module.exports = function(config, wallet, keys, args) {
  if(!keys) {
    if(args._.length > 0) {
      var firstWord = args._.shift()
      keys = [ copper.keyFromAddress(firstWord) ]
    } else {
      keys = wallet.keys
    }
  }

  console.log('gathering balances for', keys.length, 'keys')
  copper.balances(keys).then(function(balances, idx){
    var rows = []
    for(var idx in keys) {
      rows.push({pub:keys[idx].pub, satoshis:balances[idx]})
    }
    if(rows.length > 24) {
      rows.sort(function(a,b){return a.satoshis.minus(b.satoshis).toFixed()})
      rows = rows.filter(function(row){return row.satoshis > 0})
    }
    rows.forEach(function(row){
      var wkey = wallet.keys.filter(function(key){return key.pub == row.pub})[0]
      var parts = [row.pub]
      parts.push(row.satoshis.div(100000000).toFixed(8))
      parts.push('BTC')
      if(wkey && wkey.name) { parts.push(JSON.stringify(wkey.name))}
      console.log.apply(null, parts)
    })
    var total = balances.reduce(function(memo, balance){return memo.plus(balance)}, new Decimal(0))
    console.log('Total:', chalk.green(total.div(100000000)), 'BTC')
  })
}
{'fraction_non_alphanumeric': 0.1709628506444276, 'fraction_numerical': 0.018574677786201668, 'mean_word_length': 3.3619834710743803, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '4084956', 'n_tokens_mistral': 961, 'n_tokens_neox': 912, 'n_words': 166}