-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoptimizeSimplified.js
More file actions
89 lines (82 loc) · 2.51 KB
/
optimizeSimplified.js
File metadata and controls
89 lines (82 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
function getSkillLv(dev, skillName) {
const skill = dev.skills.find((s) => s.name === skillName);
//console.log({ skill });
skill ? skill.actLv : 0;
}
/**
* Ritorna i devs con le capacita` corrette per quel project.
* @param {[ name: str, skills: [{ name: str, initLv: int, actLv: int }] ]} devs
* @returns
*/
function getRightDevs(devs, project) {
const toRet = [];
const avDevs = [...devs];
for (const skill of project.reqSkills) {
const filtered = avDevs.filter((dev) => {
return dev.skills.some((s) => {
//console.log({ skill, s });
return s.name === skill.name && s.currentLv >= skill.lv;
});
}); // tra tutti quelli che hanno la skill
//console.log({ filtered });
const sorted = filtered.sort(
(dev1, dev2) =>
getSkillLv(dev1, skill.name) - getSkillLv(dev2, skill.name) // ordinali in ordine crescente
);
//console.log({ sorted });
const chosenDev = sorted.shift();
if (chosenDev) {
toRet.push(chosenDev);
avDevs.splice(
avDevs.findIndex((d) => d.name === chosenDev.name),
1
);
} else return [];
}
toRet.forEach((dev, i) => {
const skillDev = dev.skills.find(
(s) =>
s.name === project.reqSkills[i].name &&
s.currentLv === project.reqSkills[i].lv
);
if (skillDev) skillDev.currentLv++;
});
return toRet;
}
/**
*
* @param {[ name: str, skills: [{ name: str, initLv: int, actLv: int }] ]} devs
* @param {[{name: str, bestBefore: int, duration: int, fullScore: int, actualScore: int, reqSkills: [{ name: str, initLv: int, actLv: int }]}]} projects
* @returns
*/
export default function optimizeSimplified(devs, projects) {
const orderedProject = projects.sort(
(pr1, pr2) => pr1.duration - pr2.duration
);
const toRet = [];
// //console.log({ project: orderedProject[1], s: orderedProject[1].reqSkills });
// const project = orderedProject[1];
const upperBound = orderedProject.length * 2;
let i = 0;
for (const project of orderedProject) {
if (i++ > upperBound) break;
// console.log({ project });
const rightDevs = getRightDevs(devs, project);
// //console.log({ rightDevs });
if (rightDevs.length > 0) {
const rightDevsNames = rightDevs.map((d) => {
//console.log(d);
return d.name;
});
toRet.push({
name: project.name,
roles: rightDevsNames,
});
} else {
// riaggiungo project alla lista
orderedProject.push(project);
}
}
//console.log(toRet);
return toRet;
}