Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class Level {
constructor(value) {
this.value = value;
}
week() {
this.value = Math.min(1, this.value + 1 / (52 * 5));
}
}
Level.beginner = () => new Level(0);
Level.junior = () => new Level(1 / 4);
Level.middle = () => new Level(1 / 2);
Level.senior = () => new Level(3 / 4);
Level.principal = () => new Level(1);
class Skill {
constructor(value) {
this.value = value;
}
week() {
if (this.value < .8)
this.value += .8 / 52
else {
this.value += .2 / (52 * 4);
if (this.value > 1)
this.value = 1;
}
}
}
class Skills {
constructor(domain, technology, programming, teamwork, methodology) {
this.domain = new Skill(domain);
this.technology = new Skill(technology);
this.programming = new Skill(programming);
this.teamwork = new Skill(teamwork);
this.methodology = new Skill(methodology);
}
week() {
this.domain.week();
this.technology.week();
this.programming.week();
this.teamwork.week();
this.methodology.week();
}
value() {
return (this.domain.value +
this.technology.value +
this.programming.value +
this.teamwork.value +
this.methodology.value) / 5;
}
}
class Developer {
constructor(skills, level) {
this.skills = skills;
this.level = level;
}
week(repository) {
this.skills.week();
// error rate is a function of total experience:
// f(80%) = every week, f(100%) = every second month.
if (Math.random() > Math.max(0, (this.skills.value() - 0.8) * 4.375))
repository.bugs++;
}
}
class Debugger {
week(team, repository) {
if (Math.random() > (0.66 / team.length) && repository.errors > 0)
repository.errors--;
}
}
class Accountant {
constructor() {
this.spendings = 0;
}
week(team, repository) {
let sum = 0.0;
for (const dev of team) {
sum += 50000 / 52 * (dev.level.value + 1);
}
sum += repository.bugs * 50;
this.spendings += sum;
}
}
// 5 years, 1000 samples
function run(description, hr) {
let simulations = 1000;
let duration = 5; // years
let spendings = 0;
let bugs = 0;
for (let i = 0; i < simulations; i++) {
let team = hr();
const repository = { bugs: 0 };
const $debugger = new Debugger(team, repository);
const accountant = new Accountant(team, repository);
for (let i = 0; i < 52 * duration; i++) {
team.forEach(d => d.week(repository));
$debugger.week(team, repository);
accountant.week(team, repository);
}
spendings += accountant.spendings / simulations;
bugs += repository.bugs / simulations;
}
console.log(description + ': ' + spendings + ' ' + bugs);
}
run('4 juniors', () => ([
new Developer(new Skills(0, 0, .8, .8, .8), Level.junior()),
new Developer(new Skills(0, 0, .8, .8, .8), Level.junior()),
new Developer(new Skills(0, 0, .8, .8, .8), Level.junior()),
new Developer(new Skills(0, 0, .8, .8, .8), Level.junior())
]));
run('4 principals', () => ([
new Developer(new Skills(0, 1, 1, 1, 1), Level.principal()),
new Developer(new Skills(0, 1, 1, 1, 1), Level.principal()),
new Developer(new Skills(0, 1, 1, 1, 1), Level.principal()),
new Developer(new Skills(0, 1, 1, 1, 1), Level.principal())
]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.