Skip to content

Commit

Permalink
Merge pull request #373 from mission-apprentissage/ui-server/iframe-f…
Browse files Browse the repository at this point in the history
…ormation-v2

[UI - serveur] Iframe formation v2
  • Loading branch information
yohanngab authored Nov 26, 2024
2 parents f5def95 + 53279ea commit 0ca13a1
Show file tree
Hide file tree
Showing 15 changed files with 581 additions and 76 deletions.
10 changes: 10 additions & 0 deletions server/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,13 @@ export const QUESTION_LABELS_BY_QUESTION_KEY = {
trouverEntrepriseConseil: "Comment as-tu vécu ta recherche d’entreprise ? As-tu des conseils ?",
differenceCollegeCfaConseil: "À quoi ressemble une journée dans ton CFA ?",
};

export const TROUVER_ENTREPRISE_LABEL_MATCHER = {
"En me débrouillant tout·e seul·e": "En toute autonomie",
"Une personne de ma famille ou de mon entourage m'a aidé·e": "Avec l’aide de l’entourage (famille, amis, etc)",
"Oui j’ai eu besoin de lui et il m’a aidé": "Avec l’aide du CFA",
Autrement: "Autrement (non précisé)",
"Un·e éducateur·ice ou une association m’a aidé·e": "Avec l’aide d’un éducateur ou d’une association",
"Lors d'un événement sur l’orientation": "Lors d'un événement sur l’orientation",
"Un·e membre de l’équipe pédagogique de mon ancien établissement m’a aidé·e": "Avec l’aide de l’ancien établissement",
};
16 changes: 14 additions & 2 deletions server/src/services/temoignages.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
getFormattedResponses,
getGemVerbatimsByWantedQuestionKey,
getReponseRating,
getTrouverEntrepriseRating,
matchCardTypeAndQuestions,
matchIdAndQuestions,
verbatimsAnOrderedThemeAnswersMatcher,
Expand Down Expand Up @@ -209,14 +210,24 @@ export const getDatavisualisationFormation = async (intituleFormation, cfd, idCe
const query = { campagneIds };
const temoignages = await temoignagesDao.findAll(query);

if (!temoignages.length) {
if (!temoignages.length || temoignages.length === 1) {
return { success: true, body: { temoignagesCount: 0 } };
}

const commentVisTonExperienceEntreprise = temoignages
.map((temoignage) => temoignage.reponses["commentVisTonExperienceEntreprise"])
.filter(Boolean);

const cfaAideTrouverEntreprise = temoignages
.map((temoignage) => temoignage.reponses["cfaAideTrouverEntreprise"])
.filter(Boolean);

const commentTrouverEntreprise = temoignages
.map((temoignage) => temoignage.reponses["commentTrouverEntreprise"])
.filter(Boolean);

const trouverEntrepriseRating = getTrouverEntrepriseRating(cfaAideTrouverEntreprise, commentTrouverEntreprise);

const commentVisTonExperienceEntrepriseRating = getCommentVisTonExperienceEntrepriseRating(
commentVisTonExperienceEntreprise
);
Expand Down Expand Up @@ -253,7 +264,7 @@ export const getDatavisualisationFormation = async (intituleFormation, cfd, idCe
);

const allGems = getGemVerbatimsByWantedQuestionKey(verbatimsWithEtablissement);
const gems = getGemVerbatimsByWantedQuestionKey(verbatimsWithEtablissement.splice(0, 10));
const gems = getGemVerbatimsByWantedQuestionKey(verbatimsWithEtablissement.splice(0, 5));

const etablissementsCount = temoignages.reduce((acc, temoignage) => {
if (temoignage.etablissementFormateurEntrepriseRaisonSociale) {
Expand All @@ -273,6 +284,7 @@ export const getDatavisualisationFormation = async (intituleFormation, cfd, idCe
gems,
verbatimsByQuestions: allGems,
commentVisTonExperienceEntrepriseRating,
trouverEntrepriseRating,
};

return { success: true, body: result };
Expand Down
39 changes: 39 additions & 0 deletions server/src/utils/temoignages.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
NEW_ANSWER_LABELS_TO_FORMATION_VERBATIM_THEMES,
QUESTION_LABELS_BY_QUESTION_KEY,
QUESTION_LABELS_BY_QUESTION_KEY,
TROUVER_ENTREPRISE_LABEL_MATCHER,
VERBATIM_STATUS,
} from "../constants";

Expand Down Expand Up @@ -560,3 +561,41 @@ export const getCommentVisTonExperienceEntrepriseRating = (commentVisTonExperien

return result;
};

export const getTrouverEntrepriseRating = (cfaAideTrouverEntreprise, commentTrouverEntreprise) => {
const helpedFromCfa = cfaAideTrouverEntreprise.filter(
(response) => response === "Oui j’ai eu besoin de lui et il m’a aidé"
);

const mergedAndFlattenReponses = [...helpedFromCfa, ...commentTrouverEntreprise].flat();

const occurrences = mergedAndFlattenReponses.reduce((acc, str) => {
acc[str] = (acc[str] || 0) + 1;
return acc;
}, {});

const total = mergedAndFlattenReponses.length;

let result = Object.entries(occurrences).map(([key, count]) => ({
label: TROUVER_ENTREPRISE_LABEL_MATCHER[key] || key,
count,
percentage: (count / total) * 100,
}));

result = result
.sort((a, b) => b.percentage - a.percentage)
.map((item) => {
item.percentage = Math.round(item.percentage);
return item;
});

const roundedTotal = result.reduce((sum, item) => sum + item.percentage, 0);
let diff = 100 - roundedTotal;

for (let i = 0; diff !== 0; i++) {
result[i % result.length].percentage += diff > 0 ? 1 : -1;
diff += diff > 0 ? -1 : 1;
}

return result;
};
Loading

0 comments on commit 0ca13a1

Please sign in to comment.