forked from seanfreiburg/unbury.us
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sean Freiburg
authored and
Sean Freiburg
committed
Apr 6, 2015
1 parent
fce7869
commit ae5161b
Showing
8 changed files
with
377 additions
and
3 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
public/javascripts/fi_calculator/application_controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
var ApplicationController = function () { | ||
|
||
}; | ||
|
||
ApplicationController.auto_calculate = function(){ | ||
ApplicationController.calculate(); | ||
}; | ||
|
||
ApplicationController.calculate = function(){ | ||
console.log("calculated"); | ||
var years_to_fi = 0; | ||
var assets = window.current_assets; | ||
var salary_in_retirement = (1-(window.savings_rate/100))*current_salary; | ||
while (assets < (window.years_of_savings*salary_in_retirement)){ | ||
years_to_fi += 1; | ||
assets += (window.return_rate-window.inflation_rate)*assets; | ||
assets += window.current_salary*(window.savings_rate/100); | ||
if (years_to_fi > 122){ | ||
console.log("never fi"); | ||
return; | ||
} | ||
} | ||
console.log("years to fi " + years_to_fi); | ||
$("#years_to_fi").text(years_to_fi + " years to financial independence") | ||
}; | ||
|
||
ApplicationController.current_salary_input_change = function(){ | ||
ApplicationController.input_change("#current_salary"); | ||
}; | ||
|
||
ApplicationController.savings_rate_input_change = function(){ | ||
ApplicationController.input_change("#savings_rate"); | ||
}; | ||
|
||
ApplicationController.current_assets_input_change = function(){ | ||
ApplicationController.input_change("#current_assets"); | ||
}; | ||
|
||
|
||
ApplicationController.input_change = function(str){ | ||
var selector = $(str); | ||
var value = selector.val(); | ||
value = precise_round(value,2); | ||
window[str.substr(1, str.length)] = Number(value); | ||
console.log(str + " = " + value); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var init = function(){ | ||
|
||
|
||
window.current_assets = 0; | ||
window.savings_rate = 0; | ||
window.current_salary = 0; | ||
window.return_rate = .07; | ||
window.years_of_savings = 25; | ||
window.inflation_rate = .02; | ||
Router.init(); | ||
}; | ||
|
||
|
||
$().ready(function () { | ||
|
||
init(); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
String.prototype.contains = function (it) { | ||
return this.indexOf(it) !== -1; | ||
}; | ||
|
||
Math.sign = Math.sign || function sign(x) { | ||
x = +x; // convert to a number | ||
if (x === 0 || isNaN(x)) { | ||
return x; | ||
} | ||
return x > 0 ? 1 : -1; | ||
}; | ||
|
||
var deep_copy = function(string) { | ||
return JSON.parse(JSON.stringify(string)) | ||
}; | ||
|
||
|
||
|
||
|
||
var transformToAssocArray = function (prmstr) { | ||
var params = {}; | ||
var prmarr = prmstr.substr(1).split("&"); | ||
for (var i = 0; i < prmarr.length; i++) { | ||
var tmparr = prmarr[i].split("="); | ||
params[tmparr[0]] = tmparr[1]; | ||
} | ||
return params; | ||
}; | ||
|
||
Object.size = function (obj) { | ||
var size = 0, key; | ||
for (key in obj) { | ||
if (obj.hasOwnProperty(key)) size++; | ||
} | ||
return size; | ||
}; | ||
|
||
var precise_round = function (num, decimals) { | ||
var t = Math.pow(10, decimals); | ||
return parseFloat((Math.round((num * t) + (decimals > 0 ? 1 : 0) * (Math.sign(num) * (10 / Math.pow(100, decimals)))) / t).toFixed(decimals)); | ||
}; | ||
|
||
|
||
var round_interest_diff = function (a) { | ||
if (a > 0) { | ||
a = Math.ceil(a); | ||
} | ||
else if (a < 0) { | ||
a = Math.floor(a); | ||
|
||
} | ||
else { | ||
return a; | ||
} | ||
}; | ||
var arraysEqual = function (a, b) { | ||
if (a === b) return true; | ||
if (a == null || b == null) return false; | ||
if (a.length != b.length) return false; | ||
|
||
// If you don't care about the order of the elements inside | ||
// the array, you should sort both arrays here. | ||
|
||
for (var i = 0; i < a.length; ++i) { | ||
if (a[i] !== b[i]) return false; | ||
} | ||
return true; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
function Router() { | ||
|
||
} | ||
|
||
|
||
Router.init = function () { | ||
Router.add_current_assets_listener(); | ||
Router.add_savings_rate_listener(); | ||
Router.add_current_salary_listener(); | ||
Router.add_calculate_listener(); | ||
}; | ||
|
||
|
||
Router.add_current_salary_listener = function () { | ||
$("#current_salary").change(function () { | ||
ApplicationController.current_salary_input_change(); | ||
ApplicationController.auto_calculate(); | ||
}); | ||
}; | ||
|
||
Router.add_savings_rate_listener = function () { | ||
$("#savings_rate").change(function () { | ||
ApplicationController.savings_rate_input_change(); | ||
ApplicationController.auto_calculate(); | ||
}); | ||
}; | ||
|
||
Router.add_current_assets_listener = function () { | ||
$("#current_assets").change(function () { | ||
ApplicationController.current_assets_input_change(); | ||
ApplicationController.auto_calculate(); | ||
}); | ||
}; | ||
|
||
Router.add_calculate_listener = function () { | ||
$("#calculate").click(function () { | ||
ApplicationController.calculate(); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include fi_calculator/index.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>unbury.us</title> | ||
<meta name='description' | ||
content='unbury.us is an application that calculates payment plans based off of loan information to become debt free.'/> | ||
<meta name='keywords' | ||
content='loan, loan calculator, debt free, web application, personal finance, sean freiburg, jquery'/> | ||
|
||
<link rel="icon" href="assets/src/img/favicon.ico" type="image/x-icon"> | ||
<link rel="shortcut icon" href="assets/src/img/favicon.ico" type="image/x-icon"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
|
||
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"> | ||
<link href="/stylesheets/style.css" rel="stylesheet"> | ||
</head> | ||
<body> | ||
|
||
<div class="container-fluid"> | ||
<div class="row"> | ||
<div class="col-sm-3 col-sm-offset-3"> | ||
<h1 id="title">unbury.us</h1> | ||
</div> | ||
<div class="col-sm-4"> | ||
<h3>get unburied from debt</h3> | ||
</div> | ||
<div class="col-sm-2"> | ||
<a data-toggle="modal" data-target="#helpModal" href="#">help</a> \ | ||
<a data-toggle="modal" data-target="#aboutModal" href="#">about</a> \ | ||
<a href="/">debt_calculator</a> | ||
</div> | ||
</div> | ||
<hr> | ||
|
||
<div class="row"> | ||
<div class="col-sm-6 col-sm-offset-3"> | ||
<h1>Financial Independence Calculator</h1> | ||
<p>Assuming a 7% return on assets, 2% inflation, and 25x spending to be FI.</p> | ||
</div> | ||
</div> | ||
|
||
<div class="row"> | ||
<div class="col-sm-6 col-sm-offset-3"> | ||
<h3>Current Assets</h3> | ||
<input class="form-control" id="current_assets" placeholder="0"> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col-sm-6 col-sm-offset-3"> | ||
<h3>Current Salary</h3> | ||
<input class="form-control" id="current_salary" placeholder="0"> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col-sm-6 col-sm-offset-3"> | ||
<h3>Savings Rate</h3> | ||
<input class="form-control" id="savings_rate" placeholder="0%"> | ||
</div> | ||
</div> | ||
|
||
<div class="row"> | ||
<div class="col-sm-6 col-sm-offset-3"> | ||
<h4> </h4> | ||
<button id="calculate" class="btn btn-primary btn-block">calculate</button> | ||
|
||
</div> | ||
</div> | ||
|
||
<div class="row"> | ||
<div class="col-sm-6 col-sm-offset-3"> | ||
<h3 id="years_to_fi"></h3> | ||
|
||
|
||
</div> | ||
</div> | ||
|
||
<br><br> | ||
|
||
<div class="row"> | ||
<div class="col-sm-3"> | ||
<a href="http://seanfreiburg.com">seanfreiburg.com </a> | ||
</div> | ||
<div class="col-sm-3 col-sm-offset-5"> | ||
<a href='https://github.com/seanfreiburg/unbury.us/issues' title='Report bugs'>Report a Bug</a> \ | ||
<a href='http://github.com/seanfreiburg/unbury.us' title='Unbury.me on GitHub'>GitHub</a> \ | ||
<a href='https://github.com/seanfreiburg/unbury.us/blob/master/LICENSE' title='License'>MIT License</a> | ||
\ <a href='http://unbury.me' title='unbury.me'>credit</a> | ||
</div> | ||
</div> | ||
|
||
|
||
</div> | ||
|
||
<!-- Modals --> | ||
|
||
<div class="modal fade" id="paymentTypeHelpModal"> | ||
<div class="modal-dialog"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> | ||
<h4 class="modal-title">Payment Type</h4> | ||
</div> | ||
<div class="modal-body"> | ||
|
||
<p><strong>Avalanche</strong>: Paying off loans with the <strong>highest interest</strong> rate first. | ||
</p> | ||
|
||
<p><strong>Snowball</strong>: Paying off loans with the <strong>lowest balance</strong> first.</p> | ||
|
||
<p>While <strong>avalanche</strong> results in paying less interest, as well as being debt free sooner, | ||
<strong>snowball</strong> pays off individual loans faster, which can be motivating!</p> | ||
|
||
<p>Depending on your loans, the outcome may be the same regardless of the method used.</p> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
|
||
<div class="modal fade" id="helpModal"> | ||
<div class="modal-dialog"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> | ||
<h4 class="modal-title">Help</h4> | ||
</div> | ||
<div class="modal-body"> | ||
<p> | ||
|
||
unbury.us is a loan calculator designed to help you get debt-free as fast as possible. Once your | ||
loan information is entered, you may set the total amount you're able to put towards loans in a | ||
month. If this amount is greater than the minimum you're able to pay on loans, the extra money is | ||
put towards one loan every month to eliminate it. Once a loan is paid off, the money that was | ||
previously going towards that loan is now put towards the next loan, and so forth. | ||
</p> | ||
|
||
<p> | ||
The order of which loans are paid off first is either highest-to-lowest interest rate (Avalanche), | ||
or lowest-to-highest remaining principal (Snowball), depending on which you choose. | ||
</p> | ||
|
||
<p> | ||
Put just an extra $100 a month towards your loans and see how much time and interest paid you save! | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="modal fade" id="aboutModal"> | ||
<div class="modal-dialog"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> | ||
<h4 class="modal-title">About</h4> | ||
</div> | ||
<div class="modal-body"> | ||
|
||
<p> | ||
<strong>unbury.us</strong> is a loan calculator created by <a href='http://www.seanfreiburg.com' | ||
target='_new' | ||
title='seanfreiburg.com'>Sean | ||
Freiburg</a>.</p> | ||
|
||
<p>Source code for the project may be obtained at <a | ||
href="https://github.com/seanfreiburg/unbury.us">github</a> | ||
and is licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT | ||
License</a>. | ||
</p> | ||
|
||
<p>If you have any comments, questions or feedback, let me know on Twitter <a | ||
href='http://www.twitter.com/sfreiburg' title='Sean Freiburg on Twitter'>@sfreiburg</a></p> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
|
||
<!-- Libraries --> | ||
<script src="javascripts/lib/jquery-2.1.1.min.js"></script> | ||
<script src="javascripts/lib/bootstrap_3.1.1.js"></script> | ||
<script src="javascripts/lib/handlebars.js_2.0.0-alpha.2.js"></script> | ||
<script src="javascripts/lib/amplifyjs_1.1.0.js"></script> | ||
<script src="javascripts/lib/Chart.js_0.2.0.js"></script> | ||
<script src="javascripts/lib/google_analytics.js"></script> | ||
<script src="javascripts/lib/moment.js"></script> | ||
|
||
<script src="javascripts/fi_calculator/application_controller.js"></script> | ||
<script src="javascripts/fi_calculator/router.js"></script> | ||
<script src="javascripts/fi_calculator/lib.js"></script> | ||
<script src="javascripts/fi_calculator/init.js"></script> | ||
|
||
</body> | ||
</html> | ||
|
||
|
Oops, something went wrong.