From c7bef2db07b0cce3dbde8dc24dfd939d44ca1b8c Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Sat, 23 Aug 2025 21:21:01 +0100 Subject: [PATCH] Normalize callsign grouping in most worked query Updates SQL logic to group callsigns by their base identifier, stripping suffixes like /P, /MM, /AM, /QRP, /LH, and /BCN. This ensures contacts are aggregated correctly for operators using such suffixes. --- application/models/Mostworked_model.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/application/models/Mostworked_model.php b/application/models/Mostworked_model.php index 92d2a596..fc66f525 100644 --- a/application/models/Mostworked_model.php +++ b/application/models/Mostworked_model.php @@ -27,7 +27,12 @@ class Mostworked_model extends CI_Model $todate = isset($filters['todate']) ? $filters['todate'] : ''; $sql = "SELECT - col_call as callsign, + CASE + WHEN col_call REGEXP '/[PMAQLB]$|/MM$|/AM$|/QRP$|/LH$|/BCN$' THEN + SUBSTRING(col_call, 1, LOCATE('/', col_call) - 1) + ELSE + col_call + END as callsign, COUNT(*) as contact_count, MIN(col_time_on) as first_qso, MAX(col_time_on) as last_qso, @@ -64,9 +69,14 @@ class Mostworked_model extends CI_Model $sql .= " AND DATE(col_time_on) <= '" . $this->db->escape_str($todate) . "'"; } - $sql .= " GROUP BY col_call + $sql .= " GROUP BY CASE + WHEN col_call REGEXP '/[PMAQLB]$|/MM$|/AM$|/QRP$|/LH$|/BCN$' THEN + SUBSTRING(col_call, 1, LOCATE('/', col_call) - 1) + ELSE + col_call + END HAVING contact_count >= " . $min_qsos . " - ORDER BY contact_count DESC, col_call ASC"; + ORDER BY contact_count DESC, callsign ASC"; $query = $this->db->query($sql);