chore: clean up test and scratch files
This commit is contained in:
@@ -1,79 +0,0 @@
|
|||||||
const axios = require('axios');
|
|
||||||
const polylineLib = require('@mapbox/polyline');
|
|
||||||
require('dotenv').config({ path: '.env' });
|
|
||||||
const { _distKm } = require('./src/travel.js'); // Not exported, I'll copy the logic
|
|
||||||
|
|
||||||
function distKm(lat1, lng1, lat2, lng2) {
|
|
||||||
const dLat = (lat2 - lat1) * Math.PI / 180;
|
|
||||||
const dLng = (lng2 - lng1) * Math.PI / 180;
|
|
||||||
const a = Math.sin(dLat/2)**2 + Math.cos(lat1*Math.PI/180) * Math.cos(lat2*Math.PI/180) * Math.sin(dLng/2)**2;
|
|
||||||
return 6371 * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
|
|
||||||
}
|
|
||||||
|
|
||||||
async function bulkRateTest() {
|
|
||||||
const apiKey = process.env.API_MAPS;
|
|
||||||
const origin = "25 Impasse du Puits du Suc, Saint-Martin-en-Haut, France";
|
|
||||||
const destination = "Toulouse, France";
|
|
||||||
|
|
||||||
const routesUrl = 'https://routes.googleapis.com/directions/v2:computeRoutes';
|
|
||||||
const resToll = await axios.post(routesUrl, {
|
|
||||||
travelMode: 'DRIVE', routingPreference: 'TRAFFIC_UNAWARE',
|
|
||||||
origin: { address: origin }, destination: { address: destination },
|
|
||||||
}, { headers: { 'Content-Type': 'application/json', 'X-Goog-Api-Key': apiKey, 'X-Goog-FieldMask': 'routes.polyline.encodedPolyline' } });
|
|
||||||
|
|
||||||
const poly = resToll.data.routes[0].polyline.encodedPolyline;
|
|
||||||
const polylineCoords = polylineLib.decode(poly, 5);
|
|
||||||
|
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
const csvPath = path.join(__dirname, 'travel', 'gares_peage_export.csv');
|
|
||||||
const rawCsv = fs.readFileSync(csvPath, 'utf8');
|
|
||||||
const stations = [];
|
|
||||||
const lines = rawCsv.split('\n');
|
|
||||||
for (let i = 1; i < lines.length; i++) {
|
|
||||||
const l = lines[i].trim();
|
|
||||||
if (!l) continue;
|
|
||||||
const parts = l.split(',');
|
|
||||||
if (parts.length >= 4) {
|
|
||||||
const idStr = String(parts[0]).padStart(5, '0');
|
|
||||||
stations.push({
|
|
||||||
id: idStr,
|
|
||||||
operatorId: idStr.substring(0, 2),
|
|
||||||
tollId: idStr.substring(2, 5),
|
|
||||||
name: parts[1],
|
|
||||||
lat: parseFloat(parts[2]),
|
|
||||||
lon: parseFloat(parts[3]),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const candidates = [];
|
|
||||||
stations.forEach(s => {
|
|
||||||
let minDist = Infinity;
|
|
||||||
let minIndex = -1;
|
|
||||||
for (let i = 0; i < polylineCoords.length; i++) {
|
|
||||||
const d = distKm(s.lat, s.lon, polylineCoords[i][0], polylineCoords[i][1]);
|
|
||||||
if (d < minDist) { minDist = d; minIndex = i; }
|
|
||||||
}
|
|
||||||
if (minDist < 2) {
|
|
||||||
candidates.push({ ...s, polyIndex: minIndex });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
candidates.sort((a, b) => a.polyIndex - b.polyIndex);
|
|
||||||
|
|
||||||
const passages = candidates.map(c => ({
|
|
||||||
toll: { operatorId: c.operatorId, tollId: c.tollId },
|
|
||||||
passageDate: new Date().toISOString()
|
|
||||||
}));
|
|
||||||
|
|
||||||
try {
|
|
||||||
console.log(`Sending ${passages.length} passages to Ulys...`);
|
|
||||||
const res = await axios.post('https://api-ulys.azure-api.net/tollstation/v1/rate', {
|
|
||||||
vehicleCategory: "2", paymentOption: 2, tollPassages: passages
|
|
||||||
});
|
|
||||||
console.log(JSON.stringify(res.data, null, 2));
|
|
||||||
} catch(e) {
|
|
||||||
console.log(e.response ? e.response.data : e.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bulkRateTest();
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
const travel = require('./src/travel.js');
|
|
||||||
require('dotenv').config({ path: '.env' });
|
|
||||||
const auth = require('./utils/auth.js');
|
|
||||||
auth.authenticateUser = async () => ({ uid: 'dummy' });
|
|
||||||
|
|
||||||
async function test() {
|
|
||||||
const req = {
|
|
||||||
headers: { authorization: 'Bearer dummy' },
|
|
||||||
body: { origin: "25 Impasse du Puits du Suc, Saint-Martin-en-Haut, France", destination: "Grenoble, France", vehicleCategory: "2" }
|
|
||||||
};
|
|
||||||
const res = {
|
|
||||||
status: function() { return this; },
|
|
||||||
json: function(data) { console.log(JSON.stringify(data, null, 2)); }
|
|
||||||
};
|
|
||||||
await travel.googleMapsComputeRoute(req, res);
|
|
||||||
}
|
|
||||||
test();
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
const axios = require('axios');
|
|
||||||
const polylineLib = require('@mapbox/polyline');
|
|
||||||
require('dotenv').config({ path: '.env' });
|
|
||||||
const { googleMapsComputeRoute } = require('./src/travel.js');
|
|
||||||
|
|
||||||
async function testGrenobleDetailed() {
|
|
||||||
const origin = "25 Impasse du Puits du Suc, Saint-Martin-en-Haut, France";
|
|
||||||
const destination = "Grenoble, France";
|
|
||||||
|
|
||||||
const req = {
|
|
||||||
headers: { authorization: 'Bearer MOCK' },
|
|
||||||
body: { origin, destination, vehicleTollCategory: 2 }
|
|
||||||
};
|
|
||||||
let resultBody = null;
|
|
||||||
const res = {
|
|
||||||
set: () => {}, status: () => res,
|
|
||||||
json: (data) => { resultBody = data; return res; },
|
|
||||||
send: (data) => { resultBody = data; return res; }
|
|
||||||
};
|
|
||||||
|
|
||||||
const auth = require('./utils/auth');
|
|
||||||
auth.authenticateUser = async () => {};
|
|
||||||
|
|
||||||
await googleMapsComputeRoute(req, res);
|
|
||||||
|
|
||||||
if (resultBody.error) {
|
|
||||||
console.error(`Error: ${resultBody.error}`);
|
|
||||||
} else {
|
|
||||||
console.log(JSON.stringify(resultBody.routes[0], null, 2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testGrenobleDetailed();
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
const axios = require('axios');
|
|
||||||
async function getUlysRate(vehicleCategory, passages) {
|
|
||||||
const payload = {
|
|
||||||
vehicleCategory: String(vehicleCategory),
|
|
||||||
paymentOption: 2,
|
|
||||||
tollPassages: passages.map((p) => ({
|
|
||||||
toll: { operatorId: p.operatorId, tollId: p.tollId },
|
|
||||||
passageDate: new Date().toISOString(),
|
|
||||||
})),
|
|
||||||
};
|
|
||||||
const res = await axios.post('https://api-ulys.azure-api.net/tollstation/v1/rate', payload);
|
|
||||||
console.log(JSON.stringify(res.data, null, 2));
|
|
||||||
}
|
|
||||||
getUlysRate(2, [{operatorId: '03', tollId: '001'}, {operatorId: '03', tollId: '003'}]);
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
const axios = require('axios');
|
|
||||||
const polylineLib = require('@mapbox/polyline');
|
|
||||||
require('dotenv').config({ path: '.env' });
|
|
||||||
|
|
||||||
async function testHalfPolyline() {
|
|
||||||
const apiKey = process.env.API_MAPS;
|
|
||||||
const resToll = await axios.post('https://routes.googleapis.com/directions/v2:computeRoutes', {
|
|
||||||
travelMode: 'DRIVE', routingPreference: 'TRAFFIC_UNAWARE',
|
|
||||||
origin: { address: "25 Impasse du Puits du Suc, Saint-Martin-en-Haut, France" },
|
|
||||||
destination: { address: "Toulouse, France" },
|
|
||||||
}, { headers: { 'Content-Type': 'application/json', 'X-Goog-Api-Key': apiKey, 'X-Goog-FieldMask': 'routes.polyline.encodedPolyline' } });
|
|
||||||
|
|
||||||
const mainPoly = resToll.data.routes[0].polyline.encodedPolyline;
|
|
||||||
const mainCoords = polylineLib.decode(mainPoly, 5);
|
|
||||||
|
|
||||||
const halfCoords = mainCoords.slice(0, Math.floor(mainCoords.length / 2));
|
|
||||||
const halfPoly = polylineLib.encode(halfCoords, 5);
|
|
||||||
|
|
||||||
console.log(`Sending first half (${halfCoords.length} points)`);
|
|
||||||
|
|
||||||
const ulysUrl = `https://api-ulys.azure-api.net/placemark/v2/legs?precision=5&includeLayersIds=GaresPeage`;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const res = await axios.post(ulysUrl, JSON.stringify(halfPoly), {
|
|
||||||
headers: { 'Content-Type': 'application/json' }
|
|
||||||
});
|
|
||||||
const feats = res.data.features || res.data;
|
|
||||||
console.log(`Found ${feats.length} gates.`);
|
|
||||||
feats.forEach(f => {
|
|
||||||
const pm = f.Placemark || f.placemark || {};
|
|
||||||
console.log(pm.Preview || pm.preview || "Gate");
|
|
||||||
});
|
|
||||||
} catch(e) {
|
|
||||||
console.log("Error:", e.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testHalfPolyline();
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
const axios = require('axios');
|
|
||||||
const polylineLib = require('@mapbox/polyline');
|
|
||||||
require('dotenv').config({ path: '.env' });
|
|
||||||
|
|
||||||
function distKm(lat1, lng1, lat2, lng2) {
|
|
||||||
const dLat = (lat2 - lat1) * Math.PI / 180;
|
|
||||||
const dLng = (lng2 - lng1) * Math.PI / 180;
|
|
||||||
const a = Math.sin(dLat/2)**2 + Math.cos(lat1*Math.PI/180) * Math.cos(lat2*Math.PI/180) * Math.sin(dLng/2)**2;
|
|
||||||
return 6371 * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
|
|
||||||
}
|
|
||||||
|
|
||||||
function interpolatePolyline(coords, maxDistKm = 0.05) {
|
|
||||||
const newCoords = [];
|
|
||||||
if(coords.length === 0) return newCoords;
|
|
||||||
newCoords.push(coords[0]);
|
|
||||||
for(let i=1; i<coords.length; i++) {
|
|
||||||
const p1 = coords[i-1];
|
|
||||||
const p2 = coords[i];
|
|
||||||
const d = distKm(p1[0], p1[1], p2[0], p2[1]);
|
|
||||||
if(d > maxDistKm) {
|
|
||||||
const steps = Math.ceil(d / maxDistKm);
|
|
||||||
for(let step=1; step<steps; step++) {
|
|
||||||
const fraction = step / steps;
|
|
||||||
const lat = p1[0] + (p2[0] - p1[0]) * fraction;
|
|
||||||
const lng = p1[1] + (p2[1] - p1[1]) * fraction;
|
|
||||||
newCoords.push([lat, lng]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
newCoords.push(p2);
|
|
||||||
}
|
|
||||||
return newCoords;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function testInterpolatedToulouse() {
|
|
||||||
const apiKey = process.env.API_MAPS;
|
|
||||||
const resToll = await axios.post('https://routes.googleapis.com/directions/v2:computeRoutes', {
|
|
||||||
travelMode: 'DRIVE', routingPreference: 'TRAFFIC_UNAWARE',
|
|
||||||
origin: { address: "25 Impasse du Puits du Suc, Saint-Martin-en-Haut, France" },
|
|
||||||
destination: { address: "Toulouse, France" },
|
|
||||||
}, { headers: { 'Content-Type': 'application/json', 'X-Goog-Api-Key': apiKey, 'X-Goog-FieldMask': 'routes.polyline.encodedPolyline' } });
|
|
||||||
|
|
||||||
const poly = resToll.data.routes[0].polyline.encodedPolyline;
|
|
||||||
const coords = polylineLib.decode(poly, 5);
|
|
||||||
|
|
||||||
const interpolated = interpolatePolyline(coords, 0.05); // 50 meters
|
|
||||||
console.log(`Original points: ${coords.length}, Interpolated: ${interpolated.length}`);
|
|
||||||
|
|
||||||
const polyInt = polylineLib.encode(interpolated, 5);
|
|
||||||
|
|
||||||
const ulysUrl = `https://api-ulys.azure-api.net/placemark/v2/legs?precision=5&includeLayersIds=GaresPeage`;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const res = await axios.post(ulysUrl, JSON.stringify(polyInt), {
|
|
||||||
headers: { 'Content-Type': 'application/json' }
|
|
||||||
});
|
|
||||||
const feats = res.data.features || res.data;
|
|
||||||
console.log(`Found ${feats.length} gates.`);
|
|
||||||
feats.forEach(f => {
|
|
||||||
const pm = f.Placemark || f.placemark || {};
|
|
||||||
console.log(pm.Preview || pm.preview || "Gate");
|
|
||||||
});
|
|
||||||
} catch(e) {
|
|
||||||
console.log("Error:", e.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testInterpolatedToulouse();
|
|
||||||
@@ -1,147 +0,0 @@
|
|||||||
const axios = require('axios');
|
|
||||||
const fs = require('fs');
|
|
||||||
const csv = require('csv-parser');
|
|
||||||
const polylineLib = require('@mapbox/polyline');
|
|
||||||
require('dotenv').config({ path: '.env' });
|
|
||||||
|
|
||||||
function loadTollStations() {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
const csvPath = './travel/gares_peage_export.csv';
|
|
||||||
const results = [];
|
|
||||||
fs.createReadStream(csvPath)
|
|
||||||
.pipe(csv())
|
|
||||||
.on('data', (row) => {
|
|
||||||
if (row.id_gare && row.lat && row.lon) {
|
|
||||||
results.push({
|
|
||||||
id: row.id_gare,
|
|
||||||
operatorId: row.id_gare.substring(0, 2),
|
|
||||||
tollId: row.id_gare.substring(2, 5),
|
|
||||||
name: row.nom || '',
|
|
||||||
lat: parseFloat(row.lat),
|
|
||||||
lon: parseFloat(row.lon),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.on('end', () => resolve(results));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function _distKm(lat1, lng1, lat2, lng2) {
|
|
||||||
const dLat = (lat2 - lat1) * Math.PI / 180;
|
|
||||||
const dLng = (lng2 - lng1) * Math.PI / 180;
|
|
||||||
const a = Math.sin(dLat/2)**2 + Math.cos(lat1*Math.PI/180) * Math.cos(lat2*Math.PI/180) * Math.sin(dLng/2)**2;
|
|
||||||
return 6371 * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getUlysRate(vehicleCategory, passages) {
|
|
||||||
try {
|
|
||||||
const payload = {
|
|
||||||
vehicleCategory: String(vehicleCategory),
|
|
||||||
paymentOption: 2,
|
|
||||||
tollPassages: passages.map((p) => ({
|
|
||||||
toll: { operatorId: p.operatorId, tollId: p.tollId },
|
|
||||||
passageDate: new Date().toISOString(),
|
|
||||||
})),
|
|
||||||
};
|
|
||||||
const res = await axios.post('https://api-ulys.azure-api.net/tollstation/v1/rate', payload);
|
|
||||||
const data = res.data;
|
|
||||||
if (Array.isArray(data) && data.length > 0) {
|
|
||||||
if (passages.length === 2) {
|
|
||||||
if (data.length !== 1 || !data[0].exitToll) return null;
|
|
||||||
return data[0].price > 0 ? data[0].price : null;
|
|
||||||
} else {
|
|
||||||
if (data.length === 1 && data[0].price > 0) return data[0].price;
|
|
||||||
const total = data.reduce((sum, d) => sum + (d.price || 0), 0);
|
|
||||||
return total > 0 ? total : null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
} catch (e) { return null; }
|
|
||||||
}
|
|
||||||
|
|
||||||
async function test() {
|
|
||||||
const origin = "25 Impasse du Puits du Suc, Saint-Martin-en-Haut, France";
|
|
||||||
const destination = "Nice, France";
|
|
||||||
const apiKey = process.env.API_MAPS;
|
|
||||||
|
|
||||||
const routesUrl = 'https://routes.googleapis.com/directions/v2:computeRoutes';
|
|
||||||
const res = await axios.post(routesUrl, {
|
|
||||||
travelMode: 'DRIVE', routingPreference: 'TRAFFIC_UNAWARE', origin: { address: origin }, destination: { address: destination },
|
|
||||||
}, { headers: { 'Content-Type': 'application/json', 'X-Goog-Api-Key': apiKey, 'X-Goog-FieldMask': 'routes.polyline.encodedPolyline' }});
|
|
||||||
|
|
||||||
const poly = res.data.routes[0].polyline.encodedPolyline;
|
|
||||||
const coords = polylineLib.decode(poly, 5);
|
|
||||||
|
|
||||||
const safePolyline = poly;
|
|
||||||
const url = 'https://api-ulys.azure-api.net/placemark/v2/legs?precision=5&includeLayersIds=GaresPeage';
|
|
||||||
const ulysRes = await axios.post(url, JSON.stringify(safePolyline), { headers: { 'Content-Type': 'application/json' } });
|
|
||||||
const items = Array.isArray(ulysRes.data) ? ulysRes.data : (ulysRes.data.features || []);
|
|
||||||
|
|
||||||
const stations = await loadTollStations();
|
|
||||||
const gates = [];
|
|
||||||
|
|
||||||
for (const item of items) {
|
|
||||||
const pm = item.Placemark || item.placemark || {};
|
|
||||||
const tags = pm.Tags || pm.tags || {};
|
|
||||||
let idStr = tags.ID_PEAGE;
|
|
||||||
if (!idStr && pm.Code) idStr = pm.Code.split('_')[0];
|
|
||||||
const s = stations.find(s => s.id === idStr);
|
|
||||||
if (s && !gates.find(g => g.id === idStr)) gates.push(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback for missing first system
|
|
||||||
let missingSystemPrice = 0;
|
|
||||||
if (gates.length > 0) {
|
|
||||||
const originLat = coords[0][0];
|
|
||||||
const originLng = coords[0][1];
|
|
||||||
const firstGate = gates[0];
|
|
||||||
const distToFirstGate = _distKm(originLat, originLng, firstGate.lat, firstGate.lon);
|
|
||||||
|
|
||||||
if (distToFirstGate > 50) {
|
|
||||||
console.log(`First gate ${firstGate.name} is ${Math.round(distToFirstGate)}km from origin. Checking for missing system...`);
|
|
||||||
// Find all geometric gates within 2km of the route, UP TO the firstGate
|
|
||||||
let firstGateIndex = 0;
|
|
||||||
for (let i = 0; i < coords.length; i++) {
|
|
||||||
if (_distKm(coords[i][0], coords[i][1], firstGate.lat, firstGate.lon) < 1) {
|
|
||||||
firstGateIndex = i; break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const candidates = [];
|
|
||||||
stations.forEach(s => {
|
|
||||||
let minDist = Infinity;
|
|
||||||
let minIndex = -1;
|
|
||||||
for (let i = 0; i < firstGateIndex; i++) {
|
|
||||||
const d = _distKm(s.lat, s.lon, coords[i][0], coords[i][1]);
|
|
||||||
if (d < minDist) { minDist = d; minIndex = i; }
|
|
||||||
}
|
|
||||||
if (minDist < 2) {
|
|
||||||
candidates.push({ ...s, polyIndex: minIndex });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
candidates.sort((a, b) => a.polyIndex - b.polyIndex);
|
|
||||||
|
|
||||||
if (candidates.length >= 2) {
|
|
||||||
// Try combinations from furthest to closest to find the longest closed system
|
|
||||||
let found = false;
|
|
||||||
for (let i = 0; i < Math.min(10, candidates.length); i++) {
|
|
||||||
for (let j = candidates.length - 1; j > i && j > candidates.length - 10; j--) {
|
|
||||||
if (candidates[i].operatorId !== candidates[j].operatorId) continue;
|
|
||||||
const price = await getUlysRate(2, [candidates[i], candidates[j]]);
|
|
||||||
if (price) {
|
|
||||||
console.log(`Found missing system: ${candidates[i].name} -> ${candidates[j].name} = ${price}€`);
|
|
||||||
missingSystemPrice += price;
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (found) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`Missing system price: ${missingSystemPrice}€`);
|
|
||||||
}
|
|
||||||
test();
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
const axios = require('axios');
|
|
||||||
const polylineLib = require('@mapbox/polyline');
|
|
||||||
require('dotenv').config({ path: '.env' });
|
|
||||||
|
|
||||||
async function directTestToulouse() {
|
|
||||||
const origin = "25 Impasse du Puits du Suc, Saint-Martin-en-Haut, France";
|
|
||||||
const destination = "Toulouse, France";
|
|
||||||
const apiKey = process.env.API_MAPS;
|
|
||||||
|
|
||||||
const routesUrl = 'https://routes.googleapis.com/directions/v2:computeRoutes';
|
|
||||||
const fieldMask = 'routes.distanceMeters,routes.duration,routes.polyline.encodedPolyline,routes.travelAdvisory.tollInfo';
|
|
||||||
|
|
||||||
const resToll = await axios.post(routesUrl, {
|
|
||||||
travelMode: 'DRIVE',
|
|
||||||
routingPreference: 'TRAFFIC_UNAWARE',
|
|
||||||
origin: { address: origin },
|
|
||||||
destination: { address: destination },
|
|
||||||
routeModifiers: { avoidTolls: false }
|
|
||||||
}, {
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'X-Goog-Api-Key': apiKey,
|
|
||||||
'X-Goog-FieldMask': fieldMask,
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const poly = resToll.data.routes[0].polyline.encodedPolyline;
|
|
||||||
const decoded = polylineLib.decode(poly, 5);
|
|
||||||
const poly6 = polylineLib.encode(decoded, 6);
|
|
||||||
|
|
||||||
const ulysUrl = `https://api-ulys.azure-api.net/placemark/v2/legs?precision=6&includeLayersIds=GaresPeage`;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const res = await axios.post(ulysUrl, JSON.stringify(poly6), {
|
|
||||||
headers: { 'Content-Type': 'application/json' }
|
|
||||||
});
|
|
||||||
console.log("Ulys Response (precision=6):");
|
|
||||||
console.log(res.data);
|
|
||||||
} catch(e) {
|
|
||||||
console.log("Ulys Error:", e.message);
|
|
||||||
if(e.response && e.response.data) console.log(e.response.data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
directTestToulouse();
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
const axios = require('axios');
|
|
||||||
async function testRate() {
|
|
||||||
const passages = [
|
|
||||||
{ operatorId: '04', tollId: '201' }, // VIENNE
|
|
||||||
{ operatorId: '04', tollId: '457' } // TOULOUSE-NORD/OUEST
|
|
||||||
];
|
|
||||||
const payload = {
|
|
||||||
vehicleCategory: "2",
|
|
||||||
paymentOption: 2,
|
|
||||||
tollPassages: passages.map((p) => ({
|
|
||||||
toll: { operatorId: p.operatorId, tollId: p.tollId },
|
|
||||||
passageDate: new Date().toISOString(),
|
|
||||||
})),
|
|
||||||
};
|
|
||||||
try {
|
|
||||||
const res = await axios.post('https://api-ulys.azure-api.net/tollstation/v1/rate', payload);
|
|
||||||
console.log("Rate:");
|
|
||||||
console.log(JSON.stringify(res.data, null, 2));
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e.response ? e.response.data : e.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testRate();
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
const axios = require('axios');
|
|
||||||
async function testRate() {
|
|
||||||
const passages = [
|
|
||||||
{ operatorId: '04', tollId: '178' },
|
|
||||||
{ operatorId: '09', tollId: '079' }
|
|
||||||
];
|
|
||||||
const payload = {
|
|
||||||
vehicleCategory: "2", paymentOption: 2,
|
|
||||||
tollPassages: passages.map((p) => ({
|
|
||||||
toll: { operatorId: p.operatorId, tollId: p.tollId }, passageDate: new Date().toISOString(),
|
|
||||||
})),
|
|
||||||
};
|
|
||||||
try {
|
|
||||||
const res = await axios.post('https://api-ulys.azure-api.net/tollstation/v1/rate', payload);
|
|
||||||
console.log("Rate:");
|
|
||||||
console.log(JSON.stringify(res.data, null, 2));
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e.response ? e.response.data : e.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testRate();
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
const axios = require('axios');
|
|
||||||
async function testRateVienneToulouseEst() {
|
|
||||||
const passages = [
|
|
||||||
{ operatorId: '04', tollId: '178' }, // MONTBRISON (04178)
|
|
||||||
{ operatorId: '04', tollId: '456' } // TOULOUSE-EST (04456)
|
|
||||||
];
|
|
||||||
const payload = {
|
|
||||||
vehicleCategory: "2",
|
|
||||||
paymentOption: 2,
|
|
||||||
tollPassages: passages.map((p) => ({
|
|
||||||
toll: { operatorId: p.operatorId, tollId: p.tollId },
|
|
||||||
passageDate: new Date().toISOString(),
|
|
||||||
})),
|
|
||||||
};
|
|
||||||
try {
|
|
||||||
const res = await axios.post('https://api-ulys.azure-api.net/tollstation/v1/rate', payload);
|
|
||||||
console.log("Rate MONTBRISON -> TOULOUSE-EST:");
|
|
||||||
console.log(JSON.stringify(res.data, null, 2));
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e.response ? e.response.data : e.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testRateVienneToulouseEst();
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
const axios = require('axios');
|
|
||||||
async function testRateVienneToulouseEst() {
|
|
||||||
const passages = [
|
|
||||||
{ operatorId: '04', tollId: '201' }, // VIENNE (04201)
|
|
||||||
{ operatorId: '04', tollId: '456' } // TOULOUSE-EST (04456)
|
|
||||||
];
|
|
||||||
const payload = {
|
|
||||||
vehicleCategory: "2",
|
|
||||||
paymentOption: 2,
|
|
||||||
tollPassages: passages.map((p) => ({
|
|
||||||
toll: { operatorId: p.operatorId, tollId: p.tollId },
|
|
||||||
passageDate: new Date().toISOString(),
|
|
||||||
})),
|
|
||||||
};
|
|
||||||
try {
|
|
||||||
const res = await axios.post('https://api-ulys.azure-api.net/tollstation/v1/rate', payload);
|
|
||||||
console.log("Rate VIENNE -> TOULOUSE-EST:");
|
|
||||||
console.log(JSON.stringify(res.data, null, 2));
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e.response ? e.response.data : e.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testRateVienneToulouseEst();
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
const axios = require('axios');
|
|
||||||
const polylineLib = require('@mapbox/polyline');
|
|
||||||
require('dotenv').config({ path: '.env' });
|
|
||||||
const { googleMapsComputeRoute } = require('./src/travel.js');
|
|
||||||
|
|
||||||
async function testRoute(destination, expectedPrice) {
|
|
||||||
const origin = "25 Impasse du Puits du Suc, Saint-Martin-en-Haut, France";
|
|
||||||
console.log(`\nTesting ${destination}...`);
|
|
||||||
|
|
||||||
const req = {
|
|
||||||
headers: { authorization: 'Bearer MOCK' },
|
|
||||||
body: { origin, destination, vehicleTollCategory: 2 }
|
|
||||||
};
|
|
||||||
let resultBody = null;
|
|
||||||
const res = {
|
|
||||||
set: () => {}, status: () => res,
|
|
||||||
json: (data) => { resultBody = data; return res; },
|
|
||||||
send: (data) => { resultBody = data; return res; }
|
|
||||||
};
|
|
||||||
|
|
||||||
await googleMapsComputeRoute(req, res);
|
|
||||||
|
|
||||||
if (resultBody.error) {
|
|
||||||
console.error(`Error: ${resultBody.error}`);
|
|
||||||
} else {
|
|
||||||
const toll = resultBody.routes && resultBody.routes.length > 0 ? resultBody.routes[0].tollCost : 0;
|
|
||||||
console.log(`Toll: ${toll}€ (Expected: ${expectedPrice}€)`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function run() {
|
|
||||||
// Mock Firebase auth specifically for this test
|
|
||||||
const auth = require('./utils/auth');
|
|
||||||
auth.authenticateUser = async () => {};
|
|
||||||
|
|
||||||
await testRoute("Saint-Denis, France", 64.3);
|
|
||||||
await testRoute("Grenoble, France", 21.7);
|
|
||||||
await testRoute("Nice, France", 77.2);
|
|
||||||
}
|
|
||||||
run();
|
|
||||||
@@ -1,130 +0,0 @@
|
|||||||
const axios = require('axios');
|
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
require('dotenv').config({ path: '.env' });
|
|
||||||
const { _distKm } = require('./src/travel.js');
|
|
||||||
|
|
||||||
function distKm(lat1, lng1, lat2, lng2) {
|
|
||||||
const dLat = (lat2 - lat1) * Math.PI / 180;
|
|
||||||
const dLng = (lng2 - lng1) * Math.PI / 180;
|
|
||||||
const a = Math.sin(dLat/2)**2 + Math.cos(lat1*Math.PI/180) * Math.cos(lat2*Math.PI/180) * Math.sin(dLng/2)**2;
|
|
||||||
return 6371 * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
|
|
||||||
}
|
|
||||||
|
|
||||||
async function testTollSegments() {
|
|
||||||
const apiKey = process.env.API_MAPS;
|
|
||||||
const resToll = await axios.post('https://routes.googleapis.com/directions/v2:computeRoutes', {
|
|
||||||
travelMode: 'DRIVE', routingPreference: 'TRAFFIC_UNAWARE',
|
|
||||||
origin: { address: "25 Impasse du Puits du Suc, Saint-Martin-en-Haut, France" },
|
|
||||||
destination: { address: "Nice, France" },
|
|
||||||
}, { headers: { 'Content-Type': 'application/json', 'X-Goog-Api-Key': apiKey, 'X-Goog-FieldMask': 'routes.legs.steps.navigationInstruction,routes.legs.steps.distanceMeters,routes.legs.steps.startLocation,routes.legs.steps.endLocation,routes.legs.steps.polyline.encodedPolyline' } });
|
|
||||||
|
|
||||||
const steps = resToll.data.routes[0].legs[0].steps;
|
|
||||||
|
|
||||||
const rawCsv = fs.readFileSync(path.join(__dirname, 'travel', 'gares_peage_export.csv'), 'utf8');
|
|
||||||
const stations = [];
|
|
||||||
const lines = rawCsv.split('\n');
|
|
||||||
for (let i = 1; i < lines.length; i++) {
|
|
||||||
const l = lines[i].trim();
|
|
||||||
if (!l) continue;
|
|
||||||
const parts = l.split(',');
|
|
||||||
if (parts.length >= 4) {
|
|
||||||
const idStr = String(parts[0]).padStart(5, '0');
|
|
||||||
stations.push({
|
|
||||||
id: idStr, operatorId: idStr.substring(0, 2), tollId: idStr.substring(2, 5),
|
|
||||||
name: parts[1], lat: parseFloat(parts[2]), lon: parseFloat(parts[3]),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getClosestGate(lat, lng) {
|
|
||||||
let minDist = Infinity;
|
|
||||||
let closest = null;
|
|
||||||
for(let s of stations) {
|
|
||||||
const d = distKm(lat, lng, s.lat, s.lon);
|
|
||||||
if(d < minDist) { minDist = d; closest = s; }
|
|
||||||
}
|
|
||||||
return minDist < 5 ? closest : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const segments = [];
|
|
||||||
let currentSegment = null;
|
|
||||||
for(let i=0; i<steps.length; i++) {
|
|
||||||
const step = steps[i];
|
|
||||||
const inst = step.navigationInstruction ? step.navigationInstruction.instructions : '';
|
|
||||||
const isToll = inst.toLowerCase().includes('péage') || inst.toLowerCase().includes('toll');
|
|
||||||
|
|
||||||
if (isToll) {
|
|
||||||
if (!currentSegment) {
|
|
||||||
currentSegment = { steps: [] };
|
|
||||||
}
|
|
||||||
currentSegment.steps.push(step);
|
|
||||||
} else {
|
|
||||||
if (currentSegment) {
|
|
||||||
segments.push(currentSegment);
|
|
||||||
currentSegment = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (currentSegment) segments.push(currentSegment);
|
|
||||||
|
|
||||||
const polylineLib = require('@mapbox/polyline');
|
|
||||||
let totalToll = 0;
|
|
||||||
for (let i=0; i<segments.length; i++) {
|
|
||||||
const seg = segments[i];
|
|
||||||
let segCoords = [];
|
|
||||||
for(let step of seg.steps) {
|
|
||||||
if(step.polyline && step.polyline.encodedPolyline) {
|
|
||||||
segCoords = segCoords.concat(polylineLib.decode(step.polyline.encodedPolyline, 5));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const candidates = [];
|
|
||||||
stations.forEach(s => {
|
|
||||||
let minDist = Infinity;
|
|
||||||
let minIndex = -1;
|
|
||||||
for (let j = 0; j < segCoords.length; j++) {
|
|
||||||
const d = distKm(s.lat, s.lon, segCoords[j][0], segCoords[j][1]);
|
|
||||||
if (d < minDist) { minDist = d; minIndex = j; }
|
|
||||||
}
|
|
||||||
if (minDist < 2) { // must be within 2km of the segment
|
|
||||||
candidates.push({ ...s, polyIndex: minIndex });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
candidates.sort((a, b) => a.polyIndex - b.polyIndex);
|
|
||||||
|
|
||||||
let entry = null, exit = null;
|
|
||||||
if (candidates.length > 0) {
|
|
||||||
entry = candidates[0];
|
|
||||||
exit = candidates[candidates.length - 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`Segment ${i+1}: points=${segCoords.length}, candidates=${candidates.length}, Entry=${entry?entry.name:'none'}, Exit=${exit?exit.name:'none'}`);
|
|
||||||
|
|
||||||
|
|
||||||
if (entry && exit) {
|
|
||||||
try {
|
|
||||||
const passages = [
|
|
||||||
{ operatorId: entry.operatorId, tollId: entry.tollId },
|
|
||||||
{ operatorId: exit.operatorId, tollId: exit.tollId }
|
|
||||||
];
|
|
||||||
const payload = {
|
|
||||||
vehicleCategory: "2", paymentOption: 2,
|
|
||||||
tollPassages: passages.map((p) => ({ toll: { operatorId: p.operatorId, tollId: p.tollId }, passageDate: new Date().toISOString() })),
|
|
||||||
};
|
|
||||||
const res = await axios.post('https://api-ulys.azure-api.net/tollstation/v1/rate', payload);
|
|
||||||
const data = res.data;
|
|
||||||
let price = 0;
|
|
||||||
if (data.length === 1 && data[0].price > 0) price = data[0].price;
|
|
||||||
if (data.length > 1) {
|
|
||||||
const pItem = data.find(d => d.price > 0);
|
|
||||||
if (pItem) price = pItem.price;
|
|
||||||
}
|
|
||||||
console.log(` -> Price: ${price}€`);
|
|
||||||
totalToll += price;
|
|
||||||
} catch(e) { console.log(` -> Ulys Error`); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
console.log(`Total Toll: ${totalToll}€`);
|
|
||||||
}
|
|
||||||
testTollSegments();
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
const axios = require('axios');
|
|
||||||
require('dotenv').config({ path: '.env' });
|
|
||||||
|
|
||||||
async function testSteps() {
|
|
||||||
const apiKey = process.env.API_MAPS;
|
|
||||||
const resToll = await axios.post('https://routes.googleapis.com/directions/v2:computeRoutes', {
|
|
||||||
travelMode: 'DRIVE', routingPreference: 'TRAFFIC_UNAWARE',
|
|
||||||
origin: { address: "25 Impasse du Puits du Suc, Saint-Martin-en-Haut, France" },
|
|
||||||
destination: { address: "Toulouse, France" },
|
|
||||||
}, { headers: { 'Content-Type': 'application/json', 'X-Goog-Api-Key': apiKey, 'X-Goog-FieldMask': 'routes.legs.steps.navigationInstruction,routes.legs.steps.distanceMeters,routes.legs.steps.startLocation,routes.legs.steps.endLocation' } });
|
|
||||||
|
|
||||||
const steps = resToll.data.routes[0].legs[0].steps;
|
|
||||||
for(let i=0; i<steps.length; i++) {
|
|
||||||
const step = steps[i];
|
|
||||||
const inst = step.navigationInstruction ? step.navigationInstruction.instructions : '';
|
|
||||||
if(inst.toLowerCase().includes('péage') || inst.toLowerCase().includes('toll')) {
|
|
||||||
console.log(`Step ${i}: ${inst} (Dist: ${step.distanceMeters}m)`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testSteps();
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
const axios = require('axios');
|
|
||||||
const polylineLib = require('@mapbox/polyline');
|
|
||||||
require('dotenv').config({ path: '.env' });
|
|
||||||
|
|
||||||
async function testStepsPolyline() {
|
|
||||||
const apiKey = process.env.API_MAPS;
|
|
||||||
const resToll = await axios.post('https://routes.googleapis.com/directions/v2:computeRoutes', {
|
|
||||||
travelMode: 'DRIVE', routingPreference: 'TRAFFIC_UNAWARE',
|
|
||||||
origin: { address: "25 Impasse du Puits du Suc, Saint-Martin-en-Haut, France" },
|
|
||||||
destination: { address: "Toulouse, France" },
|
|
||||||
}, { headers: { 'Content-Type': 'application/json', 'X-Goog-Api-Key': apiKey, 'X-Goog-FieldMask': 'routes.polyline.encodedPolyline,routes.legs.steps.polyline.encodedPolyline' } });
|
|
||||||
|
|
||||||
const mainPoly = resToll.data.routes[0].polyline.encodedPolyline;
|
|
||||||
const mainCoords = polylineLib.decode(mainPoly, 5);
|
|
||||||
|
|
||||||
const steps = resToll.data.routes[0].legs[0].steps;
|
|
||||||
let stepCoords = [];
|
|
||||||
for(let step of steps) {
|
|
||||||
if(step.polyline && step.polyline.encodedPolyline) {
|
|
||||||
stepCoords = stepCoords.concat(polylineLib.decode(step.polyline.encodedPolyline, 5));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`Main polyline points: ${mainCoords.length}`);
|
|
||||||
console.log(`Steps combined points: ${stepCoords.length}`);
|
|
||||||
|
|
||||||
const combinedPoly = polylineLib.encode(stepCoords, 5);
|
|
||||||
|
|
||||||
const ulysUrl = `https://api-ulys.azure-api.net/placemark/v2/legs?precision=5&includeLayersIds=GaresPeage`;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const res = await axios.post(ulysUrl, JSON.stringify(combinedPoly), {
|
|
||||||
headers: { 'Content-Type': 'application/json' }
|
|
||||||
});
|
|
||||||
const feats = res.data.features || res.data;
|
|
||||||
console.log(`Found ${feats.length} gates.`);
|
|
||||||
feats.forEach(f => {
|
|
||||||
const pm = f.Placemark || f.placemark || {};
|
|
||||||
console.log(pm.Preview || pm.preview || "Gate");
|
|
||||||
});
|
|
||||||
} catch(e) {
|
|
||||||
console.log("Error:", e.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testStepsPolyline();
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
const axios = require('axios');
|
|
||||||
require('dotenv').config({ path: '.env' });
|
|
||||||
const { googleMapsComputeRoute } = require('./src/travel.js');
|
|
||||||
|
|
||||||
async function testToulouse() {
|
|
||||||
const origin = "25 Impasse du Puits du Suc, Saint-Martin-en-Haut, France";
|
|
||||||
const destination = "Toulouse, France";
|
|
||||||
|
|
||||||
const req = {
|
|
||||||
headers: { authorization: 'Bearer MOCK' },
|
|
||||||
body: { origin, destination, vehicleTollCategory: 2 }
|
|
||||||
};
|
|
||||||
let resultBody = null;
|
|
||||||
const res = {
|
|
||||||
set: () => {}, status: () => res,
|
|
||||||
json: (data) => { resultBody = data; return res; },
|
|
||||||
send: (data) => { resultBody = data; return res; }
|
|
||||||
};
|
|
||||||
|
|
||||||
const auth = require('./utils/auth');
|
|
||||||
auth.authenticateUser = async () => {};
|
|
||||||
|
|
||||||
await googleMapsComputeRoute(req, res);
|
|
||||||
|
|
||||||
if (resultBody.error) {
|
|
||||||
console.error(`Error: ${resultBody.error}`);
|
|
||||||
} else {
|
|
||||||
console.log(JSON.stringify(resultBody.routes[0], null, 2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testToulouse();
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
const axios = require('axios');
|
|
||||||
require('dotenv').config({ path: '.env' });
|
|
||||||
|
|
||||||
async function testUlysParams() {
|
|
||||||
const apiKey = process.env.API_MAPS;
|
|
||||||
const resToll = await axios.post('https://routes.googleapis.com/directions/v2:computeRoutes', {
|
|
||||||
travelMode: 'DRIVE', routingPreference: 'TRAFFIC_UNAWARE',
|
|
||||||
origin: { address: "25 Impasse du Puits du Suc, Saint-Martin-en-Haut, France" },
|
|
||||||
destination: { address: "Toulouse, France" },
|
|
||||||
}, { headers: { 'Content-Type': 'application/json', 'X-Goog-Api-Key': apiKey, 'X-Goog-FieldMask': 'routes.polyline.encodedPolyline' } });
|
|
||||||
|
|
||||||
const poly = resToll.data.routes[0].polyline.encodedPolyline;
|
|
||||||
|
|
||||||
const urls = [
|
|
||||||
`https://api-ulys.azure-api.net/placemark/v2/legs?precision=5&includeLayersIds=GaresPeage&radius=100`,
|
|
||||||
`https://api-ulys.azure-api.net/placemark/v2/legs?precision=5&includeLayersIds=GaresPeage&tolerance=100`,
|
|
||||||
`https://api-ulys.azure-api.net/placemark/v2/legs?precision=5&includeLayersIds=GaresPeage&distance=100`
|
|
||||||
];
|
|
||||||
|
|
||||||
for(let url of urls) {
|
|
||||||
try {
|
|
||||||
const res = await axios.post(url, JSON.stringify(poly), { headers: { 'Content-Type': 'application/json' } });
|
|
||||||
console.log(`URL: ${url}`);
|
|
||||||
console.log(`Found ${res.data.length || (res.data.features && res.data.features.length) || 0} gates`);
|
|
||||||
} catch(e) {
|
|
||||||
console.log(`Error on ${url}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testUlysParams();
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
const axios = require('axios');
|
|
||||||
const polylineLib = require('@mapbox/polyline');
|
|
||||||
require('dotenv').config({ path: '.env' });
|
|
||||||
|
|
||||||
async function directTestToulouse() {
|
|
||||||
const origin = "25 Impasse du Puits du Suc, Saint-Martin-en-Haut, France";
|
|
||||||
const destination = "Toulouse, France";
|
|
||||||
const apiKey = process.env.API_MAPS;
|
|
||||||
|
|
||||||
const routesUrl = 'https://routes.googleapis.com/directions/v2:computeRoutes';
|
|
||||||
const fieldMask = 'routes.distanceMeters,routes.duration,routes.polyline.encodedPolyline,routes.travelAdvisory.tollInfo';
|
|
||||||
|
|
||||||
const resToll = await axios.post(routesUrl, {
|
|
||||||
travelMode: 'DRIVE',
|
|
||||||
routingPreference: 'TRAFFIC_UNAWARE',
|
|
||||||
origin: { address: origin },
|
|
||||||
destination: { address: destination },
|
|
||||||
routeModifiers: { avoidTolls: false }
|
|
||||||
}, {
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'X-Goog-Api-Key': apiKey,
|
|
||||||
'X-Goog-FieldMask': fieldMask,
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const poly = resToll.data.routes[0].polyline.encodedPolyline;
|
|
||||||
const ulysUrl = `https://api-ulys.azure-api.net/placemark/v2/legs?precision=5&includeLayersIds=GaresPeage`;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const res = await axios.post(ulysUrl, JSON.stringify(poly), {
|
|
||||||
headers: { 'Content-Type': 'application/json' }
|
|
||||||
});
|
|
||||||
console.log("Ulys Response:");
|
|
||||||
console.log(res.data);
|
|
||||||
} catch(e) {
|
|
||||||
console.log("Ulys Error:", e.message);
|
|
||||||
if(e.response && e.response.data) console.log(e.response.data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
directTestToulouse();
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
import 'dart:convert';
|
|
||||||
import 'dart:io';
|
|
||||||
import 'package:latlong2/latlong.dart';
|
|
||||||
import '../lib/utils/polyline_utils.dart';
|
|
||||||
|
|
||||||
void main() async {
|
|
||||||
final origin = "401 route du camping, 69850 Saint Martin en haut";
|
|
||||||
final destination = "Salle des fêtes, Orliénas";
|
|
||||||
|
|
||||||
final requestBody = jsonEncode({
|
|
||||||
"data": {
|
|
||||||
"origin": origin,
|
|
||||||
"destination": destination,
|
|
||||||
"vehicleTollCategory": 2
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
print("Fetching route...");
|
|
||||||
final request = await HttpClient().postUrl(Uri.parse('https://googlemapscomputeroute-iarazmuuzq-od.a.run.app'));
|
|
||||||
request.headers.set('Content-Type', 'application/json');
|
|
||||||
request.write(requestBody);
|
|
||||||
|
|
||||||
final response = await request.close();
|
|
||||||
final responseBody = await response.transform(utf8.decoder).join();
|
|
||||||
|
|
||||||
print("Status: ${response.statusCode}");
|
|
||||||
|
|
||||||
try {
|
|
||||||
final json = jsonDecode(responseBody);
|
|
||||||
final routes = json['routes'] as List;
|
|
||||||
for (int i = 0; i < routes.length; i++) {
|
|
||||||
final polyStr = routes[i]['encodedPolyline'];
|
|
||||||
print("Route $i polyline length: ${polyStr.length}");
|
|
||||||
final pts = safeDecodePolyline(polyStr);
|
|
||||||
print("Route $i points decoded: ${pts.length}");
|
|
||||||
if (pts.isNotEmpty) {
|
|
||||||
print(" Start: ${pts.first.latitude}, ${pts.first.longitude}");
|
|
||||||
print(" End: ${pts.last.latitude}, ${pts.last.longitude}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
print("Error parsing: $e");
|
|
||||||
print(responseBody);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
import 'dart:convert';
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
void main() async {
|
|
||||||
final envFile = File('functions/.env');
|
|
||||||
final lines = await envFile.readAsLines();
|
|
||||||
String apiKey = '';
|
|
||||||
for (var line in lines) {
|
|
||||||
if (line.startsWith('API_MAPS=')) {
|
|
||||||
apiKey = line.split('=')[1].replaceAll('"', '');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final url = 'https://routes.googleapis.com/directions/v2:computeRoutes';
|
|
||||||
final client = HttpClient();
|
|
||||||
|
|
||||||
final request = await client.postUrl(Uri.parse(url));
|
|
||||||
request.headers.set('Content-Type', 'application/json');
|
|
||||||
request.headers.set('X-Goog-Api-Key', apiKey);
|
|
||||||
request.headers.set('X-Goog-FieldMask', 'routes.distanceMeters,routes.duration,routes.polyline.encodedPolyline');
|
|
||||||
|
|
||||||
final payload = jsonEncode({
|
|
||||||
"travelMode": "DRIVE",
|
|
||||||
"routingPreference": "TRAFFIC_AWARE",
|
|
||||||
"origin": { "address": "Mon depot" },
|
|
||||||
"destination": { "address": "25 Imp. du Puits du Suc, Saint-Martin-en-Haut, France" }
|
|
||||||
});
|
|
||||||
|
|
||||||
request.write(payload);
|
|
||||||
final response = await request.close();
|
|
||||||
final responseBody = await response.transform(utf8.decoder).join();
|
|
||||||
|
|
||||||
print(responseBody.length > 200 ? responseBody.substring(0, 200) : responseBody);
|
|
||||||
}
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
import 'dart:convert';
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
// Test la route Saint-Martin -> Paris (autoroute avec péage)
|
|
||||||
// Pour vérifier que la polyline longue se décode correctement en Dart
|
|
||||||
void main() async {
|
|
||||||
final envFile = File('functions/.env');
|
|
||||||
final lines = await envFile.readAsLines();
|
|
||||||
String apiKey = '';
|
|
||||||
for (var line in lines) {
|
|
||||||
if (line.startsWith('API_MAPS=')) {
|
|
||||||
apiKey = line.split('=')[1].replaceAll('"', '').trim();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final url = 'https://routes.googleapis.com/directions/v2:computeRoutes';
|
|
||||||
final client = HttpClient();
|
|
||||||
|
|
||||||
final request = await client.postUrl(Uri.parse(url));
|
|
||||||
request.headers.set('Content-Type', 'application/json');
|
|
||||||
request.headers.set('X-Goog-Api-Key', apiKey);
|
|
||||||
request.headers.set('X-Goog-FieldMask', 'routes.distanceMeters,routes.duration,routes.polyline.encodedPolyline');
|
|
||||||
|
|
||||||
final payload = jsonEncode({
|
|
||||||
"travelMode": "DRIVE",
|
|
||||||
"routingPreference": "TRAFFIC_AWARE",
|
|
||||||
"routeModifiers": { "avoidTolls": false },
|
|
||||||
"origin": { "address": "401 route du camping, 69850 Saint Martin en haut" },
|
|
||||||
"destination": { "address": "Paris, France" }
|
|
||||||
});
|
|
||||||
|
|
||||||
request.write(payload);
|
|
||||||
final response = await request.close();
|
|
||||||
final responseBody = await response.transform(utf8.decoder).join();
|
|
||||||
|
|
||||||
final json = jsonDecode(responseBody);
|
|
||||||
final routes = json['routes'] as List;
|
|
||||||
final polyStr = routes[0]['polyline']['encodedPolyline'] as String;
|
|
||||||
final dist = routes[0]['distanceMeters'];
|
|
||||||
|
|
||||||
print('Distance: ${(dist/1000).round()} km');
|
|
||||||
print('Polyline longueur: ${polyStr.length} chars');
|
|
||||||
print('Polyline (50 premiers): ${polyStr.substring(0, 50)}');
|
|
||||||
|
|
||||||
// Décoder
|
|
||||||
final pts = _decodePolyline(polyStr);
|
|
||||||
print('Points décodés: ${pts.length}');
|
|
||||||
|
|
||||||
// Chercher les points invalides
|
|
||||||
var invalides = 0;
|
|
||||||
for (final pt in pts) {
|
|
||||||
if (pt[0].abs() > 90 || pt[1].abs() > 180) {
|
|
||||||
invalides++;
|
|
||||||
if (invalides <= 3) print(' *** INVALIDE: ${pt[0]}, ${pt[1]}');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (invalides == 0) {
|
|
||||||
print('✅ Tous les ${pts.length} points sont valides WGS84');
|
|
||||||
print('Premier: ${pts[0][0].toStringAsFixed(5)}, ${pts[0][1].toStringAsFixed(5)}');
|
|
||||||
print('Dernier: ${pts.last[0].toStringAsFixed(5)}, ${pts.last[1].toStringAsFixed(5)}');
|
|
||||||
} else {
|
|
||||||
print('❌ $invalides points invalides détectés');
|
|
||||||
}
|
|
||||||
|
|
||||||
client.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
List<List<double>> _decodePolyline(String encoded) {
|
|
||||||
List<List<double>> poly = [];
|
|
||||||
int index = 0, len = encoded.length;
|
|
||||||
int lat = 0, lng = 0;
|
|
||||||
|
|
||||||
while (index < len) {
|
|
||||||
int b, shift = 0, result = 0;
|
|
||||||
do {
|
|
||||||
if (index >= len) break;
|
|
||||||
b = encoded.codeUnitAt(index++) - 63;
|
|
||||||
result |= (b & 0x1f) << shift;
|
|
||||||
shift += 5;
|
|
||||||
} while (b >= 0x20);
|
|
||||||
int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
|
|
||||||
lat += dlat;
|
|
||||||
|
|
||||||
shift = 0;
|
|
||||||
result = 0;
|
|
||||||
do {
|
|
||||||
if (index >= len) break;
|
|
||||||
b = encoded.codeUnitAt(index++) - 63;
|
|
||||||
result |= (b & 0x1f) << shift;
|
|
||||||
shift += 5;
|
|
||||||
} while (b >= 0x20);
|
|
||||||
int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
|
|
||||||
lng += dlng;
|
|
||||||
|
|
||||||
double finalLat = lat / 1e5;
|
|
||||||
double finalLng = lng / 1e5;
|
|
||||||
poly.add([finalLat, finalLng]);
|
|
||||||
}
|
|
||||||
return poly;
|
|
||||||
}
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
import 'dart:convert';
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
List<List<double>> decodePolyline(String encoded) {
|
|
||||||
List<List<double>> poly = [];
|
|
||||||
int index = 0, len = encoded.length;
|
|
||||||
int lat = 0, lng = 0;
|
|
||||||
|
|
||||||
while (index < len) {
|
|
||||||
int b, shift = 0, result = 0;
|
|
||||||
do {
|
|
||||||
if (index >= len) break;
|
|
||||||
b = encoded.codeUnitAt(index++) - 63;
|
|
||||||
result |= (b & 0x1f) << shift;
|
|
||||||
shift += 5;
|
|
||||||
} while (b >= 0x20);
|
|
||||||
int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
|
|
||||||
lat += dlat;
|
|
||||||
|
|
||||||
shift = 0;
|
|
||||||
result = 0;
|
|
||||||
do {
|
|
||||||
if (index >= len) break;
|
|
||||||
b = encoded.codeUnitAt(index++) - 63;
|
|
||||||
result |= (b & 0x1f) << shift;
|
|
||||||
shift += 5;
|
|
||||||
} while (b >= 0x20);
|
|
||||||
int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
|
|
||||||
lng += dlng;
|
|
||||||
|
|
||||||
poly.add([lat / 1e5, lng / 1e5]);
|
|
||||||
}
|
|
||||||
return poly;
|
|
||||||
}
|
|
||||||
|
|
||||||
void main() async {
|
|
||||||
final origin = "401 route du camping, 69850 Saint Martin en haut";
|
|
||||||
final destination = "Salle des fêtes, Orliénas";
|
|
||||||
|
|
||||||
final requestBody = jsonEncode({
|
|
||||||
"data": {
|
|
||||||
"origin": origin,
|
|
||||||
"destination": destination,
|
|
||||||
"vehicleTollCategory": 2
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Since we don't have the auth token, let's bypass auth if possible, or just call Google Maps directly!
|
|
||||||
// Wait, I can't call Google Maps directly without API_MAPS key.
|
|
||||||
// I will read .env file.
|
|
||||||
final envFile = File('functions/.env');
|
|
||||||
final lines = await envFile.readAsLines();
|
|
||||||
String apiKey = '';
|
|
||||||
for (var line in lines) {
|
|
||||||
if (line.startsWith('API_MAPS=')) {
|
|
||||||
apiKey = line.split('=')[1].replaceAll('"', '');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (apiKey.isEmpty) {
|
|
||||||
print("API_MAPS not found");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final url = 'https://routes.googleapis.com/directions/v2:computeRoutes';
|
|
||||||
final client = HttpClient();
|
|
||||||
final request = await client.postUrl(Uri.parse(url));
|
|
||||||
request.headers.set('Content-Type', 'application/json');
|
|
||||||
request.headers.set('X-Goog-Api-Key', apiKey);
|
|
||||||
request.headers.set('X-Goog-FieldMask', 'routes.distanceMeters,routes.duration,routes.polyline.encodedPolyline');
|
|
||||||
|
|
||||||
final payload = jsonEncode({
|
|
||||||
"travelMode": "DRIVE",
|
|
||||||
"routingPreference": "TRAFFIC_AWARE",
|
|
||||||
"origin": { "address": origin },
|
|
||||||
"destination": { "address": destination }
|
|
||||||
});
|
|
||||||
|
|
||||||
request.write(payload);
|
|
||||||
final response = await request.close();
|
|
||||||
final responseBody = await response.transform(utf8.decoder).join();
|
|
||||||
|
|
||||||
try {
|
|
||||||
final json = jsonDecode(responseBody);
|
|
||||||
final routes = json['routes'] as List;
|
|
||||||
final polyStr = routes[0]['polyline']['encodedPolyline'];
|
|
||||||
print("POLYLINE_START");
|
|
||||||
print(polyStr);
|
|
||||||
print("POLYLINE_END");
|
|
||||||
} catch (e) {
|
|
||||||
print("Error: $e\n$responseBody");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
const encoded = "qospGlrrB";
|
|
||||||
|
|
||||||
function safeDecodePolyline(encoded) {
|
|
||||||
let index = 0, len = encoded.length;
|
|
||||||
let lat = 0, lng = 0;
|
|
||||||
const poly = [];
|
|
||||||
|
|
||||||
while (index < len) {
|
|
||||||
let b, shift = 0, result = 0;
|
|
||||||
do {
|
|
||||||
if (index >= len) break;
|
|
||||||
b = encoded.charCodeAt(index++) - 63;
|
|
||||||
result |= (b & 0x1f) << shift;
|
|
||||||
shift += 5;
|
|
||||||
} while (b >= 0x20);
|
|
||||||
let dlat = ((result & 1) !== 0 ? ~(result >> 1) : (result >> 1));
|
|
||||||
lat += dlat;
|
|
||||||
|
|
||||||
shift = 0;
|
|
||||||
result = 0;
|
|
||||||
do {
|
|
||||||
if (index >= len) break;
|
|
||||||
b = encoded.charCodeAt(index++) - 63;
|
|
||||||
result |= (b & 0x1f) << shift;
|
|
||||||
shift += 5;
|
|
||||||
} while (b >= 0x20);
|
|
||||||
let dlng = ((result & 1) !== 0 ? ~(result >> 1) : (result >> 1));
|
|
||||||
lng += dlng;
|
|
||||||
|
|
||||||
poly.push([lat / 1e5, lng / 1e5]);
|
|
||||||
}
|
|
||||||
return poly;
|
|
||||||
}
|
|
||||||
|
|
||||||
const pts = safeDecodePolyline(encoded);
|
|
||||||
console.log("Decoded", pts.length, "points.");
|
|
||||||
for(let i=0; i<5 && i<pts.length; i++) {
|
|
||||||
console.log(pts[i]);
|
|
||||||
}
|
|
||||||
if(pts.length > 5) {
|
|
||||||
console.log("...");
|
|
||||||
for(let i=pts.length-5; i<pts.length; i++) {
|
|
||||||
console.log(pts[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
const fs = require('fs');
|
|
||||||
const https = require('https');
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
const env = fs.readFileSync('functions/.env', 'utf8');
|
|
||||||
const apiKey = env.split('\n').find(l => l.startsWith('API_MAPS=')).split('=')[1].replace(/"/g, '').trim();
|
|
||||||
|
|
||||||
const data = JSON.stringify({
|
|
||||||
"travelMode": "DRIVE",
|
|
||||||
"routingPreference": "TRAFFIC_AWARE",
|
|
||||||
"origin": { "address": "401 route du camping, 69850 Saint Martin en haut" },
|
|
||||||
"destination": { "address": "Salle des fêtes, Orliénas" }
|
|
||||||
});
|
|
||||||
|
|
||||||
const options = {
|
|
||||||
hostname: 'routes.googleapis.com',
|
|
||||||
path: '/directions/v2:computeRoutes',
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'X-Goog-Api-Key': apiKey,
|
|
||||||
'X-Goog-FieldMask': 'routes.distanceMeters,routes.duration,routes.polyline.encodedPolyline',
|
|
||||||
'Content-Length': data.length
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const req = https.request(options, res => {
|
|
||||||
let body = '';
|
|
||||||
res.on('data', d => body += d);
|
|
||||||
res.on('end', () => {
|
|
||||||
const json = JSON.parse(body);
|
|
||||||
const encoded = json.routes[0].polyline.encodedPolyline;
|
|
||||||
console.log("Encoded string length:", encoded.length);
|
|
||||||
|
|
||||||
// decode
|
|
||||||
let index = 0, len = encoded.length;
|
|
||||||
let lat = 0, lng = 0;
|
|
||||||
const poly = [];
|
|
||||||
while (index < len) {
|
|
||||||
let b, shift = 0, result = 0;
|
|
||||||
do {
|
|
||||||
b = encoded.charCodeAt(index++) - 63;
|
|
||||||
result |= (b & 0x1f) << shift;
|
|
||||||
shift += 5;
|
|
||||||
} while (b >= 0x20);
|
|
||||||
let dlat = ((result & 1) !== 0 ? ~(result >> 1) : (result >> 1));
|
|
||||||
lat += dlat;
|
|
||||||
|
|
||||||
shift = 0;
|
|
||||||
result = 0;
|
|
||||||
do {
|
|
||||||
b = encoded.charCodeAt(index++) - 63;
|
|
||||||
result |= (b & 0x1f) << shift;
|
|
||||||
shift += 5;
|
|
||||||
} while (b >= 0x20);
|
|
||||||
let dlng = ((result & 1) !== 0 ? ~(result >> 1) : (result >> 1));
|
|
||||||
lng += dlng;
|
|
||||||
|
|
||||||
poly.push([lat / 1e5, lng / 1e5]);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("Decoded points:", poly.length);
|
|
||||||
for(let i=0; i<5; i++) console.log(poly[i]);
|
|
||||||
|
|
||||||
// Search for exploding coordinates
|
|
||||||
for(let i=0; i<poly.length; i++) {
|
|
||||||
if (Math.abs(poly[i][0]) > 90 || Math.abs(poly[i][1]) > 180) {
|
|
||||||
console.log("EXPLODED AT INDEX", i, "POINT:", poly[i]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
req.write(data);
|
|
||||||
req.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
main();
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
import 'dart:convert';
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
void main() async {
|
|
||||||
final origin = "401 route du camping, 69850 Saint Martin en haut";
|
|
||||||
final destination = "652431, 6853241"; // Lambert 93 example
|
|
||||||
|
|
||||||
final envFile = File('functions/.env');
|
|
||||||
final lines = await envFile.readAsLines();
|
|
||||||
String apiKey = '';
|
|
||||||
for (var line in lines) {
|
|
||||||
if (line.startsWith('API_MAPS=')) {
|
|
||||||
apiKey = line.split('=')[1].replaceAll('"', '');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final url = 'https://routes.googleapis.com/directions/v2:computeRoutes';
|
|
||||||
final client = HttpClient();
|
|
||||||
final request = await client.postUrl(Uri.parse(url));
|
|
||||||
request.headers.set('Content-Type', 'application/json');
|
|
||||||
request.headers.set('X-Goog-Api-Key', apiKey);
|
|
||||||
request.headers.set('X-Goog-FieldMask', 'routes.distanceMeters,routes.duration,routes.polyline.encodedPolyline');
|
|
||||||
|
|
||||||
final payload = jsonEncode({
|
|
||||||
"travelMode": "DRIVE",
|
|
||||||
"routingPreference": "TRAFFIC_AWARE",
|
|
||||||
"origin": { "address": origin },
|
|
||||||
"destination": { "address": destination }
|
|
||||||
});
|
|
||||||
|
|
||||||
request.write(payload);
|
|
||||||
final response = await request.close();
|
|
||||||
final responseBody = await response.transform(utf8.decoder).join();
|
|
||||||
print(response.statusCode);
|
|
||||||
print(responseBody);
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
import 'dart:convert';
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
void main() async {
|
|
||||||
final envFile = File('functions/.env');
|
|
||||||
final lines = await envFile.readAsLines();
|
|
||||||
String apiKey = '';
|
|
||||||
for (var line in lines) {
|
|
||||||
if (line.startsWith('API_MAPS=')) {
|
|
||||||
apiKey = line.split('=')[1].replaceAll('"', '');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final url = 'https://routes.googleapis.com/directions/v2:computeRoutes';
|
|
||||||
final client = HttpClient();
|
|
||||||
|
|
||||||
// Test with origin = Lambert 93 coordinates
|
|
||||||
final request = await client.postUrl(Uri.parse(url));
|
|
||||||
request.headers.set('Content-Type', 'application/json');
|
|
||||||
request.headers.set('X-Goog-Api-Key', apiKey);
|
|
||||||
request.headers.set('X-Goog-FieldMask', 'routes.distanceMeters,routes.duration,routes.polyline.encodedPolyline');
|
|
||||||
|
|
||||||
final payload = jsonEncode({
|
|
||||||
"travelMode": "DRIVE",
|
|
||||||
"routingPreference": "TRAFFIC_AWARE",
|
|
||||||
"origin": { "address": "652431, 6853241" },
|
|
||||||
"destination": { "address": "Salle des fêtes, Orliénas" }
|
|
||||||
});
|
|
||||||
|
|
||||||
request.write(payload);
|
|
||||||
final response = await request.close();
|
|
||||||
final responseBody = await response.transform(utf8.decoder).join();
|
|
||||||
print(response.statusCode);
|
|
||||||
print(responseBody);
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
import 'dart:convert';
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
void main() async {
|
|
||||||
final envFile = File('functions/.env');
|
|
||||||
final lines = await envFile.readAsLines();
|
|
||||||
String apiKey = '';
|
|
||||||
for (var line in lines) {
|
|
||||||
if (line.startsWith('API_MAPS=')) {
|
|
||||||
apiKey = line.split('=')[1].replaceAll('"', '');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final url = 'https://routes.googleapis.com/directions/v2:computeRoutes';
|
|
||||||
final client = HttpClient();
|
|
||||||
|
|
||||||
final request = await client.postUrl(Uri.parse(url));
|
|
||||||
request.headers.set('Content-Type', 'application/json');
|
|
||||||
request.headers.set('X-Goog-Api-Key', apiKey);
|
|
||||||
request.headers.set('X-Goog-FieldMask', 'routes.distanceMeters,routes.duration,routes.polyline.encodedPolyline');
|
|
||||||
|
|
||||||
final payload = jsonEncode({
|
|
||||||
"travelMode": "DRIVE",
|
|
||||||
"routingPreference": "TRAFFIC_AWARE",
|
|
||||||
"origin": { "address": "401 route du camping, 69850 Saint Martin en haut" },
|
|
||||||
"destination": { "address": "652431, 6853241" }
|
|
||||||
});
|
|
||||||
|
|
||||||
request.write(payload);
|
|
||||||
final response = await request.close();
|
|
||||||
final responseBody = await response.transform(utf8.decoder).join();
|
|
||||||
|
|
||||||
print(responseBody);
|
|
||||||
}
|
|
||||||
File diff suppressed because one or more lines are too long
@@ -1,144 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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);
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
import 'dart:convert';
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
void main() async {
|
|
||||||
final envFile = File('functions/.env');
|
|
||||||
final lines = await envFile.readAsLines();
|
|
||||||
String apiKey = '';
|
|
||||||
for (var line in lines) {
|
|
||||||
if (line.startsWith('API_MAPS=')) {
|
|
||||||
apiKey = line.split('=')[1].replaceAll('"', '');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final url = 'https://routes.googleapis.com/directions/v2:computeRoutes';
|
|
||||||
final client = HttpClient();
|
|
||||||
|
|
||||||
final request = await client.postUrl(Uri.parse(url));
|
|
||||||
request.headers.set('Content-Type', 'application/json');
|
|
||||||
request.headers.set('X-Goog-Api-Key', apiKey);
|
|
||||||
request.headers.set('X-Goog-FieldMask', 'routes.distanceMeters,routes.duration,routes.polyline.encodedPolyline');
|
|
||||||
|
|
||||||
final payload = jsonEncode({
|
|
||||||
"travelMode": "DRIVE",
|
|
||||||
"routingPreference": "TRAFFIC_AWARE",
|
|
||||||
"routeModifiers": { "avoidTolls": true },
|
|
||||||
"origin": { "address": "401 route du camping, 69850 Saint Martin en haut" },
|
|
||||||
"destination": { "address": "25 Imp. du Puits du Suc, Saint-Martin-en-Haut, France" }
|
|
||||||
});
|
|
||||||
|
|
||||||
request.write(payload);
|
|
||||||
final response = await request.close();
|
|
||||||
final responseBody = await response.transform(utf8.decoder).join();
|
|
||||||
|
|
||||||
try {
|
|
||||||
final json = jsonDecode(responseBody);
|
|
||||||
final routes = json['routes'] as List;
|
|
||||||
final polyStr = routes[0]['polyline']['encodedPolyline'] as String;
|
|
||||||
|
|
||||||
print("Polyline found. Length: ${polyStr.length}");
|
|
||||||
print("String: $polyStr");
|
|
||||||
|
|
||||||
int index = 0, len = polyStr.length;
|
|
||||||
int lat = 0, lng = 0;
|
|
||||||
List poly = [];
|
|
||||||
while (index < len) {
|
|
||||||
int b, shift = 0, result = 0;
|
|
||||||
do {
|
|
||||||
b = polyStr.codeUnitAt(index++) - 63;
|
|
||||||
result |= (b & 0x1f) << shift;
|
|
||||||
shift += 5;
|
|
||||||
} while (b >= 0x20);
|
|
||||||
int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
|
|
||||||
lat += dlat;
|
|
||||||
|
|
||||||
shift = 0;
|
|
||||||
result = 0;
|
|
||||||
do {
|
|
||||||
b = polyStr.codeUnitAt(index++) - 63;
|
|
||||||
result |= (b & 0x1f) << shift;
|
|
||||||
shift += 5;
|
|
||||||
} while (b >= 0x20);
|
|
||||||
int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
|
|
||||||
lng += dlng;
|
|
||||||
|
|
||||||
double finalLat = lat / 1e5;
|
|
||||||
double finalLng = lng / 1e5;
|
|
||||||
|
|
||||||
if (finalLat.abs() > 90.0 || finalLng.abs() > 180.0) {
|
|
||||||
print("EXPLODED at index $index: $finalLat, $finalLng");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
poly.add([finalLat, finalLng]);
|
|
||||||
}
|
|
||||||
print("Decode complete. Points:");
|
|
||||||
for (var pt in poly) {
|
|
||||||
print(pt);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
print("Error: $e");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because one or more lines are too long
Binary file not shown.
Reference in New Issue
Block a user