<commit_before># Kontrol is a class for communicating with the Kontrol Kite.
# In our application, there is only one instance of this and it can be
# reachable from KD.getSingleton("kontrol").
class Kontrol extends KDObject

  constructor: (options={})->
    super options

    kite =
      name     : "kontrol"
      publicIP : "#{KD.config.newkontrol.host}"
      port     : "#{KD.config.newkontrol.port}"

    authentication =
      type     : "sessionID"
      key      : KD.remote.getSessionToken()

    @kite = new NewKite kite, authentication
    @kite.connect()

  # getKites Calls the callback function with the list of NewKite instances.
  # The returned kites are not connected. You must connect with
  # NewKite.connect().
  #
  # Query parameters are below from general to specific:
  #
  #   username    string
  #   environment string
  #   name        string
  #   version     string
  #   region      string
  #   hostname    string
  #   id          string
  #
  getKites: (query={}, callback = noop)->
    query = @_sanitizeQuery query

    @kite.tell "getKites", [query], (res)=>
      err = res.withArgs[0]
      kites = res.withArgs[1]
      return callback err, null  if err

      kiteInstances = []
      for k in kites
        kiteInstances.push @_createKite k

      callback null, kiteInstances


  # watchKites watches for Kites that matches the query. The onEvent functions
  # is called for current kites and every new kite event.
  watchKites: (query={}, callback)->
    return warn "callback is not defined "  unless callback

    query = @_sanitizeQuery query

    onEvent = (e)=>
      log "kite event: ", e.action, {e}
      callback e.action, @_createKite {kite: e.kite, token: e.token}

    args = [query, onEvent]

    @kite.tell "getKites", args, (res)=>
      err = res.withArgs[0]
      kites = res.withArgs[1]
      return callback err, null  if err

      for k in kites
        e =
          action : @KiteAction.Register
          kite   : k
          token  : k.authentication.key

        callback e.action, @_createKite {kite: e.kite, token: e.token}

  # Returns a new NewKite instance from Kite data structure coming from
  # getKites() and watchKites() methods.
  _createKite: (k)->
    return new NewKite k.kite, {type: "token", key: k.token}<commit_msg>kontrol.coffee: make it coffee style<commit_after># Kontrol is a class for communicating with the Kontrol Kite.
# In our application, there is only one instance of this and it can be
# reachable from KD.getSingleton("kontrol").
class Kontrol extends KDObject

  constructor: (options={})->
    super options

    kite =
      name     : "kontrol"
      publicIP : "#{KD.config.newkontrol.host}"
      port     : "#{KD.config.newkontrol.port}"

    authentication =
      type     : "sessionID"
      key      : KD.remote.getSessionToken()

    @kite = new NewKite kite, authentication
    @kite.connect()

  # getKites Calls the callback function with the list of NewKite instances.
  # The returned kites are not connected. You must connect with
  # NewKite.connect().
  #
  # Query parameters are below from general to specific:
  #
  #   username    string
  #   environment string
  #   name        string
  #   version     string
  #   region      string
  #   hostname    string
  #   id          string
  #
  getKites: (query={}, callback = noop)->
    query = @_sanitizeQuery query

    @kite.tell "getKites", [query], (res)=>
      [err, kites] = res.withArgs
      return callback err, null  if err

      kiteInstances = []
      for k in kites
        kiteInstances.push @_createKite k

      callback null, kiteInstances


  # watchKites watches for Kites that matches the query. The onEvent functions
  # is called for current kites and every new kite event.
  watchKites: (query={}, callback)->
    return warn "callback is not defined "  unless callback

    query = @_sanitizeQuery query

    onEvent = (e)=>
      log "kite event: ", e.action, {e}
      callback e.action, @_createKite {kite: e.kite, token: e.token}

    args = [query, onEvent]

    @kite.tell "getKites", args, (res)=>
      [err, kites] = res.withArgs
      return callback err, null  if err

      for k in kites
        e =
          action : @KiteAction.Register
          kite   : k
          token  : k.authentication.key

        callback e.action, @_createKite {kite: e.kite, token: e.token}

  # Returns a new NewKite instance from Kite data structure coming from
  # getKites() and watchKites() methods.
  _createKite: (k)->
    return new NewKite k.kite, {type: "token", key: k.token}
{'fraction_non_alphanumeric': 0.09631728045325778, 'fraction_numerical': 0.0008716495968620615, 'mean_word_length': 2.4984756097560976, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '3036', 'n_tokens_mistral': 1476, 'n_tokens_neox': 1420, 'n_words': 479}