Calculate-progress-to-goal
by Sushil Mahajan
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<div>
Goal Amount:
<input id="goal-amount">
</div>
<div>
MCS Response:
<textarea id="mcs-payload"></textarea>
</div>
<div>
<input type="button" id="run" value="Run">
</div>
<div>
Calculated succes rate for Goal Amount
<span id="goal-amt"></span> is: <span id="s-rate"></span>
</div>
CSS
div {
display: flex;
flex-direction: row;
padding: 5px;
}
span {
padding: 0 5px;
}
JavaScript
$(document).ready(function() {
$("#run").click(function() {
var goalAmount = $("#goal-amount").val();
if (goalAmount != undefined && goalAmount != "") {
var payload = $("#mcs-payload").val();
if (payload == undefined || payload == "") {
alert("Using default MCS response to calculate progress toward goal");
payload = mcsResult;
} else {
payload = JSON.parse(payload);
}
recentMCSdata = payload.originalPortValueDistWithoutGoal;
console.log(recentMCSdata);
// Calculate Progress
getProgressToGoal(recentMCSdata, goalAmount);
} else {
alert("Please enter a goal amount");
}
});
var getProgressToGoal = function(recentMCSdata, goalAmount) {
goalAmount = Number(goalAmount);
$("#goal-amt").html(goalAmount);
var trajectories = recentMCSdata.wealthTrajectories;
var endingValues = [];
var probOfSuccess = 0;
var value_0 = trajectories.zeroPercentileTrajectory[trajectories.zeroPercentileTrajectory.length - 1].value;
endingValues.push({
"key": "0",
"value": value_0
});
var value_5 = trajectories.fifthPercentileTrajectory[trajectories.fifthPercentileTrajectory.length - 1].value;
endingValues.push({
"key": "5",
"value": value_5
});
var value_10 = trajectories.tenthPercentileTrajectory[trajectories.tenthPercentileTrajectory.length - 1].value;
endingValues.push({
"key": "10",
"value": value_10
});
var value_25 = trajectories.twentyfifthPercentileTrajectory[trajectories.twentyfifthPercentileTrajectory.length - 1].value;
endingValues.push({
"key": "25",
"value": value_25
});
var value_50 = trajectories.fiftiethPercentileTrajectory[trajectories.fiftiethPercentileTrajectory.length - 1].value;
endingValues.push({
"key": "50",
"value": value_50
});
var value_75 =...