Skip to content

Commit 879e3da

Browse files
committed
feat: enhance line disruption fetching for specific stops and route types
1 parent e39363c commit 879e3da

2 files changed

Lines changed: 30 additions & 8 deletions

File tree

src/pages/index.astro

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,10 +606,15 @@ import Layout from '../layouts/Layout.astro';
606606
const loadSchedules = async () => {
607607
if (monitoringRef && line.originalRouteId) {
608608
try {
609+
// Pour Métro et Tram : utiliser line_reports (pas de stop_point)
610+
// Pour RER, TER, Transilien : utiliser disruptions avec stop_point
611+
const useStopPoint = line.routeType !== 'Métro' && line.routeType !== 'Tram';
612+
const idRefZdA = useStopPoint ? monitoringRef.split(':')[3] : null;
613+
609614
// Charger horaires et perturbations en parallèle
610615
const [allSchedules, disruptions] = await Promise.all([
611616
window.fetchStopSchedules(monitoringRef, line.originalRouteId, line.routeType),
612-
window.fetchLineDisruptions(line.originalRouteId)
617+
window.fetchLineDisruptions(line.originalRouteId, idRefZdA, line.routeType)
613618
]);
614619

615620
const schedulesElement = window.generateSchedulesElement(allSchedules, line.routeType, disruptions);

src/scripts/stopMonitoring.js

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
const API_KEY = 'SvPHVJ5fPXkfJPKsu6958pwLCh5Oidhq';
66
const API_URL = 'https://prim.iledefrance-mobilites.fr/marketplace/stop-monitoring';
7-
const LINE_REPORTS_API_URL = 'https://prim.iledefrance-mobilites.fr/marketplace/v2/navitia';
7+
const LINE_REPORTS_API_URL = 'https://prim.iledefrance-mobilites.fr/marketplace/v2/navitia/line_reports';
88

99
// Configuration de l'affichage des horaires
1010
const MAX_SCHEDULES_METRO_TRAM = 5; // Nombre d'horaires affichés pour Métro/Tram
@@ -165,9 +165,9 @@ function parseSchedulesData(data) {
165165
}
166166

167167
/**
168-
* Récupère les perturbations pour une ligne
168+
* Récupère les perturbations pour une ligne et un arrêt spécifique
169169
*/
170-
export async function fetchLineDisruptions(lineRef) {
170+
export async function fetchLineDisruptions(lineRef, idRefZdA = null, routeType = null) {
171171
try {
172172
const cleanedLineRef = cleanLineRef(lineRef);
173173

@@ -176,11 +176,28 @@ export async function fetchLineDisruptions(lineRef) {
176176
return [];
177177
}
178178

179-
// Construire l'URL avec le LineRef au format Navitia
180-
const navitiaLineId = `line:IDFM:${cleanedLineRef}`;
181-
const url = `${LINE_REPORTS_API_URL}/lines/${encodeURIComponent(navitiaLineId)}/line_reports`;
179+
let url;
180+
181+
// Pour TER : utiliser uniquement le stop_point (pas de ligne), departures car il y a les disruptions par arret
182+
if (routeType === 'TER' && idRefZdA) {
183+
const stopPointId = `stop_point:IDFM:monomodalStopPlace:${idRefZdA}`;
184+
url = `${LINE_REPORTS_API_URL}/stop_points/${encodeURIComponent(stopPointId)}/departures?count=10`;
185+
console.log('📡 Récupération perturbations TER (stop_point seul):', stopPointId);
186+
}
187+
// Si idRefZdA est fourni (RER, Transilien), construire l'URL avec ligne + stop_point, departures car il y a les disruptions par arret
188+
else if (idRefZdA) {
189+
const navitiaLineId = `line:IDFM:${cleanedLineRef}`;
190+
const stopPointId = `stop_point:IDFM:monomodalStopPlace:${idRefZdA}`;
191+
url = `${LINE_REPORTS_API_URL}/lines/${encodeURIComponent(navitiaLineId)}/stop_points/${encodeURIComponent(stopPointId)}/departures?count=10`;
192+
console.log('📡 Récupération perturbations ligne + arrêt:', navitiaLineId, stopPointId);
193+
}
194+
// Sinon, utiliser line_reports (Métro, Tram)
195+
else {
196+
const navitiaLineId = `line:IDFM:${cleanedLineRef}`;
197+
url = `${LINE_REPORTS_API_URL}/lines/${encodeURIComponent(navitiaLineId)}/line_reports`;
198+
console.log('📡 Récupération perturbations ligne:', navitiaLineId);
199+
}
182200

183-
console.log('📡 Récupération perturbations ligne:', navitiaLineId);
184201
console.log('📡 URL:', url);
185202

186203
const response = await fetch(url, {

0 commit comments

Comments
 (0)