<commit_before>require "keen_native/version"
require 'eventmachine'
require 'fiddle'
require 'time'

module KeenNative
  libkeen = Fiddle.dlopen(File.dirname(__FILE__) + '/libkeen_native.so')
  @@cache_with_field_range = Fiddle::Function.new(
    libkeen['cache_with_field_range_c'],
    [Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT],
    Fiddle::TYPE_VOIDP
  )
  def self.cache_with_field_range(pfrom, pto, field, from, to, unique=false)
    if from.class != DateTime && to.class != DateTime
      raise "time must be in form datetime"
    end
    result = @@cache_with_field_range.call(pfrom.to_i, pto.to_i, field, from.iso8601, to.iso8601, unique ? 1 : 0)
    str = result.to_s
    self.dtor_str(result)
    str
  end

  @@get_with_field_range = Fiddle::Function.new(
    libkeen['get_with_field_range_c'],
    [Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT],
    Fiddle::TYPE_VOIDP
  )
  def self.get_with_field_range(pid, pfrom, pto, field, from, to, unique=false)
    if from.class != DateTime && to.class != DateTime
      raise "time must be in form datetime"
    end
    result = @@get_with_field_range.call(pid.to_i, pfrom.to_i, pto.to_i, field, from.iso8601, to.iso8601, unique ? 1 : 0)
    str = result.to_s
    self.dtor_str(result)
    str
  end

  @@cache_page_view_range = Fiddle::Function.new(
    libkeen['cache_page_view_range_c'],
    [Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP],
    Fiddle::TYPE_VOIDP
  )
  def self.cache_page_view_range(pfrom, pto, from, to, unique=false, interval="")
    if from.class != DateTime && to.class != DateTime
      raise "time must be in form datetime"
    end
    result = @@cache_page_view_range.call(pfrom.to_i, pto.to_i, from.iso8601, to.iso8601, unique ? 1 : 0, interval)
    str = result.to_s
    self.dtor_str(result)
    str
  end

  @@get_page_view_range = Fiddle::Function.new(
    libkeen['get_page_view_range_c'],
    [Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP],
    Fiddle::TYPE_VOIDP
  )
  def self.get_page_view_range(pid, pfrom, pto, from, to, unique=false, interval="")
    if from.class != DateTime && to.class != DateTime
      raise "time must be in form datetime"
    end
    result = @@get_page_view_range.call(pid.to_i, pfrom.to_i, pto.to_i, from.iso8601, to.iso8601, unique ? 1 : 0, interval)
    str = result.to_s
    self.dtor_str(result)
    str
  end

  @@dealloc_str = Fiddle::Function.new(
    libkeen['dealloc_str'],
    [Fiddle::TYPE_VOIDP],
    Fiddle::TYPE_VOID
  )

  private
  def self.dtor_str(str)
    @@dealloc_str.call(str)
  end
end<commit_msg>make from and to date accept more type<commit_after>require "keen_native/version"
require 'eventmachine'
require 'fiddle'
require 'time'

module KeenNative
  libkeen = Fiddle.dlopen(File.dirname(__FILE__) + '/libkeen_native.so')
  @@cache_with_field_range = Fiddle::Function.new(
    libkeen['cache_with_field_range_c'],
    [Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT],
    Fiddle::TYPE_VOIDP
  )
  def self.cache_with_field_range(pfrom, pto, field, from, to, unique=false)
    from = DateTime.parse(from.to_s)
    to = DateTime.parse(to.to_s)
    result = @@cache_with_field_range.call(pfrom.to_i, pto.to_i, field, from.iso8601, to.iso8601, unique ? 1 : 0)
    str = result.to_s
    self.dtor_str(result)
    str
  end

  @@get_with_field_range = Fiddle::Function.new(
    libkeen['get_with_field_range_c'],
    [Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT],
    Fiddle::TYPE_VOIDP
  )
  def self.get_with_field_range(pid, pfrom, pto, field, from, to, unique=false)
    from = DateTime.parse(from.to_s)
    to = DateTime.parse(to.to_s)
    result = @@get_with_field_range.call(pid.to_i, pfrom.to_i, pto.to_i, field, from.iso8601, to.iso8601, unique ? 1 : 0)
    str = result.to_s
    self.dtor_str(result)
    str
  end

  @@cache_page_view_range = Fiddle::Function.new(
    libkeen['cache_page_view_range_c'],
    [Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP],
    Fiddle::TYPE_VOIDP
  )
  def self.cache_page_view_range(pfrom, pto, from, to, unique=false, interval="")
    from = DateTime.parse(from.to_s)
    to = DateTime.parse(to.to_s)
    result = @@cache_page_view_range.call(pfrom.to_i, pto.to_i, from.iso8601, to.iso8601, unique ? 1 : 0, interval.to_s)
    str = result.to_s
    self.dtor_str(result)
    str
  end

  @@get_page_view_range = Fiddle::Function.new(
    libkeen['get_page_view_range_c'],
    [Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP],
    Fiddle::TYPE_VOIDP
  )
  def self.get_page_view_range(pid, pfrom, pto, from, to, unique=false, interval="")
    from = DateTime.parse(from.to_s)
    to = DateTime.parse(to.to_s)
    result = @@get_page_view_range.call(pid.to_i, pfrom.to_i, pto.to_i, from.iso8601, to.iso8601, unique ? 1 : 0, interval.to_s)
    str = result.to_s
    self.dtor_str(result)
    str
  end

  @@dealloc_str = Fiddle::Function.new(
    libkeen['dealloc_str'],
    [Fiddle::TYPE_VOIDP],
    Fiddle::TYPE_VOID
  )

  private
  def self.dtor_str(str)
    @@dealloc_str.call(str)
  end
end
{'fraction_non_alphanumeric': 0.13400035733428622, 'fraction_numerical': 0.014293371448990531, 'mean_word_length': 4.488235294117647, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '187818', 'n_tokens_mistral': 2298, 'n_tokens_neox': 2217, 'n_words': 382}