<commit_before>define(['backbone', 'underscore'],
function (Backbone, _) {
    'use strict';

    var Element = Backbone.Model.extend({

        validParent: /\d+/,

        loaded: 0,

        url: function () {
            return '/api/datasets/' + this.dataset.get('id') + '/visualisations/' + this.visualisation.get('id') + '/elements/' + this.get('id');
        },

        initialize: function (options) {
            this.bind('change', this.change, this);

            // Set dataset and visualisation models
            this.dataset = options['dataset'];
            this.visualisation = options['visualisation'];

            // Get dimensions and observations models
            this.dimensions = [];
            this.observations = [];

            _.each(this.get('dimensions'), function (opts) {
                if (_.isUndefined(opts['field']['id'])) {
                    return;
                }

                var values = {
                        dimension: opts['field']['id'],
                        bucket: opts['bucket'],
                        measure: _.isNull(this.get('measure')) ? null : this.get('measure')['id'],
                        aggregation: this.get('aggregation')
                    },
                    observations = this.dataset.pool.getConnection(_.extend({type: 'observations'}, values)),
                    dimension = this.dataset.pool.getConnection(_.extend({type: 'dimensions'}, values));

                // Bind to sync event and keep references
                observations.bind('sync', this.change, this);
                this.observations.push(observations);

                dimension.bind('sync', this.change, this);
                this.dimensions.push(dimension);
            }, this);
        },

        /**
         * Dataset connection change event handler
         */
        change: function () {
            this.loaded++;
            this.trigger('ready', this);
        },

        /**
         * Return true if all required data has loaded
         */
        isLoaded: function () {
            // Check that all observations and dimensions have completed sync
            // and that isLoaded returns true
            return (
                ((this.loaded % (this.dimensions.length + this.observations.length)) === 0) &&
                    _.reduce(this.dimensions.concat(this.observations), function (memo, conn) {
                        return (memo && conn.isLoaded());
                    }, true)
                );<commit_msg>The element model isLoaded() function takes into account the dimensions that actually needs to be updated<commit_after>define(['backbone', 'underscore'],
function (Backbone, _) {
    'use strict';

    var Element = Backbone.Model.extend({

        validParent: /\d+/,

        loaded: 0,

        url: function () {
            return '/api/datasets/' + this.dataset.get('id') + '/visualisations/' + this.visualisation.get('id') + '/elements/' + this.get('id');
        },

        initialize: function (options) {
            this.bind('change', this.change, this);

            // Set dataset and visualisation models
            this.dataset = options['dataset'];
            this.visualisation = options['visualisation'];

            // Get dimensions and observations models
            this.dimensions = [];
            this.observations = [];

            _.each(this.get('dimensions'), function (opts) {
                if (_.isUndefined(opts['field']['id'])) {
                    return;
                }

                var values = {
                        dimension: opts['field']['id'],
                        bucket: opts['bucket'],
                        measure: _.isNull(this.get('measure')) ? null : this.get('measure')['id'],
                        aggregation: this.get('aggregation')
                    },
                    observations = this.dataset.pool.getConnection(_.extend({type: 'observations'}, values)),
                    dimension = this.dataset.pool.getConnection(_.extend({type: 'dimensions'}, values));

                // Bind to sync event and keep references
                observations.bind('sync', this.change, this);
                this.observations.push(observations);

                dimension.bind('sync', this.change, this);
                this.dimensions.push(dimension);
            }, this);
        },

        /**
         * Dataset connection change event handler
         */
        change: function () {
            this.loaded++;
            this.trigger('ready', this);
        },

        /**
         * Return true if all required data has loaded
         */
        isLoaded: function () {
            // Check that all observations and dimensions have completed sync
            // and that isLoaded returns true

            var dimensionsToUpdate = _.filter(this.dimensions, function (d) {
                var datasetField = this.dataset.fields.get(d.get('dimension'));

                // A dimension is fetched at least once.
                // When a cut is added/removed, a dimension it is updated
                // (re-fetched) only if the "update_dimension" field's attribute
                // is true
                return (!d.isLoaded() || (datasetField.get('update_dimension') === true));
            }, this);

            return (
                ((this.loaded % (dimensionsToUpdate.length + this.observations.length)) === 0) &&
                    _.reduce(this.dimensions.concat(this.observations), function (memo, conn) {
                        return (memo && conn.isLoaded());
                    }, true)
                );
{'fraction_non_alphanumeric': 0.130720113515431, 'fraction_numerical': 0.000709471443774388, 'mean_word_length': 1.593836246550138, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1870906', 'n_tokens_mistral': 1393, 'n_tokens_neox': 1295, 'n_words': 320}