maj api+formation+app+main et maj index
This commit is contained in:
+15
-125
@@ -1,131 +1,21 @@
|
||||
// Échapper les apostrophes dans les valeurs injectées dans la clause where
|
||||
function echapperValeur(valeur) {
|
||||
return String(valeur).replace(/'/g, "\\'");
|
||||
export function buildURL(query) {
|
||||
let url =
|
||||
"https://data.enseignementsup-recherche.gouv.fr/api/explore/v2.1/catalog/datasets/fr-esr-parcoursup/records?limit=10"
|
||||
|
||||
if (query && query.trim() !== "") {
|
||||
url += "&where=search(lib_for_voe_ins, '" + query + "')"
|
||||
}
|
||||
|
||||
return url
|
||||
}
|
||||
|
||||
// Construire l'URL de requête vers l'API Parcoursup
|
||||
export function construireURL(requete, limite = 20, decalage = 0, filtres = {}) {
|
||||
export async function fetchFormations(query) {
|
||||
const url = buildURL(query)
|
||||
const response = await fetch(url)
|
||||
|
||||
var url = "https://data.enseignementsup-recherche.gouv.fr/api/explore/v2.1/catalog/datasets/fr-esr-parcoursup/records?";
|
||||
|
||||
url += "limit=" + limite;
|
||||
url += "&offset=" + decalage;
|
||||
|
||||
var conditions = [];
|
||||
|
||||
if (requete && requete.trim() !== "") {
|
||||
conditions.push("search(lib_for_voe_ins, '" + echapperValeur(requete.trim()) + "')");
|
||||
if (!response.ok) {
|
||||
throw new Error("Erreur HTTP")
|
||||
}
|
||||
|
||||
if (filtres.filiere && filtres.filiere !== "") {
|
||||
conditions.push("fili='" + echapperValeur(filtres.filiere) + "'");
|
||||
}
|
||||
|
||||
if (filtres.selectivite && filtres.selectivite !== "") {
|
||||
conditions.push("select_form='" + echapperValeur(filtres.selectivite) + "'");
|
||||
}
|
||||
|
||||
if (filtres.region && filtres.region !== "") {
|
||||
conditions.push("region_etab_aff='" + echapperValeur(filtres.region) + "'");
|
||||
}
|
||||
|
||||
if (filtres.tauxMin && filtres.tauxMin > 0) {
|
||||
conditions.push("taux_acces_ens>=" + filtres.tauxMin);
|
||||
}
|
||||
|
||||
if (filtres.tauxMax && filtres.tauxMax < 100) {
|
||||
conditions.push("taux_acces_ens<=" + filtres.tauxMax);
|
||||
}
|
||||
|
||||
if (conditions.length > 0) {
|
||||
url += "&where=" + encodeURIComponent(conditions.join(" AND "));
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
// Charger les formations depuis l'API Parcoursup
|
||||
export async function chargerFormations(requete, limite = 20, decalage = 0, filtres = {}) {
|
||||
|
||||
var url = construireURL(requete, limite, decalage, filtres);
|
||||
var reponse = await fetch(url);
|
||||
|
||||
if (!reponse.ok) {
|
||||
throw new Error("Erreur HTTP " + reponse.status);
|
||||
}
|
||||
|
||||
return await reponse.json();
|
||||
}
|
||||
|
||||
// Charger l'historique d'une formation sur plusieurs années
|
||||
export async function chargerHistoriqueFormation(codUai, nomFormation) {
|
||||
|
||||
var jeuDeDonnees = {
|
||||
2020: "fr-esr-parcoursup_2020",
|
||||
2021: "fr-esr-parcoursup_2021",
|
||||
2022: "fr-esr-parcoursup_2022",
|
||||
2023: "fr-esr-parcoursup_2023",
|
||||
2024: "fr-esr-parcoursup_2024",
|
||||
2025: "fr-esr-parcoursup"
|
||||
};
|
||||
|
||||
var historique = [];
|
||||
var nomCourt = echapperValeur((nomFormation || "").substring(0, 40));
|
||||
var codeUai = echapperValeur(codUai);
|
||||
var annees = [2020, 2021, 2022, 2023, 2024, 2025];
|
||||
|
||||
for (var i = 0; i < annees.length; i++) {
|
||||
|
||||
var annee = annees[i];
|
||||
var dataset = jeuDeDonnees[annee];
|
||||
|
||||
try {
|
||||
|
||||
var where =
|
||||
"cod_uai='" + codeUai + "' AND search(lib_for_voe_ins, '" + nomCourt + "')";
|
||||
|
||||
var url = "https://data.enseignementsup-recherche.gouv.fr/api/explore/v2.1/catalog/datasets/"
|
||||
+ dataset + "/records?"
|
||||
+ "limit=5"
|
||||
+ "&where=" + encodeURIComponent(where)
|
||||
+ "&select=" + encodeURIComponent("cod_uai,lib_for_voe_ins,voe_tot,acc_tot,pct_sansmention,pct_ab,pct_b,pct_tb,pct_tbf,pct_bg,pct_bt,pct_bp");
|
||||
|
||||
var reponse = await fetch(url);
|
||||
|
||||
if (reponse.ok) {
|
||||
|
||||
var donnees = await reponse.json();
|
||||
|
||||
if (donnees.results && donnees.results.length > 0) {
|
||||
|
||||
var ligne = donnees.results[0];
|
||||
var taux = 0;
|
||||
|
||||
if (ligne.voe_tot && ligne.voe_tot > 0) {
|
||||
taux = Math.round((ligne.acc_tot / ligne.voe_tot) * 100);
|
||||
}
|
||||
|
||||
historique.push({
|
||||
annee: annee,
|
||||
tauxAcces: taux,
|
||||
candidats: ligne.voe_tot || 0,
|
||||
admis: ligne.acc_tot || 0,
|
||||
pctSansMention: ligne.pct_sansmention || 0,
|
||||
pctAB: ligne.pct_ab || 0,
|
||||
pctB: ligne.pct_b || 0,
|
||||
pctTB: ligne.pct_tb || 0,
|
||||
pctTBF: ligne.pct_tbf || 0,
|
||||
pctGeneral: ligne.pct_bg || 0,
|
||||
pctTechno: ligne.pct_bt || 0,
|
||||
pctPro: ligne.pct_bp || 0
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.warn("Erreur pour l'année " + annee + " :", e);
|
||||
}
|
||||
}
|
||||
|
||||
return historique;
|
||||
return await response.json()
|
||||
}
|
||||
+67
-536
File diff suppressed because it is too large
Load Diff
+18
-92
@@ -1,97 +1,23 @@
|
||||
// Créer un objet formation à partir des données brutes de l'API
|
||||
export function creerFormation(brut) {
|
||||
export function createFormation(raw) {
|
||||
let taux = 0
|
||||
|
||||
var taux = 0;
|
||||
var latitude = null;
|
||||
var longitude = null;
|
||||
|
||||
if (brut.voe_tot && brut.voe_tot > 0) {
|
||||
taux = Math.round((brut.acc_tot / brut.voe_tot) * 100);
|
||||
}
|
||||
|
||||
if (brut.g_olocalisation_des_formations) {
|
||||
latitude = brut.g_olocalisation_des_formations.lat;
|
||||
longitude = brut.g_olocalisation_des_formations.lon;
|
||||
if (raw.voe_tot && raw.voe_tot > 0) {
|
||||
taux = Math.round((raw.acc_tot / raw.voe_tot) * 100)
|
||||
}
|
||||
|
||||
return {
|
||||
id: brut.cod_uai + "-" + brut.lib_for_voe_ins,
|
||||
|
||||
nom: brut.lib_for_voe_ins,
|
||||
etablissement: brut.g_ea_lib_vx,
|
||||
ville: brut.ville_etab,
|
||||
departement: brut.dep,
|
||||
departementLib: brut.dep_lib,
|
||||
region: brut.region_etab_aff,
|
||||
academie: brut.acad_mies,
|
||||
contrat: brut.contrat_etab,
|
||||
|
||||
filiere: brut.fili,
|
||||
selectivite: brut.select_form,
|
||||
|
||||
capacite: brut.capa_fin,
|
||||
candidats: brut.voe_tot,
|
||||
admis: brut.acc_tot,
|
||||
tauxAcces: taux,
|
||||
|
||||
latitude: latitude,
|
||||
longitude: longitude,
|
||||
|
||||
pctFemmes: brut.pct_f,
|
||||
pctBoursiers: brut.pct_bours,
|
||||
pctNeoBac: brut.pct_neobac,
|
||||
|
||||
pctGeneral: brut.pct_bg,
|
||||
pctTechno: brut.pct_bt,
|
||||
pctPro: brut.pct_bp,
|
||||
|
||||
pctSansMention: brut.pct_sansmention,
|
||||
pctAB: brut.pct_ab,
|
||||
pctB: brut.pct_b,
|
||||
pctTB: brut.pct_tb,
|
||||
pctTBF: brut.pct_tbf,
|
||||
|
||||
pctDebutPhase: brut.pct_acc_debutpp,
|
||||
pctDateBac: brut.pct_acc_datebac,
|
||||
pctFinPhase: brut.pct_acc_finpp,
|
||||
|
||||
admisDebutPhase: brut.acc_debutpp,
|
||||
admisDateBac: brut.acc_datebac,
|
||||
admisFinPhase: brut.acc_finpp,
|
||||
|
||||
// Phase principale
|
||||
voePPGeneral: brut.nb_voe_pp_bg,
|
||||
voePPTechno: brut.nb_voe_pp_bt,
|
||||
voePPPro: brut.nb_voe_pp_bp,
|
||||
voePPAutres: brut.nb_voe_pp_at,
|
||||
voePPTotal: brut.nb_voe_pp,
|
||||
|
||||
classesPPGeneral: brut.nb_cla_pp_bg,
|
||||
classesPPTechno: brut.nb_cla_pp_bt,
|
||||
classesPPPro: brut.nb_cla_pp_bp,
|
||||
classesPPAutres: brut.nb_cla_pp_at,
|
||||
classesPPTotal: brut.nb_cla_pp,
|
||||
|
||||
propositionsPPGeneral: brut.prop_tot_bg,
|
||||
propositionsPPTechno: brut.prop_tot_bt,
|
||||
propositionsPPPro: brut.prop_tot_bp,
|
||||
propositionsPPAutres: brut.prop_tot_at,
|
||||
propositionsPPTotal: brut.prop_tot,
|
||||
|
||||
acceptesPPGeneral: brut.acc_bg,
|
||||
acceptesPPTechno: brut.acc_bt,
|
||||
acceptesPPPro: brut.acc_bp,
|
||||
acceptesPPAutres: brut.acc_at,
|
||||
acceptesPPTotal: brut.acc_pp,
|
||||
|
||||
// Phase complémentaire
|
||||
voePCGeneral: brut.nb_voe_pc_bg,
|
||||
voePCTechno: brut.nb_voe_pc_bt,
|
||||
voePCPro: brut.nb_voe_pc_bp,
|
||||
voePCAutres: brut.nb_voe_pc_at,
|
||||
voePCTotal: brut.nb_voe_pc,
|
||||
|
||||
classesPCTotal: brut.nb_cla_pc,
|
||||
acceptesPCTotal: brut.acc_pc
|
||||
};
|
||||
id: raw.cod_uai + "-" + raw.lib_for_voe_ins,
|
||||
nom: raw.lib_for_voe_ins,
|
||||
etablissement: raw.g_ea_lib_vx,
|
||||
ville: raw.ville_etab,
|
||||
departement: raw.dep,
|
||||
filiere: raw.fili,
|
||||
selectivite: raw.select_form,
|
||||
capacite: raw.capa_fin,
|
||||
candidats: raw.voe_tot,
|
||||
admis: raw.acc_tot,
|
||||
tauxAcces: taux,
|
||||
latitude: raw.g_olocalisation_des_formations ? raw.g_olocalisation_des_formations.lat : null,
|
||||
longitude: raw.g_olocalisation_des_formations ? raw.g_olocalisation_des_formations.lon : null
|
||||
}
|
||||
}
|
||||
+18
-51
@@ -1,58 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Parcoursup Explorer</title>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Parcoursup Riot</title>
|
||||
|
||||
<link rel="stylesheet" href="./style.css" />
|
||||
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/charts.css/dist/charts.min.css" />
|
||||
<script src="https://cdn.jsdelivr.net/npm/riot@9/riot+compiler.min.js"></script>
|
||||
<script type="module">
|
||||
import "./api.js"
|
||||
import "./formation.js"
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<app></app>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/riot@9/riot+compiler.min.js"></script>
|
||||
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<app></app>
|
||||
<script src="./app.riot" type="riot"></script>
|
||||
|
||||
<script src="./components/search-bar.riot" type="riot"></script>
|
||||
<script src="./components/result-list.riot" type="riot"></script>
|
||||
<script src="./components/detail-view.riot" type="riot"></script>
|
||||
<script src="./components/map-view.riot" type="riot"></script>
|
||||
<script src="./components/auth-panel.riot" type="riot"></script>
|
||||
<script src="./app.riot" type="riot"></script>
|
||||
|
||||
<script type="module">
|
||||
import { chargerFormations, chargerHistoriqueFormation } from './api.js'
|
||||
import { creerFormation } from './formation.js'
|
||||
import {
|
||||
auth,
|
||||
db,
|
||||
createAccount,
|
||||
login,
|
||||
logout,
|
||||
onUserChanged,
|
||||
saveUserData,
|
||||
loadUserData
|
||||
} from './firebase.js'
|
||||
|
||||
window.chargerFormations = chargerFormations
|
||||
window.creerFormation = creerFormation
|
||||
window.chargerHistoriqueFormation = chargerHistoriqueFormation
|
||||
|
||||
window.firebaseServices = {
|
||||
auth,
|
||||
db,
|
||||
createAccount,
|
||||
login,
|
||||
logout,
|
||||
onUserChanged,
|
||||
saveUserData,
|
||||
loadUserData
|
||||
}
|
||||
|
||||
await riot.compile()
|
||||
<script>
|
||||
riot.compile().then(() => {
|
||||
riot.mount('app')
|
||||
</script>
|
||||
</body>
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user