<commit_before>Config = {}

# ## function : safebind
safebind = (binder, target, event, callback) ->
  # safebind, binder binds to an event on target, which triggers callback.
  # Safe means that when the binder is destroyed, all callbacks are unbound.
  # callbacks are bound and evaluated in the context of binder.  Now that
  # backbone 0.99 is out, with listenTo and stopListening functions, which
  # manage event lifecycles, we probably don't need this function
  #
  # #### Parameters
  #
  # * binder : backbone model or view - when this is destroyed or removed,
  #   the callback
  #   unbound
  # * target : object triggering the event we want to bind to
  # * event : string, name of the event
  # * callback : callback for the event
  #
  # #### Returns
  #
  # * null
  #
  # stores objects we are binding events on, so that if we go away,
  # we can unbind all our events
  # currently, we require that the context being used is the binders context
  # this is because we currently unbind on a per context basis.  this can
  # be changed later if we need it
  if not _.has(binder, 'eventers')
    binder['eventers'] = {}
  try
    binder['eventers'][target.id] = target
  catch error

  # also need to bind destroy to remove obj from eventers.
  # no special logic needed to manage this life cycle, because
  # we will already unbind all listeners on target when binder goes away
  if target?
    target.on(event, callback, binder)
    target.on('destroy remove',
      () =>
        delete binder['eventers'][target]
      ,
        binder)
   else
    #debugger;
    console.log("error with binder", binder, event)
  return null

# backbone note - we're sort of using defaults in the code to tell the user
# what attributes are expected, so please specify defaults for
# all attributes you plan on usign

# Reference System
# we enable models to refer to other models using the following json
#
#     type : 'Plot'
#     id : '239009203923'
#
# The type field tell us that
# Collections.Plot is the collection which has the model id
# '239009203923'.

# ###function : load models.
load_models = (modelspecs)->
  # First we identify which model jsons correspond to new models,
  # and which ones are updates.
  # For new models we instantiate the models, add them
  # to their collections and call dinitialize.
  # For existing models we update
  # their attributes
  # ####Parameters
  # * modelspecs : list of models in json form, looking like this
  #
  #         type : 'Plot'
  #         id : '2390-23-23'
  #         attributes :
  #           firstattr : 'one'
  #         name : 'myplot'
  #         s : []
  #
  #   type is the key of the in collections for this model
  #   id is the id of this model
  #   attributes are the attributes of the model

  # ####Returns
  #
  # * null

  newspecs = []
  oldspecs = []

  # split out old and new models into arrays of
  # `[[collection, attributes], [collection, attributes]]`

  for model in modelspecs
    coll = Collections(model['type'])
    attrs = model['attributes']
    if coll and  coll.get(attrs['id'])
      oldspecs.push([coll, attrs])
    else
      newspecs.push([coll, attrs])

  # add new objects to collections silently
  for coll_attrs in newspecs
    [coll, attrs] = coll_attrs
    if coll
      coll.add(attrs, {'silent' : true})

  # call deferred initialize on all new models
  for coll_attrs in newspecs
    [coll, attrs] = coll_attrs
    if coll
      coll.get(attrs['id']).dinitialize(attrs)

  # set attributes on old models silently
  for coll_attrs in oldspecs
    [coll, attrs] = coll_attrs
    if coll
      coll.get(attrs['id']).set(attrs, {'local' : true, 'silent' : true})

  # trigger add events on all new models
  for coll_attrs in newspecs
    [coll, attrs] = coll_attrs
    if coll
      model = coll.get(attrs.id)
      model.trigger('add', model, coll, {});

  # trigger change events on all old models
  for coll_attrs in oldspecs
    [coll, attrs] = coll_attrs
    if coll
      coll.get(attrs['id']).change()

  return null


# ###class : WebsocketWrapper
# wraps websockets, provides a @connected promise, which
# you can wait on before sending subscription messages
# also triggers "msg:topic" events, with an arg of the msg
# data.  We assume that msg data over this websocket
# channel are sent in "topic:data" form, where data can
# be any arbitrary string. note that since topic is prefixed with :,
# in practice a message looks like bokehplot:docid:jsondata
class WebSocketWrapper
  _.extend(@prototype, Backbone.Events)
  # ### method :
  constructor : (ws_conn_string) ->
    @ws_conn_string = ws_conn_string
    @_connected = $.Deferred()
    @connected = @_connected.promise()
    try
      @s = new WebSocket(ws_conn_string)
    catch error
      @s = new MozWebSocket(ws_conn_string)
    @s.onopen = () =>
      @_connected.resolve()
    @s.onmessage = @onmessage
    return @<commit_msg>updated hem has more strict coffescript, remove 'return @' from constructor.<commit_after>Config = {}

