<commit_before>define [
    '../core'
    '../base'
    '../charts'
    '../charts/utils'
    'tpl!templates/views/field-stats.html'
], (c, base, charts, utils, templates...) ->

    templates = c._.object ['layout'], templates


    class FieldStatValue extends c.Marionette.ItemView
        tagName: 'li'

        template: (data) ->
            "<span class=stat-label>#{ data.label }</span><span class=stat-value>#{ data.value }</span>"


    class FieldStatsValues extends c.Marionette.CollectionView
        tagName: 'ul'

        emptyView: base.EmptyView

        itemView: FieldStatValue


    class FieldStatsChart extends charts.FieldChart
        className: 'sparkline'

        chartOptions: c.Backbone.Sparkline::chartOptions

        getChartOptions: (resp) ->
            options =
                series: [utils.getSeries(resp.data)]

            c.$.extend true, options, @chartOptions
            options.chart.renderTo = @ui.chart[0]
            return options


    class FieldStats extends c.Marionette.Layout
        className: 'field-stats'

        template: templates.layout

        regions:
            values: '.stats-values'
            chart: '.stats-chart'

        onRender: ->
            if @model.stats?
                @values.show new FieldStatsValues
                    collection: @model.stats
                @model.stats.fetch(reset: true)


    { FieldStats }<commit_msg>Only re-fetch stats if the collection is empty<commit_after>define [
    '../core'
    '../base'
    '../charts'
    '../charts/utils'
    'tpl!templates/views/field-stats.html'
], (c, base, charts, utils, templates...) ->

    templates = c._.object ['layout'], templates


    class FieldStatValue extends c.Marionette.ItemView
        tagName: 'li'

        template: (data) ->
            "<span class=stat-label>#{ data.label }</span><span class=stat-value>#{ data.value }</span>"


    class FieldStatsValues extends c.Marionette.CollectionView
        tagName: 'ul'

        emptyView: base.EmptyView

        itemView: FieldStatValue


    class FieldStatsChart extends charts.FieldChart
        className: 'sparkline'

        chartOptions: c.Backbone.Sparkline::chartOptions

        getChartOptions: (resp) ->
            options =
                series: [utils.getSeries(resp.data)]

            c.$.extend true, options, @chartOptions
            options.chart.renderTo = @ui.chart[0]
            return options


    class FieldStats extends c.Marionette.Layout
        className: 'field-stats'

        template: templates.layout

        regions:
            values: '.stats-values'
            chart: '.stats-chart'

        onRender: ->
            if @model.stats?
                @values.show new FieldStatsValues
                    collection: @model.stats
                if not @model.stats.length
                    @model.stats.fetch(reset: true)


    { FieldStats }
{'fraction_non_alphanumeric': 0.11683848797250859, 'fraction_numerical': 0.0006872852233676976, 'mean_word_length': 1.934475806451613, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, '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': '7643354', 'n_tokens_mistral': 825, 'n_tokens_neox': 785, 'n_words': 180}