<commit_before>'use strict';

(function() {
  var planner = angular.module('cashewApp.Planner', ['ngRoute']);

  planner.config(['$routeProvider', function($routeProvider) {
    $routeProvider.when('/plan', {
      templateUrl: 'views/Planner/Planner.html',
      controller: 'Planner',
      controllerAs: 'planner'
    });
  }]);

  planner.controller('Planner', ['$scope', 'LineItemsService', function($scope, LineItemsService) {
    var me = this;
    var getMonthlyAmountGraphParts = function(lineItems) {
      var debt_amt = 0;
      var pay_amt = 0;
      var aside_amt = 0;
      var total = 0;
      lineItems.forEach(function(item) {
        if (item.freq.per === 'yr' && item.type === 'minus'/* && item.freq.split*/) {
          aside_amt += item.amount / 12;
          return;
        }
        if (item.freq.per !== 'mo') {
          return;
        }
        if (item.type === 'minus') {
          debt_amt += item.amount;
        } else if (item.type === 'plus') {
          pay_amt += item.amount;
        }
      });
      total = debt_amt + pay_amt + aside_amt;
      return (total > 0) ? [
        {name: 'Monthly payments', color: '#FF4747', width: Math.round(debt_amt / total * 100)},
        {name: 'Yearly payment set-asides', color: '#FFDD45', width: Math.round(aside_amt / total * 100)},
        {name: 'Monthly income', color: '#A5E85D', width: Math.round(pay_amt / total * 100)}
      ] : [];
    };

    me.lineItems = [];

    me.updateLineItems = function() {
      me.lineItems = LineItemsService.lineItems;
      me.graphParts = getMonthlyAmountGraphParts(me.lineItems);
    };
    me.removeLineItem = function(item) {
      LineItemsService.remove(item);
    };
    me.getPartStyle = function(part) {
      return 'background-color: ' + part.color + '; width: ' + part.width + '%';
    };<commit_msg>Fix debt-income ratio calcs (#27)<commit_after>'use strict';

(function() {
  var planner = angular.module('cashewApp.Planner', ['ngRoute']);

  planner.config(['$routeProvider', function($routeProvider) {
    $routeProvider.when('/plan', {
      templateUrl: 'views/Planner/Planner.html',
      controller: 'Planner',
      controllerAs: 'planner'
    });
  }]);

  planner.controller('Planner', ['$scope', 'LineItemsService', function($scope, LineItemsService) {
    var me = this;
    var getMonthlyAmountGraphParts = function(lineItems) {
      var debt_amt = 0;
      var earn_amt = 0;
      var aside_amt = 0;
      lineItems.forEach(function(item) {
        if (item.freq.per === 'yr' && item.type === 'minus' && item.freq.split) {
          aside_amt += item.amount * item.freq.on.length / 12;
          return;
        }
        if (item.freq.per !== 'mo') {
          return;
        }
        if (item.type === 'minus') {
          debt_amt += item.amount * item.freq.on.length;
        } else if (item.type === 'plus') {
          earn_amt += item.amount * item.freq.on.length;
        }
      });
      if (earn_amt > 0) {
        var debt_width = Math.round(debt_amt / earn_amt * 100);
        var aside_width = Math.round(aside_amt / earn_amt * 100);
        return [
          {name: 'Monthly payments', color: '#FF4747', width: debt_width},
          {name: 'Monthly set-asides', color: '#FFDD45', width: aside_width},
          {name: 'Monthly earnings', color: '#A5E85D', width: 100 - (debt_width + aside_width)}
        ];
      }
      return [ {name: 'All debt :(', color: '#FF4747', width: 100} ];
    };

    me.lineItems = [];

    me.updateLineItems = function() {
      me.lineItems = LineItemsService.lineItems;
      me.graphParts = getMonthlyAmountGraphParts(me.lineItems);
    };
    me.removeLineItem = function(item) {
      LineItemsService.remove(item);
    };
    me.getPartStyle = function(part) {
      return 'background-color: ' + part.color + '; width: ' + part.width + '%';
    };
{'fraction_non_alphanumeric': 0.16390041493775934, 'fraction_numerical': 0.01504149377593361, 'mean_word_length': 2.522374429223744, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5081405', 'n_tokens_mistral': 1289, 'n_tokens_neox': 1250, 'n_words': 248}