<commit_before>require 'rubygems'
require 'json'
require 'eventmachine'

module KinectMachine
  @video_modes = 0
  @video_mode = 0
  @depth_modes = 0
  @depth_mode = 0
  @video_formats = [:freenect_video_rgb, :freenect_video_bayer, :freenect_video_ir_8bit, :freenect_video_ir_10bit,
                    :freenect_video_ir_10bit_packed, :freenect_video_yuv_rgb, :freenect_video_yuv_raw]
  @video_format = 0
  @depth_formats = [:freenect_depth_11bit, :freenect_depth_10bit, :freenect_depth_11bit_packed, :freenect_depth_10bit_packed]
  @depth_format = 0

  class << self
    attr_accessor :video_modes, :video_mode, :depth_modes, :depth_mode, :video_formats, :video_format, :depth_formats, :depth_format
  end

  def post_init
    puts "CONNECTED"
    EventMachine.next_tick do
      send_data({:action => :get_video_mode_count}.to_json)
    end
 end

  def receive_data(data)
    msg = JSON.parse(data)
    if msg['status'].eql?('success')
      send(msg['action'].to_sym, msg['data'])
    else
      puts "ERROR: ACTION=#{msg['action']}, MESSAGE=#{msg['message']}"
      EventMachine.stop_event_loop
    end
  end

  def unbind
    puts "CLOSED"
    EventMachine.stop_event_loop
  end

  def get_video_mode_count(data)
    KinectMachine.video_modes = data['video_mode_count']
    puts "VIDEO MODE COUNT: #{KinectMachine.video_modes}"
    send_data({:action => :get_video_mode, :params => {:video_mode_id => KinectMachine.video_mode}}.to_json)
  end

  def get_video_mode(data)
    puts "VIDEO MODE: #{data.inspect}"
    KinectMachine.video_mode +=1
    if KinectMachine.video_mode < KinectMachine.video_modes
      send_data({:action => :get_video_mode, :params => {:video_mode_id => KinectMachine.video_mode}}.to_json)
    else
      send_data({:action => :get_depth_mode_count}.to_json)
    end
  end

  def get_depth_mode_count(data)
    KinectMachine.depth_modes = data['depth_mode_count']
    puts "DEPTH MODE COUNT: #{KinectMachine.depth_modes}"
    send_data({:action => :get_depth_mode, :params => {:depth_mode_id => KinectMachine.depth_mode}}.to_json)
  end

  def get_depth_mode(data)
    puts "DEPTH MODE: #{data.inspect}"
    KinectMachine.depth_mode +=1
    if KinectMachine.depth_mode < KinectMachine.depth_modes
      send_data({:action => :get_depth_mode, :params => {:depth_mode_id => KinectMachine.depth_mode}}.to_json)
    else
      EventMachine.stop_event_loop
    end
  end

end

EventMachine::run do
  EventMachine::connect '10.0.1.253', 8008, KinectMachine
end

<commit_msg>added video and depth mode query by format<commit_after>require 'rubygems'
require 'json'
require 'eventmachine'

module KinectMachine
  @video_modes = 0
  @video_mode = 0
  @depth_modes = 0
  @depth_mode = 0
  @video_formats = [:freenect_video_rgb, :freenect_video_bayer, :freenect_video_ir_8bit, :freenect_video_ir_10bit,
                    :freenect_video_ir_10bit_packed, :freenect_video_yuv_rgb, :freenect_video_yuv_raw]
  @video_format = 0
  @depth_formats = [:freenect_depth_11bit, :freenect_depth_10bit, :freenect_depth_11bit_packed, :freenect_depth_10bit_packed]
  @depth_format = 0

  class << self
    attr_accessor :video_modes, :video_mode, :depth_modes, :depth_mode, :video_formats, :video_format, :depth_formats, :depth_format
  end

  def post_init
    puts "CONNECTED"
    EventMachine.next_tick do
      send_data({:action => :get_video_mode_count}.to_json)
    end
 end

  def receive_data(data)
    msg = JSON.parse(data)
    if msg['status'].eql?('success')
      send(msg['action'].to_sym, msg['data'])
    else
      puts "ERROR: ACTION=#{msg['action']}, MESSAGE=#{msg['message']}"
      EventMachine.stop_event_loop
    end
  end

  def unbind
    puts "CLOSED"
    EventMachine.stop_event_loop
  end

  def get_video_mode_count(data)
    KinectMachine.video_modes = data['video_mode_count']
    puts "VIDEO MODE COUNT: #{KinectMachine.video_modes}"
    send_data({:action => :get_video_mode, :params => {:video_mode_id => KinectMachine.video_mode}}.to_json)
  end

  def get_video_mode(data)
    puts "VIDEO MODE: #{data.inspect}"
    KinectMachine.video_mode +=1
    if KinectMachine.video_mode < KinectMachine.video_modes
      send_data({:action => :get_video_mode, :params => {:video_mode_id => KinectMachine.video_mode}}.to_json)
    elsif KinectMachine.video_format < KinectMachine.video_formats.length
       puts "GET VIDEO MODE FOR FORMAT: #{KinectMachine.video_formats[KinectMachine.video_format]}"
       send_data({:action => :get_video_mode, :params => {:video_format => KinectMachine.video_formats[KinectMachine.video_format]}}.to_json)
       KinectMachine.video_format += 1
    else
      send_data({:action => :get_depth_mode_count}.to_json)
    end
  end

  def get_depth_mode_count(data)
    KinectMachine.depth_modes = data['depth_mode_count']
    puts "DEPTH MODE COUNT: #{KinectMachine.depth_modes}"
    send_data({:action => :get_depth_mode, :params => {:depth_mode_id => KinectMachine.depth_mode}}.to_json)
  end

  def get_depth_mode(data)
    puts "DEPTH MODE: #{data.inspect}"
    KinectMachine.depth_mode +=1
    if KinectMachine.depth_mode < KinectMachine.depth_modes
      send_data({:action => :get_depth_mode, :params => {:depth_mode_id => KinectMachine.depth_mode}}.to_json)
    elsif KinectMachine.depth_format < KinectMachine.depth_formats.length
       puts "GET DEPTH MODE FOR FORMAT: #{KinectMachine.depth_formats[KinectMachine.depth_format]}"
       send_data({:action => :get_depth_mode, :params => {:depth_format => KinectMachine.depth_formats[KinectMachine.depth_format]}}.to_json)
       KinectMachine.depth_format += 1
    else
      EventMachine.stop_event_loop
    end
  end

end

EventMachine::run do
  EventMachine::connect '10.0.1.253', 8008, KinectMachine
end


{'fraction_non_alphanumeric': 0.11368788142981691, 'fraction_numerical': 0.01150828247602441, 'mean_word_length': 4.634577603143418, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '4176078', 'n_tokens_mistral': 2172, 'n_tokens_neox': 2089, 'n_words': 353}