Skip to content

Commit

Permalink
bug fixes galore
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Freiburg authored and Sean Freiburg committed Apr 5, 2015
1 parent 103930c commit 7a73033
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 17 deletions.
2 changes: 0 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

var routes = require('./routes/index');
var users = require('./routes/users');

var app = express();

Expand All @@ -25,7 +24,6 @@ app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', routes);
app.use('/users', users);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
Expand Down
19 changes: 13 additions & 6 deletions public/javascripts/loan_calculator/graph_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ GraphController.get_step_width = function (results, steps) {
GraphController.get_data = function (results) {
var max_row_length = 0;
var max_row_index = 0;
var num_labels = 20;
var step_size;
var datasets = [];
var keys = Object.keys(results.loans);
keys.sort(function (a, b) {
Expand All @@ -49,26 +51,31 @@ GraphController.get_data = function (results) {
console.log(keys);
for (var i = 0; i < keys.length; i++) {
var loan_key = keys[i];
console.log("loan key")
console.log("loan key");
console.log(loan_key);
if (results.loans[loan_key].rows.length > max_row_length) {
max_row_length = results.loans[loan_key].rows.length;
max_row_index = loan_key;
}
if (results.loans[max_row_index].rows.length > num_labels){
step_size = Math.floor(results.loans[max_row_index].rows.length/num_labels);
}
else {
step_size = 1;
}

console.log(step_size);
datasets[i] = GraphController.get_color_hash(loan_key);
datasets[i].data = [];
for (var j = 0; j < results.loans[loan_key].rows.length; j++) {
for (var j = 0; j < results.loans[loan_key].rows.length; j += step_size) {
datasets[i].data.push(results.loans[loan_key].rows[j].balance_remaining);
}
}
var labels = [];


for (var i = 0; i < results.loans[max_row_index].rows.length; i++) {
for (var i = 0; i < results.loans[max_row_index].rows.length; i += step_size) {
labels.push(results.loans[max_row_index].rows[i].date);
}


return {
labels: labels,
datasets: datasets
Expand Down
4 changes: 4 additions & 0 deletions public/javascripts/loan_calculator/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ Math.sign = Math.sign || function sign(x) {
return x > 0 ? 1 : -1;
};

var deep_copy = function(string) {
return JSON.parse(JSON.stringify(string))
};


// http://localhost:63342/unbury.us/public_html/index.html#name_0=1&balance_0=2&payment_0=4&rate_0=2
var url_loans_valid = function (params) {
Expand Down
5 changes: 5 additions & 0 deletions public/javascripts/loan_calculator/results_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ ResultsController.calculate = function (loans, payment_type, monthly_payment) {


//loop
var counter = 0;
while (Object.keys(remaining_loans).length > 0) {
counter++;
if (counter > 12*50){
return null;
}
month.add(1, 'months');
var extra_payment = monthly_payment;
for (var loan_key in remaining_loans) {
Expand Down
4 changes: 4 additions & 0 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ router.get('/', function(req, res, next) {
res.render("index");
});

router.get('/opportunity_cost', function(req, res, next) {
res.render("opportunity_cost");
});

module.exports = router;
9 changes: 0 additions & 9 deletions routes/users.js

This file was deleted.

1 change: 1 addition & 0 deletions views/opportunity_cost.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include opportunity_cost/index.html
1 change: 1 addition & 0 deletions views/opportunity_cost/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>hey</p>

0 comments on commit 7a73033

Please sign in to comment.