diff --git a/client/src/api/atlas.ts b/client/src/api/atlas.ts index 9e37a78d..0c506b3b 100644 --- a/client/src/api/atlas.ts +++ b/client/src/api/atlas.ts @@ -33,7 +33,6 @@ export async function getNumberOfStudentsHistoricByLevel(geoId: string, currentY if (geoId.startsWith('U')) { level = `niveau_geo=COMMUNE&uucr_id=${geoId}`; } if (geoId === ('PAYS_100')) { level = `niveau_geo=REGION`; } - const url = `${VITE_APP_SERVER_URL}/atlas/number-of-students-historic-by-level?${level}` const data = await fetch(url).then((response) => (response.json())); @@ -83,4 +82,28 @@ export async function getGeoIdsFromSearch(q: string) { export async function getParentsFromGeoId(geoId: string) { const url = `${VITE_APP_SERVER_URL}/atlas/get-parents-from-geo-id?geo_id=${geoId}`; return fetch(url).then((response) => (response.json())) +} + +export async function getNumberOfStudentsBySectorAndSublevel(geoId: string, currentYear: string) { + // ex: http://localhost:3000/api/atlas/number-of-students-by-sector-and-sublevel?aca_id=A11&niveau_geo=DEPARTEMENT + let params = `niveau_geo=COMMUNE&geo_id=${geoId}&annee_universitaire=${currentYear}`; + if (geoId.startsWith('R')) { params = `niveau_geo=ACADEMIE®_id=${geoId}`; } + if (geoId.startsWith('D')) { params = `niveau_geo=COMMUNE&dep_id=${geoId}`; } + if (geoId.startsWith('A')) { params = `niveau_geo=DEPARTEMENT&aca_id=${geoId}`; } + if (geoId.startsWith('U')) { params = `niveau_geo=COMMUNE&uucr_id=${geoId}`; } + if (geoId === ('PAYS_100')) { params = `niveau_geo=REGION`; } + const url = `${VITE_APP_SERVER_URL}/atlas/number-of-students-by-sector-and-sublevel?${params}` + return fetch(url).then((response) => (response.json())) +} + +export async function getNumberOfStudentsByGenderAndSublevel(geoId: string, currentYear: string) { + // ex: http://localhost:3000/api/atlas/number-of-students-by-gender-and-sublevel?aca_id=A11&niveau_geo=DEPARTEMENT + let params = `niveau_geo=COMMUNE&geo_id=${geoId}&annee_universitaire=${currentYear}`; + if (geoId.startsWith('R')) { params = `niveau_geo=ACADEMIE®_id=${geoId}`; } + if (geoId.startsWith('D')) { params = `niveau_geo=COMMUNE&dep_id=${geoId}`; } + if (geoId.startsWith('A')) { params = `niveau_geo=DEPARTEMENT&aca_id=${geoId}`; } + if (geoId.startsWith('U')) { params = `niveau_geo=COMMUNE&uucr_id=${geoId}`; } + if (geoId === ('PAYS_100')) { params = `niveau_geo=REGION`; } + const url = `${VITE_APP_SERVER_URL}/atlas/number-of-students-by-gender-and-sublevel?${params}` + return fetch(url).then((response) => (response.json())) } \ No newline at end of file diff --git a/client/src/pages/atlas/charts/atlas-map.tsx b/client/src/pages/atlas/charts/atlas-map.tsx index d6995b02..8fb403c8 100644 --- a/client/src/pages/atlas/charts/atlas-map.tsx +++ b/client/src/pages/atlas/charts/atlas-map.tsx @@ -1,35 +1,36 @@ -import { Container, Row, Col, Button, Title, Badge } from "@dataesr/dsfr-plus"; +import { + Badge, + Button, + Container, Row, Col, + Title, +} from "@dataesr/dsfr-plus"; import { - useSearchParams, + useLocation, useNavigate, - useLocation + useSearchParams, } from "react-router-dom"; - import * as turf from '@turf/turf'; -import Template from "../../../components/template/index.tsx"; -import { getNumberOfStudentsHistoricByLevel, getGeoPolygon } from "../../../api/atlas.ts"; +import { getNumberOfStudentsHistoricByLevel, getGeoPolygon, getNumberOfStudentsBySectorAndSublevel, getNumberOfStudentsByGenderAndSublevel } from "../../../api/atlas.ts"; +import { MapBubbleDataProps } from "../../../types/atlas.ts"; import { useQuery } from "@tanstack/react-query"; +import MapSkeleton from "./skeletons/map.tsx"; import MapWithPolygonHighcharts from "./map-with-polygon-highcharts.tsx"; -import { MapBubbleDataProps } from "../../../types/atlas.ts"; -import MapWithPolygonHighchartsPie from "./map-with-polygon-highcharts-pie/index.tsx"; - +import MapPieSectors from "./map-pie-sectors/index.jsx"; +import MapPieGender from "./map-pie-genders/index.jsx"; +import Template from "../../../components/template/index.tsx"; export default function AtlasMap() { const location = useLocation(); const path = location.pathname.split('/'); const selectedTab = path[path.length - 1]; - - console.log('selectedTab', selectedTab); - const [searchParams] = useSearchParams(); const navigate = useNavigate(); - const geoId = searchParams.get('geo_id') || ''; const currentYear = searchParams.get('annee_universitaire') || '2022-23'; const { data: dataHistoric, isLoading: isLoadingHistoric } = useQuery({ - queryKey: ["atlas/number-of-students-historic-by-level", geoId], + queryKey: ["atlas/number-of-students-historic-by-level", geoId, currentYear], queryFn: () => getNumberOfStudentsHistoricByLevel(geoId, currentYear) }) @@ -38,9 +39,19 @@ export default function AtlasMap() { queryFn: () => getGeoPolygon(geoId) }) + const { data: dataSectors, isLoading: isLoadingDataSectors } = useQuery({ + queryKey: ["atlas/get-number-of-students-by-sector-and-sublevel", geoId, currentYear], + queryFn: () => getNumberOfStudentsBySectorAndSublevel(geoId, currentYear) + }) + + const { data: dataGenders, isLoading: isLoadingDataGenders } = useQuery({ + queryKey: ["atlas/get-number-of-students-by-gender-and-sublevel", geoId, currentYear], + queryFn: () => getNumberOfStudentsByGenderAndSublevel(geoId, currentYear) + }) + if (isLoadingPolygons || !polygonsData || !polygonsData.length || isLoadingHistoric || !dataHistoric?.data || !dataHistoric?.data.length) { - return