# ## function : safebind
safebind = (binder, target, event, callback) ->
  # safebind, binder binds to an event on target, which triggers callback.
  # Safe means that when the binder is destroyed, all callbacks are unbound.
  # callbacks are bound and evaluated in the context of binder.  Now that
  # backbone 0.99 is out, with listenTo and stopListening functions, which
  # manage event lifecycles, we probably don't need this function
  #
  # #### Parameters
  #
  # * binder : backbone model or view - when this is destroyed or removed,
  #   the callback
  #   unbound
  # * target : object triggering the event we want to bind to
  # * event : string, name of the event
  # * callback : callback for the event
  #
  # #### Returns
  #
  # * null
  #
  # stores objects we are binding events on, so that if we go away,
  # we can unbind all our events
  # currently, we require that the context being used is the binders context
  # this is because we currently unbind on a per context basis.  this can
  # be changed later if we need it
  if not _.has(binder, 'eventers')
    binder['eventers'] = {}
  try
    binder['eventers'][target.id] = target
  catch error

  # also need to bind destroy to remove obj from eventers.
  # no special logic needed to manage this life cycle, because
  # we will already unbind all listeners on target when binder goes away
  if target?
    target.on(event, callback, binder)
    target.on('destroy remove',
      () =>
        delete binder['eventers'][target]
      ,
        binder)
   else
    #debugger;
    console.log("error with binder", binder, event)
  return null

# backbone note - we're sort of using defaults in the code to tell the user
# what attributes are expected, so please specify defaults for
# all attributes you plan on usign

# Reference System
# we enable models to refer to other models using the following json
#
#     type : 'Plot'
#     id : '239009203923'
#
# The type field tell us that
# Collections.Plot is the collection which has the model id
# '239009203923'.

# ###function : load models.
load_models = (modelspecs)->
  # First we identify which model jsons correspond to new models,
  # and which ones are updates.
  # For new models we instantiate the models, add them
  # to their collections and call dinitialize.
  # For existing models we update
  # their attributes
  # ####Parameters
  # * modelspecs : list of models in json form, looking like this
  #
  #         type : 'Plot'
  #         id : '2390-23-23'
  #         attributes :
  #           firstattr : 'one'
  #         name : 'myplot'
  #         s : []
  #
  #   type is the key of the in collections for this model
  #   id is the id of this model
  #   attributes are the attributes of the model

  # ####Returns
  #
  # * null

  newspecs = []
  oldspecs = []

  # split out old and new models into arrays of
  # `[[collection, attributes], [collection, attributes]]`

  for model in modelspecs
    coll = Collections(model['type'])
    attrs = model['attributes']
    if coll and  coll.get(attrs['id'])
      oldspecs.push([coll, attrs])
    else
      newspecs.push([coll, attrs])

  # add new objects to collections silently
  for coll_attrs in newspecs
    [coll, attrs] = coll_attrs
    if coll
      coll.add(attrs, {'silent' : true})

  # call deferred initialize on all new models
  for coll_attrs in newspecs
    [coll, attrs] = coll_attrs
    if coll
      coll.get(attrs['id']).dinitialize(attrs)

  # set attributes on old models silently
  for coll_attrs in oldspecs
    [coll, attrs] = coll_attrs
    if coll
      coll.get(attrs['id']).set(attrs, {'local' : true, 'silent' : true})

  # trigger add events on all new models
  for coll_attrs in newspecs
    [coll, attrs] = coll_attrs
    if coll
      model = coll.get(attrs.id)
      model.trigger('add', model, coll, {});

  # trigger change events on all old models
  for coll_attrs in oldspecs
    [coll, attrs] = coll_attrs
    if coll
      coll.get(attrs['id']).change()

  return null


# ###class : WebsocketWrapper
# wraps websockets, provides a @connected promise, which
# you can wait on before sending subscription messages
# also triggers "msg:topic" events, with an arg of the msg
# data.  We assume that msg data over this websocket
# channel are sent in "topic:data" form, where data can
# be any arbitrary string. note that since topic is prefixed with :,
# in practice a message looks like bokehplot:docid:jsondata
class WebSocketWrapper
  _.extend(@prototype, Backbone.Events)
  # ### method :
  constructor : (ws_conn_string) ->
    @ws_conn_string = ws_conn_string
    @_connected = $.Deferred()
    @connected = @_connected.promise()
    try
      @s = new WebSocket(ws_conn_string)
    catch error
      @s = new MozWebSocket(ws_conn_string)
    @s.onopen = () =>
      @_connected.resolve()
    @s.onmessage = @onmessage
{'fraction_non_alphanumeric': 0.09147945759967618, 'fraction_numerical': 0.007083586318558996, 'mean_word_length': 3.0404742436631236, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '5799900', 'n_tokens_mistral': 2996, 'n_tokens_neox': 2907, 'n_words': 1172}