diff --git a/application/controllers/Calltester.php b/application/controllers/Calltester.php index d1ddad509..f922c2ce0 100644 --- a/application/controllers/Calltester.php +++ b/application/controllers/Calltester.php @@ -53,6 +53,7 @@ class Calltester extends CI_Controller { /* Uses DXCC Class. Much faster */ function doClassCheck($de) { + ini_set('memory_limit', '-1'); $i = 0; $result = array(); @@ -185,6 +186,7 @@ class Calltester extends CI_Controller { } function getQsos($station_id) { + ini_set('memory_limit', '-1'); $sql = 'select distinct col_country, col_call, col_dxcc, date(col_time_on) date, station_profile.station_profile_name, col_primary_key from ' . $this->config->item('table_name') . ' join station_profile on ' . $this->config->item('table_name') . '.station_id = station_profile.station_id @@ -368,273 +370,434 @@ class Calltester extends CI_Controller { 'Callsign' => 'WJ7R/C6A', 'Country' => 'Bahamas', 'Adif' => 60, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'WJ7R/KH6', 'Country' => 'Hawaii', 'Adif' => 110, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'WJ7R/C6', 'Country' => 'Bahamas', 'Adif' => 60, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'VE3EY/VP9', 'Country' => 'Bermuda', 'Adif' => 64, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'VP2MDG', 'Country' => 'Montserrat', 'Adif' => 96, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'VP2EY', 'Country' => 'Anguilla', 'Adif' => 12, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'VP2VI', 'Country' => 'British Virgin Islands.', 'Adif' => 65, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'VP2V/AA7V', 'Country' => 'British Virgin Islands', 'Adif' => 65, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'W8LR/R', 'Country' => 'United States Of America', 'Adif' => 291, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'SO1FH', 'Country' => 'Poland', 'Adif' => 269, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'KZ1H/PP', 'Country' => 'Brazil', 'Adif' => 108, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'K1KW/AM', 'Country' => 'None', 'Adif' => 0, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'K1KW/MM', 'Country' => 'None', 'Adif' => 0, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'TF/DL2NWK/P', 'Country' => 'Iceland', 'Adif' => 242, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'OZ1ALS/A', 'Country' => 'Denmark', 'Adif' => 221, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'LA1K', 'Country' => 'Norway', 'Adif' => 266, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'K1KW/M', 'Country' => 'United States Of America', 'Adif' => 291, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'TF/DL2NWK/M', 'Country' => 'Iceland', 'Adif' => 242, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'TF/DL2NWK/MM', 'Country' => 'None', 'Adif' => 0, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'TF/DL2NWK/P', 'Country' => 'Iceland', 'Adif' => 242, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => '2M0SQL/P', 'Country' => 'Scotland', 'Adif' => 279, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'FT8WW', 'Country' => 'Crozet Island', 'Adif' => 41, - 'Date' => 20230314 + 'Date' => '2023-03-14' ); $testarray[] = array( 'Callsign' => 'RV0AL/0/P', 'Country' => 'Asiatic Russia', 'Adif' => 15, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'OH/DJ1YFK', 'Country' => 'Finland', 'Adif' => 224, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'N6TR/7', 'Country' => 'United States Of America', 'Adif' => 291, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'KH0CW', 'Country' => 'United States Of America', 'Adif' => 291, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'R2FM/P', 'Country' => 'kaliningrad', 'Adif' => 126, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'R2FM', 'Country' => 'kaliningrad', 'Adif' => 126, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'FT5XO', 'Country' => 'Kerguelen Island', 'Adif' => 131, - 'Date' => 20050320 + 'Date' => '2005-03-20' ); $testarray[] = array( 'Callsign' => 'VP8CTR', 'Country' => 'Antarctica', 'Adif' => 13, - 'Date' => 19970207 + 'Date' => '1997-02-07' ); $testarray[] = array( 'Callsign' => 'FO0AAA', 'Country' => 'Clipperton', 'Adif' => 36, - 'Date' => '20000302' + 'Date' => '2000-03-02' ); $testarray[] = array( 'Callsign' => 'CX/PR8KW', 'Country' => 'Uruguay', 'Adif' => 144, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'IQ3MV/LH', 'Country' => 'Italy', 'Adif' => 248, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'LA1K/QRP', 'Country' => 'Norway', 'Adif' => 266, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'LA1K/LGT', 'Country' => 'Norway', 'Adif' => 266, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'SM1K/LH', 'Country' => 'Sweden', 'Adif' => 284, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'KG4W', 'Country' => 'United States Of America', 'Adif' => 291, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'KG4WW', 'Country' => 'Guantanamo Bay', 'Adif' => 105, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) ); $testarray[] = array( 'Callsign' => 'KG4WWW', 'Country' => 'United States Of America', 'Adif' => 291, - 'Date' => $date = date('Ymd', time()) + 'Date' => $date = date('Y-m-d', time()) + ); + + $testarray[] = array( + 'Callsign' => 'JA0JHQ/VK9X', + 'Country' => 'Christmas Island', + 'Adif' => 35, + 'Date' => '2015-05-08' + ); + + $testarray[] = array( + 'Callsign' => 'D5M', + 'Country' => 'Liberia', + 'Adif' => 434, + 'Date' => '2025-12-14' + ); + + $testarray[] = array( + 'Callsign' => 'AT44I', + 'Country' => 'Antarctica', + 'Adif' => 13, + 'Date' => '2025-12-16' + ); + + $testarray[] = array( + 'Callsign' => 'PT7BZ/PY0F', + 'Country' => 'Fernando De Noronha', + 'Adif' => 56, + 'Date' => $date = date('Y-m-d', time()) + ); + + $testarray[] = array( + 'Callsign' => 'VP6A', + 'Country' => 'Ducie Island', + 'Adif' => 513, + 'Date' => '2023-06-21' + ); + + $testarray[] = array( + 'Callsign' => '9M1Z', + 'Country' => 'East Malaysia', + 'Adif' => 46, + 'Date' => '2024-06-24' + ); + + $testarray[] = array( + 'Callsign' => 'VK2/W7BRS', + 'Country' => 'Lord Howe Island', + 'Adif' => 147, + 'Date' => '2024-07-18' + ); + + $testarray[] = array( + 'Callsign' => 'G4SGX/6Y', + 'Country' => 'Jamaica', + 'Adif' => 82, + 'Date' => $date = date('Y-m-d', time()) + ); + + $testarray[] = array( + 'Callsign' => 'DX0JP', + 'Country' => 'Spratly Islands', + 'Adif' => 247, + 'Date' => '2007-02-08' + ); + + $testarray[] = array( + 'Callsign' => 'AU7JCB', + 'Country' => 'India', + 'Adif' => 324, + 'Date' => '2007-02-08' + ); + + $testarray[] = array( + 'Callsign' => 'N2JBY/4X', + 'Country' => 'Israel', + 'Adif' => 336, + 'Date' => $date = date('Y-m-d', time()) + ); + + $testarray[] = array( + 'Callsign' => 'KH5K', + 'Country' => 'Invalid', + 'Adif' => 0, + 'Date' => '1993-03-13' + ); + + $testarray[] = array( + 'Callsign' => 'HB/DK9TA', + 'Country' => 'Switzerland', + 'Adif' => 287, + 'Date' => $date = date('Y-m-d', time()) + ); + + $testarray[] = array( + 'Callsign' => 'OE5DI/500', + 'Country' => 'Austria', + 'Adif' => 206, + 'Date' => $date = date('Y-m-d', time()) + ); + + $testarray[] = array( + 'Callsign' => 'YI6SUL', + 'Country' => 'Invalid', + 'Adif' => 0, + 'Date' => $date = date('Y-m-d', time()) + ); + + $testarray[] = array( + 'Callsign' => '3DA8/DF8LY/P', + 'Country' => 'Kingdom Of Eswatini', + 'Adif' => 468, + 'Date' => $date = date('Y-m-d', time()) + ); + + $testarray[] = array( + 'Callsign' => '3X/DL5DAB', + 'Country' => 'Invalid', + 'Adif' => 0, + 'Date' => $date = date('Y-m-d', time()) + ); + + $testarray[] = array( + 'Callsign' => '3X/DL5DA', + 'Country' => 'Guinea', + 'Adif' => 107, + 'Date' => $date = date('Y-m-d', time()) + ); + + $testarray[] = array( + 'Callsign' => 'KN5H/6YA', + 'Country' => 'Jamaica', + 'Adif' => 82, + 'Date' => $date = date('Y-m-d', time()) + ); + + $testarray[] = array( + 'Callsign' => 'DL2AAZ/6Y5', + 'Country' => 'Jamaica', + 'Adif' => 82, + 'Date' => $date = date('Y-m-d', time()) + ); + + $testarray[] = array( + 'Callsign' => '6Y5WJ', + 'Country' => 'Jamaica', + 'Adif' => 82, + 'Date' => $date = date('Y-m-d', time()) + ); + + $testarray[] = array( + 'Callsign' => 'R20RRC/0', + 'Country' => 'Asiatic Russia', + 'Adif' => 15, + 'Date' => $date = date('Y-m-d', time()) + ); + + $testarray[] = array( + 'Callsign' => 'G4KJV/2K/P', + 'Country' => 'England', + 'Adif' => 223, + 'Date' => $date = date('Y-m-d', time()) ); set_time_limit(3600); @@ -648,22 +811,24 @@ class Calltester extends CI_Controller { $i = 0; + $dxccobj = new Dxcc(null); + foreach ($testarray as $call) { $i++; - $dxcc = $this->logbook_model->dxcc_lookup($call['Callsign'], $call['Date']); + $dxcc = $dxccobj->dxcc_lookup($call['Callsign'], $call['Date']); - $dxcc['adif'] = (isset($dxcc['adif'])) ? $dxcc['adif'] : 0; - $dxcc['entity'] = (isset($dxcc['entity'])) ? $dxcc['entity'] : 0; + $dxcc['adif'] = (isset($dxcc['adif'])) ? $dxcc['adif'] : 0; + $dxcc['entity'] = (isset($dxcc['entity'])) ? $dxcc['entity'] : 'None'; - if ($call['Adif'] != $dxcc['adif']) { - $result[] = array( - 'Callsign' => $call['Callsign'], - 'Expected country' => $call['Country'], - 'Expected adif' => $call['Adif'], - 'Result country' => ucwords(strtolower($dxcc['entity']), "- (/"), - 'Result adif' => $dxcc['adif'], - ); - } + $result[] = array( + 'Callsign' => $call['Callsign'], + 'Date' => $call['Date'], + 'Expected country' => $call['Country'], + 'Expected adif' => $call['Adif'], + 'Result country' => ucwords(strtolower($dxcc['entity']), "- (/"), + 'Result adif' => $dxcc['adif'], + 'Passed' => ($call['Adif'] == $dxcc['adif']) ? 'Yes' : 'No', + ); } // End clock time in seconds @@ -672,12 +837,13 @@ class Calltester extends CI_Controller { // Calculate script execution time $execution_time = ($end_time - $start_time); - echo " Execution time of script = ".$execution_time." sec
"; - echo $i . " calls tested.
"; - $count = 0; + $data['result'] = $result; + $data['execution_time'] = $execution_time; + $data['calls_tested'] = $i; - if ($result) { - $this->array_to_table($result); - } + $data['page_title'] = __("Callsign Tester"); + $this->load->view('interface_assets/header', $data); + $this->load->view('calltester/call'); + $this->load->view('interface_assets/footer'); } } diff --git a/application/views/calltester/call.php b/application/views/calltester/call.php new file mode 100644 index 000000000..08b33b248 --- /dev/null +++ b/application/views/calltester/call.php @@ -0,0 +1,44 @@ +
+"; + +if ($result) { + array_to_table($result); +} ?> + +
+ +'; + + // Table header + foreach ($table[0] as $key=>$value) { + echo "".$key.""; + } + + // Table body + foreach ($table as $value) { + $passed = strtolower($value['Passed'] ?? ''); + $rowClass = ($passed === 'yes') ? 'table-success' : 'table-danger'; + echo ""; + foreach ($value as $key=>$val) { + echo "".$val.""; + } + echo ""; + } + echo ""; +} diff --git a/src/Dxcc/Dxcc.php b/src/Dxcc/Dxcc.php index 779b49f4d..7dff41096 100644 --- a/src/Dxcc/Dxcc.php +++ b/src/Dxcc/Dxcc.php @@ -7,7 +7,7 @@ class Dxcc { protected $dxccexceptions = array(); protected $csadditions = '/^X$|^D$|^T$|^P$|^R$|^B$|^A$|^M$|^LH$|^L$|^J$|^SK$/'; - protected $lidadditions = '/^QRP$|^LGT$/'; + protected $lidadditions = '/^QRP$|^LGT$|^2K$/'; protected $noneadditions = '/^MM$|^AM$/'; function __construct($date) { @@ -45,6 +45,8 @@ class Dxcc { $call = "K"; } elseif (preg_match('/(^OH\/)|(\/OH[1-9]?$)/', $call)) { # non-Aland prefix! $call = "OH"; # make callsign OH = finland + } elseif (preg_match('/(^HB\/)|(\/HB[1-9]?$)/', $call)) { # non-Liechtenstein prefix! + $call = "HB"; # make callsign HB = Switzerland } elseif (preg_match('/(^CX\/)|(\/CX[1-9]?$)/', $call)) { # non-Antarctica prefix! $call = "CX"; # make callsign CX = Uruguay } elseif (preg_match('/(^3D2R)|(^3D2.+\/R)/', $call)) { # seems to be from Rotuma @@ -170,7 +172,15 @@ class Dxcc { if (preg_match($this->lidadditions, $b) || preg_match('/^[0-9]+$/', $b)) { # check if $b is a lid-addition $b = $a; $a = null; # $a goes to $b, delete lid-add - } elseif ((preg_match('/\d[A-Z]+$/', $a)) && (preg_match('/\d$/', $b) || preg_match('/^[A-Z]\d[A-Z]$/', $b))) { # check for call in $a + } elseif ((preg_match('/\d[A-Z]+$/', $a)) && (preg_match('/\d$/', $b) || preg_match('/^[A-Z]\d[A-Z]$/', $b) || preg_match('/^\d[A-Z]+$/', $b))) { + $temp = $b; + $b = $a; + $a = $temp; + } + # Additional check: if $a looks like a full callsign (longer than typical prefix) + # and $b looks like a country prefix (short, with digit), swap them + # This handles cases like JA0JHQ/VK9X where VK9X should be the prefix + elseif (strlen($a) >= 5 && preg_match('/^\d?[A-Z]+\d[A-Z]+$/', $a) && strlen($b) <= 5 && preg_match('/^[A-Z]+\d[A-Z]*$/', $b)) { $temp = $b; $b = $a; $a = $temp; @@ -210,38 +220,53 @@ class Dxcc { } else { # Case 1.2, no number $prefix = substr($b, 0, 2) . "0"; # first two + 0 } - } elseif (($a == null) && (isset($c))) { # Case 2, CALL/X - if (preg_match('/^(\d)/', $c)) { # Case 2.1, number - preg_match('/(.+\d)[A-Z]*/', $b, $matches); # regular Prefix in $1 - # Here we need to find out how many digits there are in the - # prefix, because for example A45XR/0 is A40. If there are 2 - # numbers, the first is not deleted. If course in exotic cases - # like N66A/7 -> N7 this brings the wrong result of N67, but I - # think that's rather irrelevant cos such calls rarely appear - # and if they do, it's very unlikely for them to have a number - # attached. You can still edit it by hand anyway.. - if (!isset($matches[1]) || $matches[1] === null) { - $this->logError('preg_match failed to capture prefix in $b', [ - 'testcall' => $testcall, - 'b' => $b, - 'c' => $c, - 'matches' => $matches - ]); - return ''; - } - if (preg_match('/^([A-Z]\d)\d$/', $matches[1])) { # e.g. A45 $c = 0 - $prefix = $matches[1] . $c; # -> A40 - } else { # Otherwise cut all numbers - if (!preg_match('/(.*[A-Z])\d+/', $matches[1], $match)) { - $this->logError('preg_match failed to extract prefix without number', [ + } elseif (($a == null) && ($c != null && $c != '')) { # Case 2, CALL/X + if (preg_match($this->lidadditions, $c)) { # check if $b is a lid-addition + $prefix = $b; + } else if (preg_match('/^(\d)/', $c)) { # Case 2.1, starts with digit + # Check if $c is a full country prefix (like 6YA, 6Y, etc.) not just a number + # A country prefix has the pattern: digit + letters (like 6YA, 6Y) + # NOT just a single digit + if (strlen($c) > 1 && preg_match('/^\d[A-Z]+$/', $c)) { + # This is a country prefix starting with a digit (like 6YA, 6Y) + # Use it directly - it's already a valid prefix + $prefix = $c; + } elseif (strlen($c) > 1 && preg_match('/^[A-Z]+\d[A-Z]*$/', $c)) { + # Country prefix starting with letters (like W1, K2, etc.) + $prefix = $c; + } else { + # Single digit, replace the digit in the base call # Case 2.1, starts with digit + preg_match('/(.+\d)[A-Z]*/', $b, $matches); # regular Prefix in $1 + # Here we need to find out how many digits there are in the + # prefix, because for example A45XR/0 is A40. If there are 2 + # numbers, the first is not deleted. If course in exotic cases + # like N66A/7 -> N7 this brings the wrong result of N67, but I + # think that's rather irrelevant cos such calls rarely appear + # and if they do, it's very unlikely for them to have a number + # attached. You can still edit it by hand anyway.. + if (!isset($matches[1]) || $matches[1] === null) { + $this->logError('preg_match failed to capture prefix in $b', [ 'testcall' => $testcall, - 'matches1' => $matches[1], 'b' => $b, - 'c' => $c + 'c' => $c, + 'matches' => $matches ]); return ''; } - $prefix = $match[1] . $c; # Add attached number + if (preg_match('/^([A-Z]\d)\d$/', $matches[1])) { # e.g. A45 $c = 0 + $prefix = $matches[1] . $c; # -> A40 + } else { # Otherwise cut all numbers + if (!preg_match('/(.*[A-Z])\d+/', $matches[1], $match)) { + $this->logError('preg_match failed to extract prefix without number', [ + 'testcall' => $testcall, + 'matches1' => $matches[1], + 'b' => $b, + 'c' => $c + ]); + return ''; + } + $prefix = $match[1] . $c; # Add attached number + } } } elseif (preg_match($this->csadditions, $c)) { if (!preg_match('/(.+\d)[A-Z]*/', $b, $matches)) { @@ -266,9 +291,15 @@ class Dxcc { } $prefix = $matches[1][0]; } else { # Must be a Prefix! - if (preg_match('/\d$/', $c)) { # ends in number -> good prefix + # Check if $c looks like a country prefix + # Pattern: starts with digit followed by letters (6YA, 6Y) OR has digit in it + if (preg_match('/^\d[A-Z]+$/', $c)) { # Starts with digit, has letters after (6YA, 6Y, etc.) + $prefix = $c; # Already a valid prefix + } elseif (preg_match('/\d$/', $c)) { # ends in number -> good prefix $prefix = $c; - } else { # Add Zero at the end + } elseif (preg_match('/\d/', $c)) { # contains digit but doesn't end with one + $prefix = $c . "0"; # Add zero at end + } else { # No digit, add zero $prefix = $c . "0"; } } @@ -278,7 +309,7 @@ class Dxcc { # $a contains the prefix we want if (preg_match('/\d$/', $a)) { # ends in number -> good prefix $prefix = $a; - } else { # add zero if no number + } else { $prefix = $a . "0"; } }