From c9fd4915b812015836eec60e5b75d03d1f272e9f Mon Sep 17 00:00:00 2001 From: Adam Wisher <37659188+mrwish7@users.noreply.github.com> Date: Sat, 31 May 2025 09:12:26 +0100 Subject: [PATCH] Multi TX search tweaks Order the match list by score, clean up of matches panel HTML and show score in DOM as data element --- server/datahandler.js | 3 ++- server/tx_search.js | 7 +++++-- web/index.ejs | 2 +- web/js/main.js | 15 ++++++++------- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/server/datahandler.js b/server/datahandler.js index d0e2291..1f4ef74 100644 --- a/server/datahandler.js +++ b/server/datahandler.js @@ -421,7 +421,8 @@ function handleData(wss, receivedData, rdsWss) { id: currentTx.id, pi: currentTx.pi, reg: currentTx.reg, - otherMatches: currentTx.others + otherMatches: currentTx.others, + score: currentTx.score, }; } }) diff --git a/server/tx_search.js b/server/tx_search.js index 2380cce..33c8eef 100644 --- a/server/tx_search.js +++ b/server/tx_search.js @@ -191,10 +191,12 @@ async function fetchTx(freq, piCode, rdsPs) { for (loc of filteredLocations) { loc.score = evaluateStation(loc); } - match = filteredLocations.reduce((max, obj) => obj.score > max.score ? obj : max, filteredLocations[0]); - multiMatches = filteredLocations.filter(obj => obj !== match); + filteredLocations.sort((a, b) => b.score - a.score); + match = filteredLocations[0]; + multiMatches = filteredLocations.slice(1); } else if (filteredLocations.length === 1) { match = filteredLocations[0]; + match.score = 1; } if (match) { @@ -218,6 +220,7 @@ async function fetchTx(freq, piCode, rdsPs) { pi: match.pi, foundStation: true, reg: match.detectedByPireg, + score: match.score, others: multiMatches, }; } else { diff --git a/web/index.ejs b/web/index.ejs index 044d2ed..286c8b0 100644 --- a/web/index.ejs +++ b/web/index.ejs @@ -290,7 +290,7 @@
-
+

diff --git a/web/js/main.js b/web/js/main.js index 532bce2..0645d06 100644 --- a/web/js/main.js +++ b/web/js/main.js @@ -918,13 +918,11 @@ function throttle(fn, wait) { } function buildAltTxList(txList) { - const wrapper = '
'; let outString = ''; - outString += wrapper; for (let i = 0; i < txList.length; i++) { const tx = txList[i]; outString += `
-
+

${tx.station.replace("R.", "Radio ").replace(/%/g, '%25')}

@@ -935,11 +933,7 @@ function buildAltTxList(txList) {
`; - if (i % 2 !== 0) { - outString += `
${wrapper}`; - } } - outString += '
'; return outString; } @@ -955,6 +949,12 @@ function updateHtmlIfChanged($element, newHtml) { } } +function updateDatasetValIfChanged($element, dataLabel, newVal) { + if ($element.attr(dataLabel) !== newVal) { + $element.attr(dataLabel, newVal); + } +} + // Main function to update data elements, optimized const updateDataElements = throttle(function(parsedData) { updateTextIfChanged($dataFrequency, parsedData.freq); @@ -1015,6 +1015,7 @@ const updateDataElements = throttle(function(parsedData) { updateTextIfChanged($('#data-station-pol'), parsedData.txInfo.pol); updateHtmlIfChanged($('#data-station-azimuth'), parsedData.txInfo.azi + '°'); updateHtmlIfChanged($('#data-station-others'), parsedData.txInfo.otherMatches.length > 0 ? ('+' + parsedData.txInfo.otherMatches.length +'') : ''); + updateDatasetValIfChanged($('#data-station-container'), "data-score", parsedData.txInfo.score); const txDistance = localStorage.getItem('imperialUnits') == "true" ? (Number(parsedData.txInfo.dist) * 0.621371192).toFixed(0) + " mi" : parsedData.txInfo.dist + " km"; const altTxInfo = buildAltTxList(parsedData.txInfo.otherMatches); updateHtmlIfChanged($('#alternative-txes'), altTxInfo);