<commit_before>BaseView = require 'views/base_view'

class UbretTool extends BaseView
  tagName: 'div'
  className: 'ubret-tool'
  nonDisplayKeys: ['id', 'uid', 'image']
  noDataTemplate: require './templates/no_data'

  initialize: ->
    if @model?
      @model.on 'change:selectedElements', @toolSelectElements
      @model.on 'change:selectedKey', @toolSelectKey
      @model.filters.on 'add reset', @toolAddFilters
      @model.settings.on 'change', @passSetting
      @model.on 'tool:dataProcessed', @render

    @$el.addClass @model.get('type')
    @$el.attr 'id', @id
    @tool = new Ubret[@model.get('type')]
      selector: '#' + @id
      el: @$el

  render: =>
    if (not @model.dataSource.data?) or (@model.dataSource.data.length is 0)
      @$el.html @noDataTemplate()
    else
      @$('.no-data').remove()
      data = @model.dataSource.data.map (datum) ->
        try
          return datum.toJSON()
        catch error
          return datum

      opts =
        data: data
        keys: @dataKeys data[0]
        filters: @model.filters.models
        selectedElements: @model.get('selectedElements')?.slice()
        selectedKey: @model.get('selectedKey')
        selectElementsCb: @selectElements
        selectKeyCb: @selectKey

      _.extend opts, @model.settings.toJSON()

      @tool.setOpts opts

      # This is Horrifically ugly
      if $("##{@id}").length isnt 0
        @tool.start()
      else
        setTimeout @tool.start, 500
    @

  dataKeys: (dataModel) =>
    keys = new Array
    for key, value of dataModel
      keys.push key unless key in @nonDisplayKeys<commit_msg>wait til call stack is cleared before starting tool<commit_after>BaseView = require 'views/base_view'

class UbretTool extends BaseView
  tagName: 'div'
  className: 'ubret-tool'
  nonDisplayKeys: ['id', 'uid', 'image']
  noDataTemplate: require './templates/no_data'

  initialize: ->
    if @model?
      @model.on 'change:selectedElements', @toolSelectElements
      @model.on 'change:selectedKey', @toolSelectKey
      @model.filters.on 'add reset', @toolAddFilters
      @model.settings.on 'change', @passSetting
      @model.on 'tool:dataProcessed', @render

    @$el.addClass @model.get('type')
    @$el.attr 'id', @id
    @tool = new Ubret[@model.get('type')]
      selector: '#' + @id
      el: @$el

  render: =>
    if (not @model.dataSource.data?) or (@model.dataSource.data.length is 0)
      @$el.html @noDataTemplate()
    else
      @$('.no-data').remove()
      data = @model.dataSource.data.map (datum) ->
        try
          return datum.toJSON()
        catch error
          return datum

      opts =
        data: data
        keys: @dataKeys data[0]
        filters: @model.filters.models
        selectedElements: @model.get('selectedElements')?.slice()
        selectedKey: @model.get('selectedKey')
        selectElementsCb: @selectElements
        selectKeyCb: @selectKey

      _.extend opts, @model.settings.toJSON()

      @tool.setOpts opts
      _.defer @tool.start
    @

  dataKeys: (dataModel) =>
    keys = new Array
    for key, value of dataModel
      keys.push key unless key in @nonDisplayKeys
{'fraction_non_alphanumeric': 0.1346031746031746, 'fraction_numerical': 0.0025396825396825397, 'mean_word_length': 2.668218859138533, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '2331377', 'n_tokens_mistral': 1003, 'n_tokens_neox': 982, 'n_words': 238}