From 2b05b608ba6a17a98757f29d527b6f9684724c49 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 11 Jul 2025 10:00:37 -0600 Subject: [PATCH] debugged build precision values on decimal places inside nocodb --- map/app/controllers/locationsController.js | 4 +- map/app/services/geocoding.js | 4 +- map/app/utils/helpers.js | 102 ++++++++++++--------- map/build-nocodb.sh | 26 ++++-- test.md | 1 + 5 files changed, 82 insertions(+), 55 deletions(-) create mode 100644 test.md diff --git a/map/app/controllers/locationsController.js b/map/app/controllers/locationsController.js index 1ecfc42..2500f4c 100644 --- a/map/app/controllers/locationsController.js +++ b/map/app/controllers/locationsController.js @@ -121,10 +121,10 @@ class LocationsController { } } - // Format geodata + // Format geodata with string values to preserve precision const geodata = `${validation.latitude};${validation.longitude}`; - // Prepare data for NocoDB + // Prepare data for NocoDB - keep coordinates as strings const finalData = { geodata, 'Geo-Location': geodata, diff --git a/map/app/services/geocoding.js b/map/app/services/geocoding.js index d26a6f1..eacc369 100644 --- a/map/app/services/geocoding.js +++ b/map/app/services/geocoding.js @@ -36,8 +36,8 @@ setInterval(() => { * @returns {Promise} Geocoding result */ async function reverseGeocode(lat, lng) { - // Create cache key - const cacheKey = `${lat.toFixed(6)},${lng.toFixed(6)}`; + // Create cache key - use full precision + const cacheKey = `${lat},${lng}`; // Check cache first const cached = geocodeCache.get(cacheKey); diff --git a/map/app/utils/helpers.js b/map/app/utils/helpers.js index b656907..927accf 100644 --- a/map/app/utils/helpers.js +++ b/map/app/utils/helpers.js @@ -2,12 +2,16 @@ function syncGeoFields(data) { // If we have latitude and longitude but no Geo-Location, create it if (data.latitude && data.longitude && !data['Geo-Location']) { - const lat = parseFloat(data.latitude); - const lng = parseFloat(data.longitude); - if (!isNaN(lat) && !isNaN(lng)) { - data['Geo-Location'] = `${lat};${lng}`; - data.geodata = `${lat};${lng}`; - } + // Keep as strings to preserve precision + const lat = typeof data.latitude === 'string' ? data.latitude : String(data.latitude); + const lng = typeof data.longitude === 'string' ? data.longitude : String(data.longitude); + + data['Geo-Location'] = `${lat};${lng}`; + data.geodata = `${lat};${lng}`; + + // Keep original values without parsing + data.latitude = lat; + data.longitude = lng; } // If we have Geo-Location but no lat/lng, parse it else if (data['Geo-Location'] && (!data.latitude || !data.longitude)) { @@ -16,9 +20,12 @@ function syncGeoFields(data) { // Try semicolon-separated first let parts = geoLocation.split(';'); if (parts.length === 2) { - const lat = parseFloat(parts[0].trim()); - const lng = parseFloat(parts[1].trim()); - if (!isNaN(lat) && !isNaN(lng)) { + // Keep as strings to preserve precision + const lat = parts[0].trim(); + const lng = parts[1].trim(); + + // Only validate they're numeric, don't convert + if (!isNaN(parseFloat(lat)) && !isNaN(parseFloat(lng))) { data.latitude = lat; data.longitude = lng; data.geodata = `${lat};${lng}`; @@ -29,9 +36,10 @@ function syncGeoFields(data) { // Try comma-separated parts = geoLocation.split(','); if (parts.length === 2) { - const lat = parseFloat(parts[0].trim()); - const lng = parseFloat(parts[1].trim()); - if (!isNaN(lat) && !isNaN(lng)) { + const lat = parts[0].trim(); + const lng = parts[1].trim(); + + if (!isNaN(parseFloat(lat)) && !isNaN(parseFloat(lng))) { data.latitude = lat; data.longitude = lng; data.geodata = `${lat};${lng}`; @@ -44,6 +52,46 @@ function syncGeoFields(data) { return data; } +// Validate coordinates +function validateCoordinates(lat, lng) { + // Keep original string values + const latStr = typeof lat === 'string' ? lat : String(lat); + const lngStr = typeof lng === 'string' ? lng : String(lng); + + // Parse only for validation + const latitude = parseFloat(latStr); + const longitude = parseFloat(lngStr); + + if (isNaN(latitude) || isNaN(longitude)) { + return { valid: false, error: 'Invalid coordinate values' }; + } + + if (latitude < -90 || latitude > 90) { + return { valid: false, error: 'Latitude must be between -90 and 90' }; + } + + if (longitude < -180 || longitude > 180) { + return { valid: false, error: 'Longitude must be between -180 and 180' }; + } + + // Return the original string values to preserve precision + return { valid: true, latitude: latStr, longitude: lngStr }; +} + +// Check if coordinates are within bounds +function checkBounds(lat, lng, bounds) { + if (!bounds) return true; + + // Parse only for comparison + const latitude = parseFloat(lat); + const longitude = parseFloat(lng); + + return latitude <= bounds.north && + latitude >= bounds.south && + longitude <= bounds.east && + longitude >= bounds.west; +} + // Validate URL format function validateUrl(url) { if (!url || typeof url !== 'string') { @@ -101,36 +149,6 @@ function extractId(record) { return record.Id || record.id || record.ID || record._id; } -// Validate coordinates -function validateCoordinates(lat, lng) { - const latitude = parseFloat(lat); - const longitude = parseFloat(lng); - - if (isNaN(latitude) || isNaN(longitude)) { - return { valid: false, error: 'Invalid coordinate values' }; - } - - if (latitude < -90 || latitude > 90) { - return { valid: false, error: 'Latitude must be between -90 and 90' }; - } - - if (longitude < -180 || longitude > 180) { - return { valid: false, error: 'Longitude must be between -180 and 180' }; - } - - return { valid: true, latitude, longitude }; -} - -// Check if coordinates are within bounds -function checkBounds(lat, lng, bounds) { - if (!bounds) return true; - - return lat <= bounds.north && - lat >= bounds.south && - lng <= bounds.east && - lng >= bounds.west; -} - // Sanitize user data for response function sanitizeUser(user) { const { Password, password, ...safeUser } = user; diff --git a/map/build-nocodb.sh b/map/build-nocodb.sh index ec5507b..fb98cae 100755 --- a/map/build-nocodb.sh +++ b/map/build-nocodb.sh @@ -265,16 +265,20 @@ create_locations_table() { "title": "latitude", "uidt": "Decimal", "rqd": false, - "precision": 10, - "scale": 8 + "meta": { + "precision": 8, + "scale": 8 + } }, { "column_name": "longitude", - "title": "longitude", + "title": "longitude", "uidt": "Decimal", "rqd": false, - "precision": 11, - "scale": 8 + "meta": { + "precision": 8, + "scale": 8 + } }, { "column_name": "first_name", @@ -486,16 +490,20 @@ create_settings_table() { "title": "latitude", "uidt": "Decimal", "rqd": false, - "precision": 10, - "scale": 8 + "meta": { + "precision": 8, + "scale": 8 + } }, { "column_name": "longitude", "title": "longitude", "uidt": "Decimal", "rqd": false, - "precision": 11, - "scale": 8 + "meta": { + "precision": 8, + "scale": 8 + } }, { "column_name": "zoom", diff --git a/test.md b/test.md new file mode 100644 index 0000000..f451671 --- /dev/null +++ b/test.md @@ -0,0 +1 @@ +Just a test file \ No newline at end of file