<commit_before>define(function (require) {

  var Backbone = require('backbone');

  function isRelevant(model, identityId) {
        // using double ~ to convert string to number
        return model.id && model.get('identity') &&
            ~~model.get('identity').id === identityId;

  }

  return Backbone.Model.extend({

    parse: function (attributes) {

      // put default allocation data here since it isn't
      // in the data structure for admins (but we want it
      // in the object for consistency)
      if (!attributes.allocation) {
        attributes.allocation = {
          current: 10,
          threshold: 168
        }
      }

      // todo: put this in the API
      if (attributes.allocation.current === null || attributes.allocation.current === undefined) {
        attributes.allocation.current = 777;
      }

      return attributes;
    },

    getInstancesConsumingAllocation: function (instances) {
      var identityId = this.id;

      return instances.filter(function (instance) {
        if (isRelevant(instance, identityId)) {
          return instance.get('status') !== "suspended";
        } else {
          return false;
        }
      });
    },

    getCpusUsed: function (instances, sizes) {
      var identityId = this.id;

      return instances.reduce(function (total, instance) {
        if (isRelevant(instance, identityId)) {
          var size = sizes.get(instance.get('size').id);
          return total + size.get('cpu');
        } else {
          return total;
        }
      }, 0);
    },

    getMemoryUsed: function (instances, sizes) {
      var identityId = this.id;

      return instances.reduce(function (total, instance) {
        if (isRelevant(instance, identityId)) {

          var size = sizes.get(instance.get('size').id);
          return total + size.get('mem');
        } else {
          return total;
        }
      }, 0);
    },

    getStorageUsed: function (volumes) {
      var identityId = this.id;

      return volumes.reduce(function (total, volume) {
        if (isRelevant(volume, identityId)) {
          var size = volume.get('size');
          return total + size;
        } else {
          return total;
        }
      }, 0);
    },

    getStorageCountUsed: function (volumes) {
      var identityId = this.id;

      return volumes.reduce(function (total, volume) {
        if (isRelevant(volume, identityId)) {
          return total + 1;
        } else {
          return total;
        }
      }, 0);
    }

  });

});
<commit_msg>Changed to filter by `active` status instances.<commit_after>define(function (require) {

  var Backbone = require('backbone');

  function isRelevant(model, identityId) {
        // using double ~ to convert string to number
        return model.id && model.get('identity') &&
            ~~model.get('identity').id === identityId;

  }

  return Backbone.Model.extend({

    parse: function (attributes) {

      // put default allocation data here since it isn't
      // in the data structure for admins (but we want it
      // in the object for consistency)
      if (!attributes.allocation) {
        attributes.allocation = {
          current: 10,
          threshold: 168
        }
      }

      // todo: put this in the API
      if (attributes.allocation.current === null || attributes.allocation.current === undefined) {
        attributes.allocation.current = 777;
      }

      return attributes;
    },

    getInstancesConsumingAllocation: function (instances) {
      var identityId = this.id;

      return instances.filter(function (instance) {
        if (isRelevant(instance, identityId)) {
          return instance.get('status') === "active";
        } else {
          return false;
        }
      });
    },

    getCpusUsed: function (instances, sizes) {
      var identityId = this.id;

      return instances.reduce(function (total, instance) {
        if (isRelevant(instance, identityId)) {
          var size = sizes.get(instance.get('size').id);
          return total + size.get('cpu');
        } else {
          return total;
        }
      }, 0);
    },

    getMemoryUsed: function (instances, sizes) {
      var identityId = this.id;

      return instances.reduce(function (total, instance) {
        if (isRelevant(instance, identityId)) {

          var size = sizes.get(instance.get('size').id);
          return total + size.get('mem');
        } else {
          return total;
        }
      }, 0);
    },

    getStorageUsed: function (volumes) {
      var identityId = this.id;

      return volumes.reduce(function (total, volume) {
        if (isRelevant(volume, identityId)) {
          var size = volume.get('size');
          return total + size;
        } else {
          return total;
        }
      }, 0);
    },

    getStorageCountUsed: function (volumes) {
      var identityId = this.id;

      return volumes.reduce(function (total, volume) {
        if (isRelevant(volume, identityId)) {
          return total + 1;
        } else {
          return total;
        }
      }, 0);
    }

  });

});

{'fraction_non_alphanumeric': 0.12095667516173299, 'fraction_numerical': 0.005097039796118408, 'mean_word_length': 1.9906213364595544, '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': '356042', 'n_tokens_mistral': 1466, 'n_tokens_neox': 1387, 'n_words': 364}