Published
Edited
Jun 4, 2018
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
skill1Results = {
const iterationNumber = Math.max(...studentSkill1Choices.choices.map(x => x.choices.length))
let results = []
let subjectsStatus = []
const shuffledChoices = _.shuffle(studentSkill1Choices.choices)
for (let x = 0; x < iterationNumber; x++) {
for (let { studentId, choices } of shuffledChoices) {
// Récupérer l'instance dans résult qui correspond à l'étudiant
const studentResultIndex = results.findIndex(y => y.studentId === studentId)
// Récupérer l'instance de l'ue dans subjectsStatus
const subjectStatusIndex = subjectsStatus.findIndex(y => y.subjectId === choices[x])
if (studentResultIndex === -1) {
// Cas ou l'étudiant n'existe pas encore dans les résultats
if (subjectStatusIndex === -1) {
// Cas ou l'UE n'a pas encore été affecté à un étudiant
results = [
...results,
{
studentId,
choices: [choices[x]]
}
]
subjectsStatus = [
...subjectsStatus,
{
subjectId: choices[x],
students: 1
}
]
} else {
// Cas ou l'UE a déjà été affecté à un ou plusieurs étudiant et donc existe en tant que sujet
if (subjectsStatus[subjectStatusIndex].students < skillSubjects.find(y => y.id === choices[x]).capacity) {
// Cas ou la capacité de l'UE concernée par le choix en cours n'est pas dépassée
results = [
...results,
{
studentId,
choices: [choices[x]]
}
]
subjectsStatus = [
...subjectsStatus.filter(x => x.subjectId !== subjectsStatus[subjectStatusIndex].subjectId),
{
...subjectsStatus[subjectStatusIndex],
students: subjectsStatus[subjectStatusIndex].students +1
}
]
}
}
} else {
// Cas ou l'étudiant existe déjà dans les résultats
if (results[studentResultIndex].choices.length < currentSkill.optionalSubjectsNb) {
// Cas ou l'étudiant n'a pas encore le nombre d'UE optionnelle requises
if (subjectStatusIndex === -1) {
// Cas ou l'UE n'a pas encore été affecté à un étudiant
results = [
...results.filter(x => x.studentId !== results[studentResultIndex].studentId),
{
...results[studentResultIndex],
choices: [...results[studentResultIndex].choices, choices[x]]
}
]
subjectsStatus = [
...subjectsStatus,
{
subjectId: choices[x],
students: 1
}
]
} else {
// Cas ou l'UE a déjà été affecté à un ou plusieurs étudiant et donc existe en tant que sujet
if (subjectsStatus[subjectStatusIndex].students < skillSubjects.find(y => y.id === choices[x]).capacity) {
// Cas ou la capacité de l'UE concernée par le choix en cours n'est pas dépassée
results = [
...results.filter(x => x.studentId !== results[studentResultIndex].studentId),
{
...results[studentResultIndex],
choices: [...results[studentResultIndex].choices, choices[x]]
}
]
subjectsStatus = [
...subjectsStatus.filter(x => x.subjectId !== subjectsStatus[subjectStatusIndex].subjectId),
{
...subjectsStatus[subjectStatusIndex],
students: subjectsStatus[subjectStatusIndex].students +1
}
]
}
}
}
}
}
}

return { results, subjectsStatus }
}
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more