<commit_before>require_relative 'base_write'

module WavefrontCli
  #
  # Send points via a proxy. This inherits from the same base class
  # as Report, but has to do a couple of things differently, as it
  # speaks to a proxy rather than to the API.
  #
  class Write < BaseWrite
    # rubocop:disable Metrics/AbcSize
    def do_distribution
      p = { path:     options[:'<metric>'],
            interval: options[:interval] || 'M',
            value:    mk_dist,
            tags:     tags_to_hash(options[:tag]) }

      p[:source] = options[:host] if options[:host]
      p[:ts] = parse_time(options[:time]) if options[:time]
      send_point(p)
    end
    # rubocop:enable Metrics/AbcSize

    # Turn our user's representation of a distribution into one
    # which suits Wavefront. The SDK can do this for us.
    #
    def mk_dist
      xpanded = expand_dist(options[:'<val>'])
      wf.mk_distribution(xpanded.map(&:to_f))
    end

    def extra_options
      options[:using] ? { writer: options[:using] } : {}
    end

    # I chose to prioritise UI consistency over internal elegance
    # here. The `write` command doesn't follow the age-old
    # assumption that each command maps 1:1 to a similarly named SDK
    # class. Write can use `write` or `distribution`.
    #
    def _sdk_class
      return 'Wavefront::Distribution' if distribution?
      'Wavefront::Write'
    end

    def distribution?
      return true if options[:distribution]
      options[:infileformat] && options[:infileformat].include?('d')
    end

    def mk_creds
      { proxy: options[:proxy], port: options[:port] || default_port }
    end

    def default_port
      distribution? ? 40000 : 2878
    end<commit_msg>pass all creds to write<commit_after>require_relative 'base_write'

module WavefrontCli
  #
  # Send points via a proxy. This inherits from the same base class
  # as Report, but has to do a couple of things differently, as it
  # speaks to a proxy rather than to the API.
  #
  class Write < BaseWrite
    # rubocop:disable Metrics/AbcSize
    def do_distribution
      p = { path:     options[:'<metric>'],
            interval: options[:interval] || 'M',
            value:    mk_dist,
            tags:     tags_to_hash(options[:tag]) }

      p[:source] = options[:host] if options[:host]
      p[:ts] = parse_time(options[:time]) if options[:time]
      send_point(p)
    end
    # rubocop:enable Metrics/AbcSize

    # Turn our user's representation of a distribution into one
    # which suits Wavefront. The SDK can do this for us.
    #
    def mk_dist
      xpanded = expand_dist(options[:'<val>'])
      wf.mk_distribution(xpanded.map(&:to_f))
    end

    def extra_options
      options[:using] ? { writer: options[:using] } : {}
    end

    # I chose to prioritise UI consistency over internal elegance
    # here. The `write` command doesn't follow the age-old
    # assumption that each command maps 1:1 to a similarly named SDK
    # class. Write can use `write` or `distribution`.
    #
    def _sdk_class
      return 'Wavefront::Distribution' if distribution?
      'Wavefront::Write'
    end

    def distribution?
      return true if options[:distribution]
      options[:infileformat] && options[:infileformat].include?('d')
    end

    def mk_creds
      { proxy:    options[:proxy],
        port:     options[:port] || default_port,
        endpoint: options[:endpoint],
        token:    options[:token] }
    end

    def default_port
      distribution? ? 40000 : 2878
    end
{'fraction_non_alphanumeric': 0.10005685048322911, 'fraction_numerical': 0.0062535531552018195, 'mean_word_length': 2.723809523809524, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '1750746', 'n_tokens_mistral': 1088, 'n_tokens_neox': 1023, 'n_words': 335}