V0.5.0.1
This commit is contained in:
1 parent
bc9c88a548
commit
2cb9ce64cb
32 files changed
+2233
-47
No files matched your search
@@ -0,0 +1,77 @@
|
||||
const fs = require('fs');
|
||||
let code = fs.readFileSync('src/components/TrainDetailsClient.tsx', 'utf8');
|
||||
|
||||
const newPerturbationLogic = `
|
||||
// Fetch perturbations
|
||||
const parts = currentDateDisplay.split('/');
|
||||
const targetIsoDate = parts.length === 3 ? \`\${parts[2]}-\${parts[1]}-\${parts[0]}\` : new Date().toISOString().split('T')[0];
|
||||
|
||||
const { data: pertData } = await supabase.from('perturbations').select('*').eq('actif', true);
|
||||
let currentDelay = 0;
|
||||
let pArrets: any[] = [];
|
||||
|
||||
if (pertData) {
|
||||
const matchingPert = pertData.find((p: any) => {
|
||||
const matchTrain = p.horaire_id === h.id || p.horaire_id === h.numero_train;
|
||||
if (!matchTrain) return false;
|
||||
|
||||
const pStart = (p.date_debut || '').slice(0, 10);
|
||||
const pEnd = (p.date_fin || '').slice(0, 10);
|
||||
|
||||
if (pStart && pEnd && pStart <= targetIsoDate && targetIsoDate <= pEnd) return true;
|
||||
|
||||
if (p.jours_perturbation && Array.isArray(p.jours_perturbation)) {
|
||||
return p.jours_perturbation.some((jp: any) => {
|
||||
const d = (jp.date || jp.dateDebut || '').slice(0, 10);
|
||||
return d === targetIsoDate;
|
||||
});
|
||||
}
|
||||
return !pStart && !pEnd && (!p.jours_perturbation || p.jours_perturbation.length === 0);
|
||||
});
|
||||
|
||||
if (matchingPert) {
|
||||
pArrets = Array.isArray(matchingPert.perturbations_arrets) ? matchingPert.perturbations_arrets : [];
|
||||
|
||||
// Find max delay in perturbations_arrets
|
||||
let maxArretsDelay = 0;
|
||||
pArrets.forEach(pa => {
|
||||
if (pa.retard_cumule > maxArretsDelay) maxArretsDelay = pa.retard_cumule;
|
||||
if (pa.retard_entrant > maxArretsDelay) maxArretsDelay = pa.retard_entrant;
|
||||
});
|
||||
|
||||
currentDelay = maxArretsDelay > 0 ? maxArretsDelay : (matchingPert.duree_retard_minutes || 0);
|
||||
|
||||
setPerturbationInfo({
|
||||
type: matchingPert.type_perturbation || 'Retard',
|
||||
delayMinutes: currentDelay,
|
||||
message: matchingPert.cause_details || matchingPert.notes || '',
|
||||
});
|
||||
setDelayMinutes(currentDelay);
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const newResolveLogic = `
|
||||
const resolved: StopItem[] = parsedStops.map((s, idx) => {
|
||||
const prev = s.heure_depart || s.heure_arrivee || '12:00';
|
||||
let est = prev;
|
||||
|
||||
// Get delay specifically for this stop
|
||||
const stopPert = pArrets.find(pa => pa.gare_nom === s.gare_nom || pa.gare_id === s.gare_id);
|
||||
const stopDelay = stopPert && stopPert.retard_cumule !== undefined ? stopPert.retard_cumule : currentDelay;
|
||||
|
||||
if (stopDelay > 0) {
|
||||
const [hh, mm] = prev.split(':').map(Number);
|
||||
const totalMin = (hh * 60 + mm + stopDelay) % 1440;
|
||||
const newH = String(Math.floor(totalMin / 60)).padStart(2, '0');
|
||||
const newM = String(totalMin % 60).padStart(2, '0');
|
||||
est = \`\${newH}:\${newM}\`;
|
||||
}
|
||||
`;
|
||||
|
||||
// Replace fetch perturbation logic
|
||||
code = code.replace(/\/\/ Fetch perturbations[\s\S]*?(?=\/\/ Fetch materiel roulant)/, newPerturbationLogic);
|
||||
// Replace mapping logic
|
||||
code = code.replace(/const resolved: StopItem\[\] = parsedStops\.map\(\(s, idx\) => \{[\s\S]*?if \(currentDelay > 0\) \{[\s\S]*?est = `\$\{newH\}:\$\{newM\}`;\s*\}/, newResolveLogic);
|
||||
|
||||
fs.writeFileSync('src/components/TrainDetailsClient.tsx', code);
|
||||
Reference in new issue
Block a user