<commit_before>import Ember from 'ember';
import DS from 'ember-data';

export default DS.Model.extend({
  name: DS.attr('string'),
  due: DS.attr('number'),
  amount: DS.attr('number'),
  //Geht in Budget rate: DS.attr('number'),
  percentage: Ember.computed('amount', 'balance', function(){return Math.floor(this.get('balance')/this.get('amount')*100);}),
  budget: DS.belongsTo('budget'),
  rate: Ember.computed.alias('budget.amount'),
  payments: Ember.computed.alias('budget.payments'),
  balance: Ember.computed('payments.@each.amount', function(){
    let payments = this.get('payments');
    let sum = 0;
    if(payments.length >0){
      let amounts = payments.mapBy('amount');
      amounts.forEach(function(amount){sum+= parseInt(amount);});
    }

    return sum;}),

});<commit_msg>Fixed a bug in the goal creation caused by undefined payments and zero amount<commit_after>import Ember from 'ember';
import DS from 'ember-data';

export default DS.Model.extend({
  name: DS.attr('string'),
  due: DS.attr('number'),
  amount: DS.attr('number'),
  //Geht in Budget rate: DS.attr('number'),
  percentage: Ember.computed('amount', 'balance', function(){
    if(Ember.isNone(this.get('amount'))){return 0;}
    return Math.floor(this.get('balance')/this.get('amount')*100);
  }),
  budget: DS.belongsTo('budget'),
  rate: Ember.computed.alias('budget.amount'),
  payments: Ember.computed.alias('budget.payments'),
  balance: Ember.computed('payments.@each.amount', function(){
    if(Ember.isNone(this.get('payments'))){
      Ember.Logger.log('hello');
      return 0;
    }
    let payments =this.get('payments');
    let sum = 0;
    if(payments.length >0){
      let amounts = payments.mapBy('amount');
      amounts.forEach(function(amount){sum+= parseInt(amount);});
    }

    return sum;}),

});
{'fraction_non_alphanumeric': 0.18818984547461368, 'fraction_numerical': 0.006622516556291391, 'mean_word_length': 4.493939393939394, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '1156020', 'n_tokens_mistral': 601, 'n_tokens_neox': 598, 'n_words': 122}