<commit_before>noflo = require("noflo")
_ = require("underscore")
_s = require("underscore.string")
print = require("node-print")
util = require("util")

format = "%13s | %s"
padding = "              | "
log = []
count = 0
options =
  showHidden: false
  depth: 2
  colors: false

flush = ->
  print.pf "%s", "---------- NEW STREAM ----------"

  for l in log.reverse()
    print.pf "%s", ""
    print.pf format, "CONNECT", ""
    display l
    print.pf format, "DISCONNECT", ""

  print.pf "%s", ""
  print.pf "%s", "--------------------------------"
  print.pf "%s", ""
  print.pf "%s", ""

  log = []

display = (log) ->
  for packet, i in log
    packet = util.inspect packet,
      options.showHidden, options.depth, options.colors
    packet = packet.replace /\n/g, "\n#{padding}"
    print.pf format, "DATA", packet
    delete log[i]

  for group, l of log
    print.pf format, "BEGINGROUP", group
    display l
    print.pf format, "ENDGROUP", group

class Log extends noflo.Component

  description: _s.clean "Log all packets, groups, and disconnects, to be
  displayed on next tick."

  constructor: ->
    @inPorts =
      in: new noflo.Port
      options: new noflo.Port
    @outPorts =
      out: new noflo.Port

    @inPorts.options.on "data", (otps) =>
      if _.isObject opts
        for own key, value of opts
          options[key] = value

    @inPorts.in.on "connect", =>
      count++
      @cache = []
      @groups = []

    @inPorts.in.on "begingroup", (group) =>
      here = @locate()
      here[group] ?= []
      @groups.push group
      @outPorts.out.beginGroup group if @outPorts.out.isAttached()

    @inPorts.in.on "data", (data) =>
      here = @locate()
      here.push data
      @outPorts.out.send data if @outPorts.out.isAttached()

    @inPorts.in.on "endgroup", (group) =>
      @groups.pop()
      @outPorts.out.endGroup() if @outPorts.out.isAttached()

    @inPorts.in.on "disconnect", =>
      @outPorts.out.disconnect() if @outPorts.out.isAttached()

      log.push @cache
      count--
      flush() if count is 0

  locate: ->
    here = @cache
    here = here[group] for group in @groups
    here

exports.getComponent = -> new Log
<commit_msg>Improve description<commit_after>noflo = require("noflo")
_ = require("underscore")
_s = require("underscore.string")
print = require("node-print")
util = require("util")

format = "%13s | %s"
padding = "              | "
log = []
count = 0
options =
  showHidden: false
  depth: 2
  colors: false

flush = ->
  print.pf "%s", "---------- NEW STREAM ----------"

  for l in log.reverse()
    print.pf "%s", ""
    print.pf format, "CONNECT", ""
    display l
    print.pf format, "DISCONNECT", ""

  print.pf "%s", ""
  print.pf "%s", "--------------------------------"
  print.pf "%s", ""
  print.pf "%s", ""

  log = []

display = (log) ->
  for packet, i in log
    packet = util.inspect packet,
      options.showHidden, options.depth, options.colors
    packet = packet.replace /\n/g, "\n#{padding}"
    print.pf format, "DATA", packet
    delete log[i]

  for group, l of log
    print.pf format, "BEGINGROUP", group
    display l
    print.pf format, "ENDGROUP", group

class Log extends noflo.Component

  description: _s.clean "Log all packets, groups, and disconnects, when
  the entire stream is complete."

  constructor: ->
    @inPorts =
      in: new noflo.Port
      options: new noflo.Port
    @outPorts =
      out: new noflo.Port

    @inPorts.options.on "data", (otps) =>
      if _.isObject opts
        for own key, value of opts
          options[key] = value

    @inPorts.in.on "connect", =>
      count++
      @cache = []
      @groups = []

    @inPorts.in.on "begingroup", (group) =>
      here = @locate()
      here[group] ?= []
      @groups.push group
      @outPorts.out.beginGroup group if @outPorts.out.isAttached()

    @inPorts.in.on "data", (data) =>
      here = @locate()
      here.push data
      @outPorts.out.send data if @outPorts.out.isAttached()

    @inPorts.in.on "endgroup", (group) =>
      @groups.pop()
      @outPorts.out.endGroup() if @outPorts.out.isAttached()

    @inPorts.in.on "disconnect", =>
      @outPorts.out.disconnect() if @outPorts.out.isAttached()

      log.push @cache
      count--
      flush() if count is 0

  locate: ->
    here = @cache
    here = here[group] for group in @groups
    here

exports.getComponent = -> new Log

{'fraction_non_alphanumeric': 0.17205279927173417, 'fraction_numerical': 0.002275830678197542, 'mean_word_length': 2.2847533632286994, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '2842515', 'n_tokens_mistral': 1536, 'n_tokens_neox': 1489, 'n_words': 389}