JSFiddle - React, Tailwind, and code Playground
by smacky311
HTML
<script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
<h1>
Evidence Based Estimation
</h1>
<p>
Input a set of actual velocities your team has taken over time. Then give the estimated size of the next major milestone. This application will tell you the projected time it will take to complete the milestone.
</p>
<label>Actual Velocities </label>
<input id="velocities" style="width: 200px;" value="10, 8, 10, 10, 6, 12, 7, 10, 12, 12"/>
<br /><br />
<label>size of milestone</label>
<input id="milestoneSize" value="100" />
<br /><br />
<label>Length of sprint in weeks</label>
<input id="lengthOfSprint" value="1" />
<br /><br />
<button id="runApp">
Calculate
</button>
<h2>
Estimation given these numbers
</h2>
<label id="output" />
JavaScript
//Determines probability distribution for a Milestone of a given size.
//Displays best and worst project completion times by week and the odds of hitting
//said deadline
var numberOfSampleIterations = 10000;
var result = new Array();
var milestoneSize;
var velocities;
var outputLabel = document.getElementById("output");
var lengthOfSprint;
$('#runApp').click(run);
function run() {
resetState();
getUserData();
createProjection();
printResult();
}
function resetState() {
outputLabel.innerHTML = "";
result = new Array();
}
function getUserData() {
lengthOfSprint = Number(document.getElementById("lengthOfSprint").value);
milestoneSize = Number(document.getElementById("milestoneSize").value);
velocities = document.getElementById("velocities").value.replace(/\s/g, '').split(",");
//convert string to number
velocities = velocities.map(Number);
//adjust for length of sprint
velocities = velocities.map(adjustForLengthOfSprint);
//console.log("milestonesize: " + milestoneSize + " velocities: " + velocities);
}
function adjustForLengthOfSprint(input) {
var result = input / lengthOfSprint;
return result;
}
function createProjection() {
var sample = 0;
var weeksThisIteration = 0;
for (var i = 0; i < numberOfSampleIterations; i++) {
sample = 0;
weeksThisIteration = 0;
while (sample < milestoneSize) {
var randomNumber = getRandomInt(0,velocities.length - 1);
sample += velocities[randomNumber];
//console.log('sample size ' + velocities[randomNumber]);
weeksThisIteration++;
}
if(!result[weeksThisIteration]) {
result[weeksThisIteration] = 0;//initialize the element
}
result[weeksThisIteration]++;
}
}
function printResult() {
var cumulativeResult = 0;
var firstRun = true;
for (var key in result) {
var resultAsNumber = result[key];
//var output = "It took " + key + " Weeks " + resultAsNumber + " times ";
//console.log(output);
...