From 2cd2cf5cf1f00cf39497b3ca10ccf075c0e2473a Mon Sep 17 00:00:00 2001 From: Adam Wisher <37659188+mrwish7@users.noreply.github.com> Date: Mon, 21 Apr 2025 08:22:36 +0100 Subject: [PATCH] TX ID Algorithm tweaks and config options Fix bug when TX ERP is 1W and allow user choice of algorithms in webserver config --- server/server_config.js | 3 ++- server/tx_search.js | 27 ++++++++++++++++++++++++--- web/setup.ejs | 10 ++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/server/server_config.js b/server/server_config.js index 1be8796..8c6ae9b 100644 --- a/server/server_config.js +++ b/server/server_config.js @@ -30,7 +30,8 @@ let serverConfig = { ], defaultTheme: "theme1", bgImage: "", - rdsMode: false + rdsMode: false, + txIdAlgorithm: 0 }, xdrd: { wirelessConnection: true, diff --git a/server/tx_search.js b/server/tx_search.js index 38220e5..cf48bcd 100644 --- a/server/tx_search.js +++ b/server/tx_search.js @@ -12,6 +12,21 @@ var currentRdsPs = ''; const usStatesGeoJsonUrl = "https://raw.githubusercontent.com/PublicaMundi/MappingAPI/master/data/geojson/us-states.json"; let usStatesGeoJson = null; // To cache the GeoJSON data for US states +// Get weighting values based on algorithm setting. +// Defaults = algorithm 1 +let weightedErp = 10; +let weightedDist = 400; +const algorithms = [ + [10, 400], + [30, 500] +]; +const algoSetting = parseInt(serverConfig.webserver.txIdAlgorithm); + +if (typeof algorithms[algoSetting] !== 'undefined') { + weightedErp = algorithms[algoSetting][0]; + weightedDist = algorithms[algoSetting][1]; +} + // Load the US states GeoJSON data async function loadUsStatesGeoJson() { if (!usStatesGeoJson) { @@ -121,8 +136,14 @@ async function processData(data, piCode, rdsPs) { weightDistance = Math.abs(distance.distanceKm - 1500); } let erp = station.erp && station.erp > 0 ? station.erp : 1; - let extraWeight = erp >= 10 && distance.distanceKm <= 400 ? 0.3 : 0; - const score = ((10 * Math.log10(erp * 1000)) / weightDistance) + extraWeight; + let extraWeight = erp >= weightedErp && distance.distanceKm <= weightedDist ? 0.3 : 0; + let score = 0; + // If ERP is 1W, use a simpler formula to avoid zero-scoring. + if (erp === 0.001) { + score = erp / distance.distanceKm; + } else { + score = ((10 * Math.log10(erp * 1000)) / weightDistance) + extraWeight; + } if (score > maxScore) { maxScore = score; txAzimuth = distance.azimuth; @@ -247,4 +268,4 @@ function deg2rad(deg) { module.exports = { fetchTx -}; +}; \ No newline at end of file diff --git a/web/setup.ejs b/web/setup.ejs index f63edfd..207e671 100644 --- a/web/setup.ejs +++ b/web/setup.ejs @@ -296,6 +296,16 @@

You can switch between American (RBDS) / Global (RDS) mode here.

<%- include('_components', {component: 'checkbox', cssClass: 'bottom-20', iconClass: '', label: 'American RDS mode (RBDS)', id: 'webserver-rdsMode'}) %>
+
+

Transmitter Search Algorithm

+

Different modes may help with more accurate transmitter identification depending on your region.

+ <%- include('_components', { component: 'dropdown', id: 'server-tx-id-algo', inputId: 'webserver-txIdAlgorithm', label: 'Transmitter ID Algorithm', cssClass: '', placeholder: 'Algorithm 1', + options: [ + { value: '0', label: 'Algorithm 1' }, + { value: '1', label: 'Algorithm 2' }, + ] + }) %> +