<commit_before>require 'time'
require 'dogapi/v1'

module Dogapi

  # A simple DogAPI client
  #
  # See Dogapi::EventService and Dogapi::MetricService for the thick underlying clients
  class Client

    # Create a new Client optionally specifying a default host and device
    def initialize(api_key, application_key=nil, host=nil, device=nil)

      if api_key
        @api_key = api_key
      else
        raise 'Please provide an API key to submit your data'
      end

      @application_key = application_key

      @datadog_host = Dogapi.find_datadog_host()

      @host = host
      @device = device

      @metric_svc = Dogapi::V1::MetricService.new(@api_key, @application_key)
      @event_svc = Dogapi::V1::EventService.new(@api_key, @application_key)
      @legacy_event_svc = Dogapi::EventService.new(@datadog_host)
    end

    # Record a single point of metric data
    #
    # Optional arguments:
    #  :timestamp => Ruby stdlib Time
    #  :host      => String
    #  :device    => String
    def emit_point(metric, value, options={})
      defaults = {:timestamp => Time.now, :host => nil, :device => nil}
      options = defaults.merge(options)

      self.emit_points(metric,
                       [[options[:timestamp], value]],
                       :host => options[:host],
                       :device => options[:device])
    end

    # Record a set of points of metric data
    #
    # +points+ is an array of <tt>[Time, value]</tt> doubles
    #
    # Optional arguments:
    #  :host   => String
    #  :device => String
    def emit_points(metric, points, options={})
      defaults = {:host => nil, :device => nil}
      options = defaults.merge(options)

      scope = override_scope options[:host], options[:device]

      points.each do |p|
        p[0].kind_of? Time or raise "Not a Time"
        p[1].to_f # TODO: stupid to_f will never raise and exception
      end

      @metric_svc.submit(metric, points, scope)
    end

    # Record an event
    #
    # Optional arguments:
    #  :host        => String
    #  :device      => String
    def emit_event(event, options={})
      defaults = {:host => nil, :device => nil}
      options = defaults.merge(options)

      scope = override_scope(options[:host], options[:device])

      @event_svc.submit(event, scope)
    end
<commit_msg>convert ruby time object to an actual POSIX timestamp<commit_after>require 'time'
require 'dogapi/v1'

module Dogapi

  # A simple DogAPI client
  #
  # See Dogapi::EventService and Dogapi::MetricService for the thick underlying clients
  class Client

    # Create a new Client optionally specifying a default host and device
    def initialize(api_key, application_key=nil, host=nil, device=nil)

      if api_key
        @api_key = api_key
      else
        raise 'Please provide an API key to submit your data'
      end

      @application_key = application_key

      @datadog_host = Dogapi.find_datadog_host()

      @host = host
      @device = device

      @metric_svc = Dogapi::V1::MetricService.new(@api_key, @application_key)
      @event_svc = Dogapi::V1::EventService.new(@api_key, @application_key)
      @legacy_event_svc = Dogapi::EventService.new(@datadog_host)
    end

    # Record a single point of metric data
    #
    # Optional arguments:
    #  :timestamp => Ruby stdlib Time
    #  :host      => String
    #  :device    => String
    def emit_point(metric, value, options={})
      defaults = {:timestamp => Time.now, :host => nil, :device => nil}
      options = defaults.merge(options)

      self.emit_points(metric,
                       [[options[:timestamp], value]],
                       :host => options[:host],
                       :device => options[:device])
    end

    # Record a set of points of metric data
    #
    # +points+ is an array of <tt>[Time, value]</tt> doubles
    #
    # Optional arguments:
    #  :host   => String
    #  :device => String
    def emit_points(metric, points, options={})
      defaults = {:host => nil, :device => nil}
      options = defaults.merge(options)

      scope = override_scope options[:host], options[:device]

      points.each do |p|
        p[0].kind_of? Time or raise "Not a Time"
        p[0] = p[0].to_i
        p[1] = p[1].to_f # TODO: stupid to_f will never raise an exception
      end

      @metric_svc.submit(metric, points, scope)
    end

    # Record an event
    #
    # Optional arguments:
    #  :host        => String
    #  :device      => String
    def emit_event(event, options={})
      defaults = {:host => nil, :device => nil}
      options = defaults.merge(options)

      scope = override_scope(options[:host], options[:device])

      @event_svc.submit(event, scope)
    end

{'fraction_non_alphanumeric': 0.11144005075068725, 'fraction_numerical': 0.002748995559314866, 'mean_word_length': 2.4907749077490773, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 39, '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': '1637905', 'n_tokens_mistral': 1443, 'n_tokens_neox': 1388, 'n_words': 399}