estimate-tasks
Advanced tools
Comparing version 0.1.0 to 1.0.0
139
lib/calc.js
@@ -1,69 +0,64 @@ | ||
(function (undefined) { | ||
"use strict"; | ||
(function () { | ||
'use strict' | ||
var hasModule = (typeof module !== "undefined" && module.exports), | ||
function isFunction (x) { | ||
return (typeof x === 'function') | ||
} | ||
underscore = function () { | ||
return ( | ||
hasModule ? | ||
require("underscore") : (window._) | ||
); | ||
}, | ||
function scope () { | ||
return hasModule ? module.exports : {} | ||
} | ||
scope = function () { | ||
return hasModule ? module.exports : {}; | ||
}, | ||
var hasModule = (typeof module !== 'undefined' && module.exports) | ||
var exports = scope() | ||
_ = underscore(), | ||
exports = scope(), | ||
/** | ||
* bestCaseHours <= mostLikelyCaseHours <= worstCaseHours | ||
* Minimum possible confidencePercent is 10 | ||
*/ | ||
var Estimate = function (bestCaseHours, mostLikelyCaseHours, worstCaseHours, confidencePercent) { | ||
var isVector = (typeof bestCaseHours === 'object') | ||
/** | ||
* bestCaseHours <= mostLikelyCaseHours <= worstCaseHours | ||
* Minimum possible confidencePercent is 10 | ||
*/ | ||
Estimate = function (bestCaseHours, mostLikelyCaseHours, worstCaseHours, confidencePercent) { | ||
var isVector = _.isArray(bestCaseHours); | ||
this.bestCaseHours = isVector ? bestCaseHours[0] : bestCaseHours | ||
this.mostLikelyCaseHours = isVector ? bestCaseHours[1] : mostLikelyCaseHours | ||
this.worstCaseHours = isVector ? bestCaseHours[2] : worstCaseHours | ||
this.confidencePercent = isVector ? bestCaseHours[3] : confidencePercent | ||
} | ||
this.bestCaseHours = isVector ? bestCaseHours[0] : bestCaseHours; | ||
this.mostLikelyCaseHours = isVector ? bestCaseHours[1] : mostLikelyCaseHours; | ||
this.worstCaseHours = isVector ? bestCaseHours[2] : worstCaseHours; | ||
this.confidencePercent = isVector ? bestCaseHours[3] : confidencePercent; | ||
}; | ||
Estimate.prototype.expectedCaseHours = function () { | ||
return (this.bestCaseHours + 4.0 * this.mostLikelyCaseHours + this.worstCaseHours) / 6.0; | ||
}; | ||
return (this.bestCaseHours + 4.0 * this.mostLikelyCaseHours + this.worstCaseHours) / 6.0 | ||
} | ||
Estimate.prototype.variance = function () { | ||
var confidenceDivisor = exports.confidenceDivisor(this.confidencePercent), | ||
standardDeviation = (this.worstCaseHours - this.bestCaseHours) / confidenceDivisor; | ||
var confidenceDivisor = exports.confidenceDivisor(this.confidencePercent) | ||
var standardDeviation = (this.worstCaseHours - this.bestCaseHours) / confidenceDivisor | ||
return standardDeviation * standardDeviation; | ||
}; | ||
return standardDeviation * standardDeviation | ||
} | ||
exports.Estimate = Estimate; | ||
exports.Estimate = Estimate | ||
exports.confidenceDivisor = function (confidencePercent) { | ||
var foundPair = _.find( | ||
[[99.7, 6], [90, 3.3], [80, 2.6], [70, 2.1], [60, 1.7], | ||
[50, 1.4], [40, 1], [30, 0.77], [20, 0.51], [10, 0.25]], | ||
var foundPair = [ | ||
[99.7, 6], [90, 3.3], [80, 2.6], [70, 2.1], [60, 1.7], | ||
[50, 1.4], [40, 1], [30, 0.77], [20, 0.51], [10, 0.25] | ||
].find( | ||
function (pair) { | ||
return confidencePercent >= pair[0] | ||
} | ||
) | ||
function (pair) { | ||
return confidencePercent >= pair[0]; | ||
} | ||
); | ||
return (foundPair ? foundPair[1] : undefined) | ||
} | ||
return (foundPair ? foundPair[1] : undefined); | ||
}; | ||
exports.total75PercentLikelyHours = function (estimates) { | ||
var add = function (memo, num) { return memo + num; }, | ||
var add = function (memo, num) { return memo + num } | ||
ensureEstimateObjects = function () { | ||
return _.map(estimates, function (e) { | ||
return ( | ||
_.isFunction(e.expectedCaseHours) && _.isFunction(e.variance) ? | ||
e : | ||
var ensureEstimateObjects = function () { | ||
return estimates.map(function (e) { | ||
return ( | ||
isFunction(e.expectedCaseHours) && isFunction(e.variance) | ||
? e | ||
new Estimate( | ||
: new Estimate( | ||
e.bestCaseHours, | ||
@@ -74,32 +69,26 @@ e.mostLikelyCaseHours, | ||
) | ||
); | ||
}); | ||
}, | ||
) | ||
}) | ||
} | ||
expectedCasesSum = _.reduce( | ||
_.map( | ||
ensureEstimateObjects(), | ||
function (e) { return e.expectedCaseHours(); } | ||
), | ||
var expectedCasesSum = ensureEstimateObjects().map( | ||
function (e) { return e.expectedCaseHours() } | ||
).reduce( | ||
add, | ||
0.0 | ||
) | ||
add, | ||
0.0 | ||
), | ||
var variancesSum = ensureEstimateObjects().map( | ||
function (e) { return e.variance() } | ||
).reduce( | ||
add, | ||
0.0 | ||
) | ||
variancesSum = _.reduce( | ||
_.map( | ||
ensureEstimateObjects(), | ||
function (e) { return e.variance(); } | ||
), | ||
return expectedCasesSum + 0.67 * Math.sqrt(variancesSum) | ||
} | ||
add, | ||
0.0 | ||
); | ||
return expectedCasesSum + 0.67 * Math.sqrt(variancesSum); | ||
}; | ||
if (!hasModule) { | ||
window["estimate-tasks"] = exports; | ||
window['estimate-tasks'] = exports | ||
} | ||
}()); | ||
}()) |
{ | ||
"name": "estimate-tasks", | ||
"version": "0.1.0", | ||
"description": "Given the individual tasks' estimations, calculates the total estimation for the whole project", | ||
"main": "lib/calc.js", | ||
"engines": { | ||
"node": ">=0.4.0" | ||
}, | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/ikr/estimate-tasks.git" | ||
}, | ||
"keywords": [ | ||
"estimation", | ||
"project", | ||
"planning", | ||
"probability", | ||
"tasks", | ||
"estimate" | ||
], | ||
"dependencies": { | ||
"underscore": "1.4.x" | ||
}, | ||
"devDependencies": { | ||
"mocha": "1.9.x", | ||
"should": "1.2.x", | ||
"sinon": "1.6.x" | ||
}, | ||
"author": "Ivan Krechetov <ivan.krechetov@gmail.com>", | ||
"license": "MIT" | ||
"name": "estimate-tasks", | ||
"version": "1.0.0", | ||
"description": "Given the individual tasks' estimations, calculates the total estimation for the whole project", | ||
"main": "lib/calc.js", | ||
"engines": { | ||
"node": ">=0.4.0" | ||
}, | ||
"scripts": { | ||
"test": "mocha", | ||
"pretest": "eslint lib test" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/ikr/estimate-tasks.git" | ||
}, | ||
"keywords": [ | ||
"estimation", | ||
"project", | ||
"planning", | ||
"probability", | ||
"tasks", | ||
"estimate" | ||
], | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"eslint": "^4.11.0", | ||
"eslint-config-standard": "^10.2.1", | ||
"eslint-plugin-import": "^2.8.0", | ||
"eslint-plugin-node": "^5.2.1", | ||
"eslint-plugin-promise": "^3.6.0", | ||
"eslint-plugin-standard": "^3.0.1", | ||
"mocha": "^4.0.1", | ||
"should": "^13.1.3", | ||
"sinon": "^4.1.2" | ||
}, | ||
"author": "Ivan Krechetov <ivan.krechetov@gmail.com>", | ||
"license": "MIT" | ||
} |
@@ -0,1 +1,3 @@ | ||
[![Build Status](https://travis-ci.org/ikr/estimate-tasks.svg?branch=master)](https://travis-ci.org/ikr/estimate-tasks) | ||
# About | ||
@@ -56,3 +58,3 @@ | ||
In the browser you have to include [Underscore](http://documentcloud.github.io/underscore/) and the | ||
In the browser you have to include the | ||
[lib/calc.js](https://github.com/ikr/estimate-tasks/blob/master/lib/calc.js) script. Then: | ||
@@ -64,14 +66,4 @@ | ||
Test-driven with [Mocha](http://visionmedia.github.com/mocha/). Under Node, say: | ||
Test-driven with [Mocha](http://mochajs.org/). Under Node, say: | ||
~/estimate-tasks(master)$ npm test | ||
# License (MIT) | ||
Copyright (c) 2013 Ivan Krechetov | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
(function () { | ||
"use strict"; | ||
'use strict' | ||
var _ = require("underscore"), | ||
assert = require("assert"), | ||
should = require("should"), | ||
sinon = require("sinon"), | ||
calc = require("../lib/calc"), | ||
Estimate = calc.Estimate; | ||
var assert = require('assert') | ||
var should = require('should') | ||
var sinon = require('sinon') | ||
var calc = require('../lib/calc') | ||
var Estimate = calc.Estimate | ||
describe("Estimate object", function () { | ||
it("has a constructor function", function () { | ||
Estimate.should.be.a("function"); | ||
}); | ||
describe('Estimate object', function () { | ||
it('has a constructor function', function () { | ||
assert.strictEqual(typeof Estimate, 'function') | ||
}) | ||
it("accepts a vector of values in constructor", function () { | ||
it('accepts a vector of values in constructor', function () { | ||
assert.strictEqual( | ||
(new Estimate(1, 2, 3.5, 80)).variance(), | ||
(new Estimate([1, 2, 3.5, 80])).variance() | ||
); | ||
}); | ||
}); | ||
) | ||
}) | ||
}) | ||
describe("confidenceDivisor()", function () { | ||
it("is 0.25 for 9%", function () { | ||
should.not.exist(calc.confidenceDivisor(9)); | ||
}); | ||
describe('confidenceDivisor()', function () { | ||
it('is 0.25 for 9%', function () { | ||
should.not.exist(calc.confidenceDivisor(9)) | ||
}) | ||
it("is 0.25 for 10%", function () { | ||
calc.confidenceDivisor(10).should.be.within(0.25 - 0.001, 0.25 + 0.001); | ||
}); | ||
it('is 0.25 for 10%', function () { | ||
calc.confidenceDivisor(10).should.be.within(0.25 - 0.001, 0.25 + 0.001) | ||
}) | ||
it("is 0.51 for 20%", function () { | ||
calc.confidenceDivisor(20).should.be.within(0.51 - 0.001, 0.51 + 0.001); | ||
}); | ||
it('is 0.51 for 20%', function () { | ||
calc.confidenceDivisor(20).should.be.within(0.51 - 0.001, 0.51 + 0.001) | ||
}) | ||
it("is 0.77 for 30%", function () { | ||
calc.confidenceDivisor(30).should.be.within(0.77 - 0.001, 0.77 + 0.001); | ||
}); | ||
it('is 0.77 for 30%', function () { | ||
calc.confidenceDivisor(30).should.be.within(0.77 - 0.001, 0.77 + 0.001) | ||
}) | ||
it("is 1.0 for 40%", function () { | ||
calc.confidenceDivisor(40).should.be.within(1.0 - 0.001, 1.0 + 0.001); | ||
}); | ||
it('is 1.0 for 40%', function () { | ||
calc.confidenceDivisor(40).should.be.within(1.0 - 0.001, 1.0 + 0.001) | ||
}) | ||
it("is 1.4 for 50%", function () { | ||
calc.confidenceDivisor(50).should.be.within(1.4 - 0.001, 1.4 + 0.001); | ||
}); | ||
it('is 1.4 for 50%', function () { | ||
calc.confidenceDivisor(50).should.be.within(1.4 - 0.001, 1.4 + 0.001) | ||
}) | ||
it("is 1.7 for 60%", function () { | ||
calc.confidenceDivisor(60).should.be.within(1.7 - 0.001, 1.7 + 0.001); | ||
}); | ||
it('is 1.7 for 60%', function () { | ||
calc.confidenceDivisor(60).should.be.within(1.7 - 0.001, 1.7 + 0.001) | ||
}) | ||
it("is 2.1 for 70%", function () { | ||
calc.confidenceDivisor(70).should.be.within(2.1 - 0.001, 2.1 + 0.001); | ||
}); | ||
it('is 2.1 for 70%', function () { | ||
calc.confidenceDivisor(70).should.be.within(2.1 - 0.001, 2.1 + 0.001) | ||
}) | ||
it("is 2.6 for 80%", function () { | ||
calc.confidenceDivisor(80).should.be.within(2.6 - 0.001, 2.6 + 0.001); | ||
}); | ||
it('is 2.6 for 80%', function () { | ||
calc.confidenceDivisor(80).should.be.within(2.6 - 0.001, 2.6 + 0.001) | ||
}) | ||
it("is 3.3 for 90%", function () { | ||
calc.confidenceDivisor(90).should.be.within(3.3 - 0.001, 3.3 + 0.001); | ||
}); | ||
it('is 3.3 for 90%', function () { | ||
calc.confidenceDivisor(90).should.be.within(3.3 - 0.001, 3.3 + 0.001) | ||
}) | ||
it("is 6.0 for 99.7%", function () { | ||
calc.confidenceDivisor(99.7).should.be.within(6.0 - 0.001, 6.0 + 0.001); | ||
}); | ||
it('is 6.0 for 99.7%', function () { | ||
calc.confidenceDivisor(99.7).should.be.within(6.0 - 0.001, 6.0 + 0.001) | ||
}) | ||
it("is 6.0 for 99.9%", function () { | ||
calc.confidenceDivisor(99.9).should.be.within(6.0 - 0.001, 6.0 + 0.001); | ||
}); | ||
}); | ||
it('is 6.0 for 99.9%', function () { | ||
calc.confidenceDivisor(99.9).should.be.within(6.0 - 0.001, 6.0 + 0.001) | ||
}) | ||
}) | ||
describe("Estimate.prototype.expectedCaseHours()", function () { | ||
it("is 16 for [12, 16, 20, 99.9]", function () { | ||
var e = new Estimate(12, 16, 20, 99.9); | ||
e.expectedCaseHours().should.be.within(16 - 0.001, 16 + 0.001); | ||
}); | ||
describe('Estimate.prototype.expectedCaseHours()', function () { | ||
it('is 16 for [12, 16, 20, 99.9]', function () { | ||
var e = new Estimate(12, 16, 20, 99.9) | ||
e.expectedCaseHours().should.be.within(16 - 0.001, 16 + 0.001) | ||
}) | ||
it("is 24.33 for [20, 24, 30, 99.9]", function () { | ||
var e = new Estimate(20, 24, 30, 99.9); | ||
e.expectedCaseHours().should.be.within(24.33 - 0.01, 24.33 + 0.01); | ||
}); | ||
}); | ||
it('is 24.33 for [20, 24, 30, 99.9]', function () { | ||
var e = new Estimate(20, 24, 30, 99.9) | ||
e.expectedCaseHours().should.be.within(24.33 - 0.01, 24.33 + 0.01) | ||
}) | ||
}) | ||
describe("Estimate.prototype.variance()", function () { | ||
it("relies on calc.confidenceDivisor()", function () { | ||
var e = new Estimate(12, 16, 20, 100), | ||
spy = sinon.spy(calc, "confidenceDivisor"); | ||
describe('Estimate.prototype.variance()', function () { | ||
it('relies on calc.confidenceDivisor()', function () { | ||
var e = new Estimate(12, 16, 20, 100) | ||
sinon.spy(calc, 'confidenceDivisor') | ||
e.variance(); | ||
e.variance() | ||
assert(calc.confidenceDivisor.calledWith(100)) | ||
calc.confidenceDivisor.restore() | ||
}) | ||
assert(calc.confidenceDivisor.calledWith(100)); | ||
it('is 1.78 for [12, 16, 20, 99.9]', function () { | ||
var e = new Estimate(12, 16, 20, 99.9) | ||
e.variance().should.be.within(1.78 - 0.005, 1.78 + 0.005) | ||
}) | ||
}) | ||
calc.confidenceDivisor.restore(); | ||
}); | ||
it("is 1.78 for [12, 16, 20, 99.9]", function () { | ||
var e = new Estimate(12, 16, 20, 99.9); | ||
e.variance().should.be.within(1.78 - 0.005, 1.78 + 0.005); | ||
}); | ||
}); | ||
describe("total75PercentLikelyHours()", function () { | ||
it("is 16 for (1 2 3) (4 5 6) (7 8 10)", function () { | ||
describe('total75PercentLikelyHours()', function () { | ||
it('is 16 for (1 2 3) (4 5 6) (7 8 10)', function () { | ||
calc.total75PercentLikelyHours([ | ||
@@ -110,6 +107,6 @@ new Estimate(1, 2, 3, 99.9), | ||
new Estimate(7, 8, 10, 99.9) | ||
]).should.be.within(16 - 0.5, 16 + 0.5); | ||
}); | ||
]).should.be.within(16 - 0.5, 16 + 0.5) | ||
}) | ||
it("is 10 for (1 2 3) (1 2 2.5) (3 5 7) (0.5 1 1.5)", function () { | ||
it('is 10 for (1 2 3) (1 2 2.5) (3 5 7) (0.5 1 1.5)', function () { | ||
calc.total75PercentLikelyHours([ | ||
@@ -120,6 +117,6 @@ new Estimate(1, 2, 3, 99.9), | ||
new Estimate(0.5, 1, 1.5, 99.9) | ||
]).should.be.within(10 - 0.5, 10 + 0.5); | ||
}); | ||
]).should.be.within(10 - 0.5, 10 + 0.5) | ||
}) | ||
it("accepts the plain maps instead of Estimate objects as the input", function () { | ||
it('accepts the plain maps instead of Estimate objects as the input', function () { | ||
calc.total75PercentLikelyHours([{ | ||
@@ -140,5 +137,5 @@ bestCaseHours: 1, | ||
confidencePercent: 99.9 | ||
}]).should.be.within(16 - 0.5, 16 + 0.5); | ||
}); | ||
}); | ||
}()); | ||
}]).should.be.within(16 - 0.5, 16 + 0.5) | ||
}) | ||
}) | ||
}()) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
12440
0
9
1
9
190
68
1
- Removedunderscore@1.4.x
- Removedunderscore@1.4.4(transitive)