feat: (broken) implement route map and address autocomplete widgets with associated infrastructure testing scripts
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
/**
|
||||
* Test final :
|
||||
* 1. 03003 → 03087 (tarif ?)
|
||||
* 2. Google travelAdvisory.tollInfo pour Saint-Martin → Grenoble
|
||||
* 3. Identifier pourquoi VOREPPE n'est pas détecté par Ulys
|
||||
*/
|
||||
const axios = require('axios');
|
||||
const polylineLib = require('@mapbox/polyline');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
let API_MAPS = '';
|
||||
const envContent = fs.readFileSync(path.join(__dirname, '.env'), 'utf-8');
|
||||
for (const line of envContent.split('\n')) {
|
||||
const m = line.match(/^API_MAPS=(.+)/);
|
||||
if (m) API_MAPS = m[1].trim().replace(/"/g, '');
|
||||
}
|
||||
|
||||
async function testRate(vehicleCategory, tollPassages, label) {
|
||||
try {
|
||||
const res = await axios.post(
|
||||
'https://api-ulys.azure-api.net/tollstation/v1/rate',
|
||||
{ vehicleCategory: String(vehicleCategory), paymentOption: 2, tollPassages },
|
||||
{ headers: { 'Content-Type': 'application/json' }, timeout: 8000 }
|
||||
);
|
||||
const data = res.data;
|
||||
const total = Array.isArray(data) ? data.reduce((s, d) => s + (d.price || 0), 0) : 0;
|
||||
const comment = Array.isArray(data) && data[0] ? (data[0].comments || []).join(', ') : '';
|
||||
console.log(` [cl${vehicleCategory}] ${label}: ${total}€ ${comment ? '('+comment+')' : ''}`);
|
||||
return total;
|
||||
} catch (e) {
|
||||
console.log(` ERROR: ${e.message}`);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
const now = new Date().toISOString();
|
||||
|
||||
async function main() {
|
||||
console.log('=== TEST 1: Combinations de gares A43+A48 pour Saint-Martin → Grenoble ===\n');
|
||||
|
||||
// 03003 → 03087 (Isle d'Abeau → Voreppe) - système fermé?
|
||||
await testRate(1, [
|
||||
{ toll: { operatorId: '03', tollId: '003' }, passageDate: now },
|
||||
{ toll: { operatorId: '03', tollId: '087' }, passageDate: now }
|
||||
], '03003→03087 (Isle d\'Abeau→Voreppe)');
|
||||
await testRate(2, [
|
||||
{ toll: { operatorId: '03', tollId: '003' }, passageDate: now },
|
||||
{ toll: { operatorId: '03', tollId: '087' }, passageDate: now }
|
||||
], '03003→03087');
|
||||
|
||||
// Essayer toutes les paires gares sur A48
|
||||
const a48gates = [
|
||||
{ op: '03', toll: '083', name: 'MOIRANS NORD' },
|
||||
{ op: '03', toll: '084', name: 'MOIRANS' },
|
||||
{ op: '03', toll: '085', name: 'RIVES' },
|
||||
{ op: '03', toll: '086', name: 'VOIRON' },
|
||||
{ op: '03', toll: '087', name: 'VOREPPE' },
|
||||
{ op: '03', toll: '091', name: 'CHATUZANGE' },
|
||||
{ op: '03', toll: '092', name: 'BAUME HOSTUN' },
|
||||
{ op: '03', toll: '093', name: 'ST MARCELLIN' },
|
||||
{ op: '03', toll: '094', name: 'VINAY' },
|
||||
{ op: '03', toll: '095', name: 'TULLINS' },
|
||||
];
|
||||
|
||||
console.log('\n03003 (Isle d\'Abeau) → toutes les gares A48:');
|
||||
for (const g of a48gates) {
|
||||
await testRate(2, [
|
||||
{ toll: { operatorId: '03', tollId: '003' }, passageDate: now },
|
||||
{ toll: { operatorId: g.op, tollId: g.toll }, passageDate: now }
|
||||
], `03003→${g.toll} ${g.name}`);
|
||||
}
|
||||
|
||||
console.log('\n=== TEST 2: Google Routes API - travelAdvisory.tollInfo ===\n');
|
||||
|
||||
const res = await axios.post('https://routes.googleapis.com/directions/v2:computeRoutes', {
|
||||
travelMode: 'DRIVE',
|
||||
routingPreference: 'TRAFFIC_AWARE',
|
||||
routeModifiers: { avoidTolls: false },
|
||||
origin: { address: '25 Impasse du Puits du Suc, Saint-Martin-en-Haut, France' },
|
||||
destination: { address: 'Grenoble, France' },
|
||||
}, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Goog-Api-Key': API_MAPS,
|
||||
'X-Goog-FieldMask': 'routes.distanceMeters,routes.duration,routes.polyline.encodedPolyline,routes.travelAdvisory.tollInfo',
|
||||
},
|
||||
timeout: 15000,
|
||||
});
|
||||
|
||||
const r = res.data.routes[0];
|
||||
console.log(`Distance: ${Math.round(r.distanceMeters/1000)}km`);
|
||||
console.log(`travelAdvisory:`, JSON.stringify(r.travelAdvisory, null, 2));
|
||||
|
||||
console.log('\n=== TEST 3: Diagnostiquer pourquoi VOREPPE n\'est pas dans Ulys ===\n');
|
||||
|
||||
// Récupérer la polyline complète et identifier les points proches de VOREPPE
|
||||
const poly = r.polyline.encodedPolyline;
|
||||
const coords = polylineLib.decode(poly, 5);
|
||||
|
||||
// VOREPPE BARRIERE: 45.28323°N, 5.622°E
|
||||
const VOREPPE = [45.28323, 5.622];
|
||||
|
||||
let minDist = Infinity;
|
||||
let closestIdx = -1;
|
||||
for (let i = 0; i < coords.length; i++) {
|
||||
const [lat, lng] = coords[i];
|
||||
const dist = Math.sqrt(Math.pow(lat - VOREPPE[0], 2) + Math.pow(lng - VOREPPE[1], 2));
|
||||
if (dist < minDist) {
|
||||
minDist = dist;
|
||||
closestIdx = i;
|
||||
}
|
||||
}
|
||||
|
||||
const minDistKm = minDist * 111; // approximation 1° ≈ 111km
|
||||
console.log(`Point le plus proche de VOREPPE (45.283, 5.622):`);
|
||||
console.log(` Index ${closestIdx}/${coords.length-1}: ${JSON.stringify(coords[closestIdx])}`);
|
||||
console.log(` Distance: ${minDistKm.toFixed(2)} km`);
|
||||
|
||||
if (minDistKm > 2) {
|
||||
console.log(` -> Le tracé NE PASSE PAS par VOREPPE (trop loin: ${minDistKm.toFixed(1)}km)`);
|
||||
console.log(' -> Google route par une autre voie que A48 vers Grenoble!');
|
||||
} else {
|
||||
console.log(` -> Le tracé passe PRÈS de VOREPPE (${minDistKm.toFixed(2)}km)`);
|
||||
}
|
||||
|
||||
// Vérifier aussi ST QUENTIN (03001): 45.641°N, 5.119°E (d'après le CSV)
|
||||
const STQUENTIN001 = [45.641, 5.119];
|
||||
let minDist2 = Infinity;
|
||||
for (const [lat, lng] of coords) {
|
||||
const d = Math.sqrt(Math.pow(lat - STQUENTIN001[0], 2) + Math.pow(lng - STQUENTIN001[1], 2));
|
||||
if (d < minDist2) minDist2 = d;
|
||||
}
|
||||
console.log(`\nDistance du tracé à ST QUENTIN 03001 (45.641, 5.119): ${(minDist2*111).toFixed(2)} km`);
|
||||
|
||||
// Regarder la zone géographique couverte par la route
|
||||
const lats = coords.map(c => c[0]);
|
||||
const lngs = coords.map(c => c[1]);
|
||||
console.log(`\nBounding box de la route:`);
|
||||
console.log(` Lat: ${Math.min(...lats).toFixed(4)} → ${Math.max(...lats).toFixed(4)}`);
|
||||
console.log(` Lng: ${Math.min(...lngs).toFixed(4)} → ${Math.max(...lngs).toFixed(4)}`);
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
Reference in New Issue
Block a user