diff --git a/parcoursup/api.js b/parcoursup/api.js index a263180..20b2c65 100644 --- a/parcoursup/api.js +++ b/parcoursup/api.js @@ -1,19 +1,45 @@ -export function buildURL(query, limit = 20, offset = 0) { +export function buildURL(query, limit = 20, offset = 0, filters = {}) { let url = "https://data.enseignementsup-recherche.gouv.fr/api/explore/v2.1/catalog/datasets/fr-esr-parcoursup/records?" url += "limit=" + limit url += "&offset=" + offset + var conditions = [] + if (query && query.trim() !== "") { - url += "&where=search(lib_for_voe_ins, '" + query + "')" + conditions.push("search(lib_for_voe_ins, '" + query + "')") + } + + if (filters.filiere && filters.filiere !== "") { + conditions.push("fili='" + filters.filiere + "'") + } + + if (filters.selectivite && filters.selectivite !== "") { + conditions.push("select_form='" + filters.selectivite + "'") + } + + if (filters.region && filters.region !== "") { + conditions.push("region_etab_aff='" + filters.region + "'") + } + + if (filters.tauxMin && filters.tauxMin > 0) { + conditions.push("taux_acces_ens>=" + filters.tauxMin) + } + + if (filters.tauxMax && filters.tauxMax < 100) { + conditions.push("taux_acces_ens<=" + filters.tauxMax) + } + + if (conditions.length > 0) { + url += "&where=" + conditions.join(" AND ") } return url } -export async function fetchFormations(query, limit = 20, offset = 0) { - const url = buildURL(query, limit, offset) +export async function fetchFormations(query, limit = 20, offset = 0, filters = {}) { + const url = buildURL(query, limit, offset, filters) const response = await fetch(url) if (!response.ok) { @@ -21,4 +47,66 @@ export async function fetchFormations(query, limit = 20, offset = 0) { } return await response.json() -} \ No newline at end of file +} + +export async function fetchFormationHistory(codUai, nomFormation) { + var datasets = { + 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 history = [] + var searchName = nomFormation.substring(0, 40).replace(/'/g, "\\'") + var years = [2020, 2021, 2022, 2023, 2024, 2025] + + for (var i = 0; i < years.length; i++) { + var year = years[i] + var dataset = datasets[year] + + try { + var url = "https://data.enseignementsup-recherche.gouv.fr/api/explore/v2.1/catalog/datasets/" + + dataset + "/records?" + + "limit=5" + + "&where=cod_uai%3D'" + codUai + "' AND search(lib_for_voe_ins, '" + searchName + "')" + + "&select=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 response = await fetch(url) + + if (response.ok) { + var data = await response.json() + + if (data.results && data.results.length > 0) { + var r = data.results[0] + var taux = 0 + + if (r.voe_tot && r.voe_tot > 0) { + taux = Math.round((r.acc_tot / r.voe_tot) * 100) + } + + history.push({ + annee: year, + tauxAcces: taux, + candidats: r.voe_tot || 0, + admis: r.acc_tot || 0, + pctSansMention: r.pct_sansmention || 0, + pctAB: r.pct_ab || 0, + pctB: r.pct_b || 0, + pctTB: r.pct_tb || 0, + pctTBF: r.pct_tbf || 0, + pctGeneral: r.pct_bg || 0, + pctTechno: r.pct_bt || 0, + pctPro: r.pct_bp || 0 + }) + } + } + } catch (e) { + console.warn("Erreur pour " + year + ":", e) + } + } + + return history +} diff --git a/parcoursup/app.riot b/parcoursup/app.riot index 3ba175f..e597f1b 100644 --- a/parcoursup/app.riot +++ b/parcoursup/app.riot @@ -2,10 +2,10 @@