From 70f08ec39d7117bec5e33a946d698729d3347007 Mon Sep 17 00:00:00 2001 From: Adam Wisher <37659188+mrwish7@users.noreply.github.com> Date: Sat, 6 Jul 2024 21:49:58 +0100 Subject: [PATCH 1/3] Sporadic E mode for TX search Add sporadic E mode for TX search, to optimise for 1500km distance if recent activity has been reported in server region. --- server/tx_search.js | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/server/tx_search.js b/server/tx_search.js index 60e08b7..ad03bae 100644 --- a/server/tx_search.js +++ b/server/tx_search.js @@ -46,6 +46,7 @@ function processData(data, piCode, rdsPs) { let maxScore = -Infinity; // Initialize maxScore with a very low value let txAzimuth; let maxDistance; + let esMode = checkEs(); for (const cityId in data.locations) { const city = data.locations[cityId]; @@ -53,7 +54,13 @@ function processData(data, piCode, rdsPs) { for (const station of city.stations) { if (station.pi === piCode.toUpperCase() && !station.extra && station.ps && station.ps.toLowerCase().includes(rdsPs.replace(/ /g, '_').replace(/^_*(.*?)_*$/, '$1').toLowerCase())) { const distance = haversine(serverConfig.identification.lat, serverConfig.identification.lon, city.lat, city.lon); - const score = (10*Math.log10(station.erp*1000)) / distance.distanceKm; // Calculate score + let weightDistance = distance.distanceKm + if (esMode && distance.distanceKm > 200) { + weightDistance = Math.abs(distance.distanceKm-1500); + } else { + weightDistance = distance.distanceKm; + } + const score = (10*Math.log10(station.erp*1000)) / weightDistance; // Calculate score if (score > maxScore) { maxScore = score; txAzimuth = distance.azimuth; @@ -82,6 +89,29 @@ function processData(data, piCode, rdsPs) { } } +function checkEs() { + const url = "https://fmdx.org/includes/tools/get_muf.php"; + let esSwitch = false; + + fetch(url) + .then(response => response.json()) + .then(data => { + if (serverConfig.identification.lon < -32) { + if (data.north_america.max_frequency != "No data") { + esSwitch = true; + } + } else { + if (data.europe.max_frequency != "No data") { + esSwitch = true; + } + } + }) + .catch(error => { + console.error("Error fetching data:", error); + }); + return esSwitch; +} + function haversine(lat1, lon1, lat2, lon2) { const R = 6371; // Earth radius in kilometers const dLat = deg2rad(lat2 - lat1); From 993456ef47d2736ada9dd4e484528f3aa657f9b0 Mon Sep 17 00:00:00 2001 From: Adam Wisher <37659188+mrwish7@users.noreply.github.com> Date: Sun, 14 Jul 2024 09:59:47 +0100 Subject: [PATCH 2/3] TX search sp.E mode: tidy up Remove unrequired lines from sp.E mode switch code. --- server/tx_search.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/server/tx_search.js b/server/tx_search.js index ad03bae..325df36 100644 --- a/server/tx_search.js +++ b/server/tx_search.js @@ -57,8 +57,6 @@ function processData(data, piCode, rdsPs) { let weightDistance = distance.distanceKm if (esMode && distance.distanceKm > 200) { weightDistance = Math.abs(distance.distanceKm-1500); - } else { - weightDistance = distance.distanceKm; } const score = (10*Math.log10(station.erp*1000)) / weightDistance; // Calculate score if (score > maxScore) { From d7fa74f6716280da5349759a425cfb7facd3b389 Mon Sep 17 00:00:00 2001 From: Adam Wisher <37659188+mrwish7@users.noreply.github.com> Date: Sun, 14 Jul 2024 21:10:56 +0100 Subject: [PATCH 3/3] Add caching for spE mode switch Cache endpoint response for sporadic E TX search mode for 5 minutes to avoid excessive calls --- server/tx_search.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/server/tx_search.js b/server/tx_search.js index 325df36..4d6119a 100644 --- a/server/tx_search.js +++ b/server/tx_search.js @@ -6,6 +6,9 @@ let cachedData = {}; let lastFetchTime = 0; const fetchInterval = 3000; +const esSwitchCache = {"lastCheck":0, "esSwitch":false}; +const esFetchInterval = 300000; + // Fetch data from maps function fetchTx(freq, piCode, rdsPs) { const now = Date.now(); @@ -55,7 +58,7 @@ function processData(data, piCode, rdsPs) { if (station.pi === piCode.toUpperCase() && !station.extra && station.ps && station.ps.toLowerCase().includes(rdsPs.replace(/ /g, '_').replace(/^_*(.*?)_*$/, '$1').toLowerCase())) { const distance = haversine(serverConfig.identification.lat, serverConfig.identification.lon, city.lat, city.lon); let weightDistance = distance.distanceKm - if (esMode && distance.distanceKm > 200) { + if (esMode && (distance.distanceKm > 200)) { weightDistance = Math.abs(distance.distanceKm-1500); } const score = (10*Math.log10(station.erp*1000)) / weightDistance; // Calculate score @@ -88,10 +91,15 @@ function processData(data, piCode, rdsPs) { } function checkEs() { + const now = Date.now(); const url = "https://fmdx.org/includes/tools/get_muf.php"; let esSwitch = false; - fetch(url) + if (now - esSwitchCache.lastCheck < esFetchInterval) { + esSwitch = esSwitchCache.esSwitch; + } else { + esSwitchCache.lastCheck = now; + fetch(url) .then(response => response.json()) .then(data => { if (serverConfig.identification.lon < -32) { @@ -103,10 +111,13 @@ function checkEs() { esSwitch = true; } } + esSwitchCache.esSwitch = esSwitch; }) .catch(error => { console.error("Error fetching data:", error); }); + } + return esSwitch; }