Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pilotage de la réforme - taux transfo cumule v2 #561

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,8 @@
"compareFolders.ignoreWhiteSpaces": true,
"compareFolders.respectGitIgnore": true,
"eslint.useFlatConfig": false,
"eslint.options": { "overrideConfigFile": ".eslintrc.json" }
"eslint.options": { "overrideConfigFile": ".eslintrc.json" },
"[sql]": {
"editor.defaultFormatter": "ReneSaarsoo.sql-formatter-vsc"
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { getKbdClient } from "@/db/db";
import { isInPerimetreIJRegion } from "@/modules/data/utils/isInPerimetreIJ";
import { cleanNull } from "@/utils/noNull";

export const getFilters = async () => {
const regions = getKbdClient()
.selectFrom("region")
.where(isInPerimetreIJRegion)
.distinct()
.$castTo<{ label: string; value: string }>()
.select(["region.libelleRegion as label", "region.codeRegion as value"])
.orderBy("label", "asc")
.execute();

const diplomes = getKbdClient().selectFrom("niveauDiplome")
.select(["libelleNiveauDiplome as label", "codeNiveauDiplome as value"])
.where("codeNiveauDiplome", "is not", null)
.where("codeNiveauDiplome", "in", ["500", "320", "400", "461", "561", '010', '241','401', '381', '481', '581'])
.$castTo<{ label: string; value: string }>()
.orderBy("label", "asc")
.execute();

return {
regions: (await regions).map(cleanNull),
diplomes: (await diplomes).map(cleanNull),
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { sql } from "kysely";

import { getKbdClient } from "@/db/db";

export const getRentreesScolaire = async () => {
return (await getKbdClient()
.selectFrom("campagne")
.select(eb => [
sql<number>`CAST(${eb.ref("annee")} AS INTEGER) + 1`.as("rentreeScolaire")
])
.distinct()
.execute())
.map(({rentreeScolaire}) => rentreeScolaire.toString());
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import { sql } from "kysely";
import { getMillesimeFromRentreeScolaire } from "shared/utils/getMillesime";
import { getRentreeScolaire } from "shared/utils/getRentreeScolaire";

import { getKbdClient } from "@/db/db";
import { effectifAnnee } from "@/modules/data/utils/effectifAnnee";
import { isScolaireIndicateurRegionSortie } from "@/modules/data/utils/isScolaire";
import { notAnneeCommune, notAnneeCommuneIndicateurRegionSortie } from "@/modules/data/utils/notAnneeCommune";
import { notHistorique } from "@/modules/data/utils/notHistorique";
import { selectTauxInsertion6moisAgg } from "@/modules/data/utils/tauxInsertion6mois";
import { selectTauxPoursuiteAgg } from "@/modules/data/utils/tauxPoursuite";
import { cleanNull } from "@/utils/noNull";

const getRentreesScolaires = async () => {
return await getKbdClient()
.selectFrom("indicateurEntree")
.select("rentreeScolaire")
.distinct()
.orderBy("rentreeScolaire", "desc")
.execute()
.then((rentreesScolaireArray) => rentreesScolaireArray.map((rentreeScolaire) => rentreeScolaire.rentreeScolaire));
};

const getMillesimesSortie = async () => {
return await getKbdClient()
.selectFrom("indicateurRegionSortie")
.select("millesimeSortie")
.distinct()
.orderBy("millesimeSortie", "desc")
.execute()
.then((millesimesSortieArray) => millesimesSortieArray.map((millesimeSortie) => millesimeSortie.millesimeSortie));
};

const selectStatsEffectif = async (
{ isScoped = false, annee = 0, rentreeScolaire, codeRegion, codeNiveauDiplome }:
{ isScoped: boolean; annee: number, rentreeScolaire: string, codeRegion?: string, codeNiveauDiplome?: string }) => getKbdClient()
.selectFrom("formationEtablissement")
.leftJoin("formationScolaireView as formationView", "formationView.cfd", "formationEtablissement.cfd")
.innerJoin("indicateurEntree", (join) =>
join
.onRef("formationEtablissement.id", "=", "indicateurEntree.formationEtablissementId")
.on("indicateurEntree.rentreeScolaire", "=", getRentreeScolaire({ rentreeScolaire, offset: annee }))
)
.leftJoin("etablissement", "etablissement.uai", "formationEtablissement.uai")
.$call((q) => {
if (!isScoped || !codeRegion) return q;
return q.where("etablissement.codeRegion", "=", codeRegion);
})
.$call((q) => {
if (!codeNiveauDiplome) return q;
return q.where("formationView.codeNiveauDiplome", "=", codeNiveauDiplome);
})
.where(notHistorique)
.where(notAnneeCommune)
.select([
sql<number>`COUNT(distinct CONCAT("formationEtablissement"."cfd", "formationEtablissement"."codeDispositif"))`.as(
"nbFormations"
),
sql<number>`COUNT(distinct "formationEtablissement"."uai")`.as("nbEtablissements"),
sql<number>`COALESCE(SUM(${effectifAnnee({
alias: "indicateurEntree",
})}),0)`.as("effectif"),
])
.executeTakeFirstOrThrow()
.then(cleanNull);

const selectStatsSortie = async ({ isScoped = false, annee = 0, rentreeScolaire, codeRegion, codeNiveauDiplome }:
{ isScoped: boolean; annee: number, rentreeScolaire: string, codeRegion?: string, codeNiveauDiplome?: string }) =>
getKbdClient()
.selectFrom("indicateurRegionSortie")
.leftJoin("formationScolaireView as formationView", "formationView.cfd", "indicateurRegionSortie.cfd")
.$call((q) => {
if (!isScoped || !codeRegion) return q;
return q.where("indicateurRegionSortie.codeRegion", "=", codeRegion);
})
.$call((q) => {
if (!codeNiveauDiplome) return q;
return q.where("formationView.codeNiveauDiplome", "=", codeNiveauDiplome);
})
.$call((q) =>
q.where(
"indicateurRegionSortie.millesimeSortie",
"=",
getMillesimeFromRentreeScolaire({ rentreeScolaire, offset: annee })
)
)
.where("indicateurRegionSortie.cfdContinuum", "is", null)
.where(isScolaireIndicateurRegionSortie)
.where(notAnneeCommuneIndicateurRegionSortie)
.select([
selectTauxInsertion6moisAgg("indicateurRegionSortie").as("tauxInsertion"),
selectTauxPoursuiteAgg("indicateurRegionSortie").as("tauxPoursuite"),
])
.executeTakeFirstOrThrow()
.then(cleanNull);

export const getStats = async ({
codeRegion,
codeNiveauDiplome,
}: {
codeRegion?: string;
codeNiveauDiplome?: string;
}) => {
const rentreesScolaires = await getRentreesScolaires();
const rentreeScolaire = rentreesScolaires[0];
const millesimesSortie = await getMillesimesSortie();



const getStatsAnnee = async (millesimeSortie: string) => {
// millesimeSortie est au format 2000_2001
const finDanneeScolaireMillesime = parseInt(millesimeSortie.split("_")[1]);
const rentree = parseInt(rentreeScolaire);
const offset = finDanneeScolaireMillesime - rentree;

return {
annee: finDanneeScolaireMillesime,
millesime: millesimeSortie.split("_"),
scoped: {
...(await selectStatsEffectif({ isScoped: true, annee: offset, rentreeScolaire, codeRegion, codeNiveauDiplome })),
...(await selectStatsSortie({ isScoped: true, annee: offset + 1, rentreeScolaire, codeRegion, codeNiveauDiplome })),
},
nationale: {
...(await selectStatsEffectif({ isScoped: false, annee: offset, rentreeScolaire, codeRegion, codeNiveauDiplome })),
...(await selectStatsSortie({ isScoped: false, annee: offset + 1, rentreeScolaire, codeRegion, codeNiveauDiplome })),
},
};
};

const annees = await Promise.all(millesimesSortie.map(async (millesimeSortie) => getStatsAnnee(millesimeSortie)));

return {
annees,
};
};
Loading
Loading