<commit_before>module SparkleMotion
  module Audio
    # Class to track signal processing info, and report on it in a readable way.
    class StreamReporter < Task
      # Tiny helper just to let us do things like:
      #   some_metric.average[channel]
      # ... without having to vivify the average in advance.
      class Averager
        def initialize(sums, counts)
          @sums   = sums
          @counts = counts
        end

        def [](channel); @sums[channel] / @counts[channel]; end
      end

      # Records metrics about a particular measurement for each channel.
      class Metric
        def initialize
          @mins     = []
          @maxes    = []
          @sums     = []
          @currents = []
          @counts   = []
          @averager = Averager.new(@sums, @counts)
        end

        def min; @mins; end
        def max; @maxes; end
        def current; @currents; end
        def mean; @averager; end

        def length; @currents.length; end

        def []=(channel, val)
          @mins[channel]   ||= Float::INFINITY
          @mins[channel]     = val if val < @mins[channel]
          @maxes[channel]  ||= 0.0
          @maxes[channel]    = val if val > @maxes[channel]
          @sums[channel]   ||= 0.0
          @sums[channel]    += val
          @counts[channel] ||= 0.0
          @counts[channel]  += 1
          @currents[channel] = val
        end
      end

      attr_reader :name, :dc0, :minima, :maxima, :sum, :mean, :count, :dropped_frames

      def initialize(stream_name, interval, logger)
        @name           = stream_name
        @interval       = interval

        reset!

        super("StreamReporter", logger) do
          next if count == 0

          print_report

          sleep @interval
        end
      end

      def print_report
        title = "%s[%05d, %05d]:" % [@name, @count, @dropped_frames]
        @logger.info { title }
        (0..@max_channel).each do |ch|
          print_channel(ch)
        end
      end

      def record_channel(channel:, datum:)
        @dc0[channel] = datum[:dc0]
        @metrics.each do |name, metric|
          metric[channel] = datum.fetch(name)
        end
      end

      def record(dropped_frames:, data:)
        @dropped_frames = dropped_frames<commit_msg>Whoops, renamed this out from under myself.<commit_after>module SparkleMotion
  module Audio
    # Class to track signal processing info, and report on it in a readable way.
    class StreamReporter < Task
      # Tiny helper just to let us do things like:
      #   some_metric.average[channel]
      # ... without having to vivify the average in advance.
      class Averager
        def initialize(sums, counts)
          @sums   = sums
          @counts = counts
        end

        def [](channel); @sums[channel] / @counts[channel]; end
      end

      # Records metrics about a particular measurement for each channel.
      class Metric
        def initialize
          @mins     = []
          @maxes    = []
          @sums     = []
          @currents = []
          @counts   = []
          @averager = Averager.new(@sums, @counts)
        end

        def min; @mins; end
        def max; @maxes; end
        def current; @currents; end
        def mean; @averager; end

        def length; @currents.length; end

        def []=(channel, val)
          @mins[channel]   ||= Float::INFINITY
          @mins[channel]     = val if val < @mins[channel]
          @maxes[channel]  ||= 0.0
          @maxes[channel]    = val if val > @maxes[channel]
          @sums[channel]   ||= 0.0
          @sums[channel]    += val
          @counts[channel] ||= 0.0
          @counts[channel]  += 1
          @currents[channel] = val
        end
      end

      attr_reader :name, :dc0, :minima, :maxima, :sum, :mean, :count, :dropped_frames

      def initialize(stream_name, interval, logger)
        @name           = stream_name
        @interval       = interval

        reset!

        super("StreamReporter", logger) do
          next if @count == 0

          print_report

          sleep @interval
        end
      end

      def print_report
        title = "%s[%05d, %05d]:" % [@name, @count, @dropped_frames]
        @logger.info { title }
        (0..@max_channel).each do |ch|
          print_channel(ch)
        end
      end

      def record_channel(channel:, datum:)
        @dc0[channel] = datum[:dc0]
        @metrics.each do |name, metric|
          metric[channel] = datum.fetch(name)
        end
      end

      def record(dropped_frames:, data:)
        @dropped_frames = dropped_frames
{'fraction_non_alphanumeric': 0.10637372199260388, 'fraction_numerical': 0.006961061561888188, 'mean_word_length': 1.727164887307236, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '2129333', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1365, 'n_words': 385}