DXCC lookup - big speed

This commit is contained in:
Andreas Kristiansen
2025-12-20 11:50:53 +01:00
parent fa801e3817
commit e952a25f1b
3 changed files with 171 additions and 62 deletions

View File

@@ -1,6 +1,8 @@
<?php
use Wavelog\Dxcc\Dxcc;
require_once APPPATH . '../src/Dxcc/Dxcc.php';
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Calltester extends CI_Controller {
@@ -17,7 +19,7 @@ class Calltester extends CI_Controller {
// Starting clock time in seconds
$start_time = microtime(true);
$callarray = $this->getQsos(null);
$this->load->model('stations');
@@ -34,6 +36,7 @@ class Calltester extends CI_Controller {
$this->load->view('interface_assets/footer', $footerData);
}
/* Uses DXCC Class. Much faster */
function doDxccCheck() {
$this->load->model('logbook_model');
$i = 0;
@@ -41,6 +44,54 @@ class Calltester extends CI_Controller {
$callarray = $this->getQsos($this->input->post('de', true));
// Starting clock time in seconds
$start_time = microtime(true);
$dxccobj = new Dxcc(null);
foreach ($callarray->result() as $call) {
$i++;
//$dxcc = $this->logbook_model->dxcc_lookup($call->col_call, $call->date);
$dxcc = $dxccobj->dxcc_lookup($call->col_call, $call->date);
$dxcc['adif'] = (isset($dxcc['adif'])) ? $dxcc['adif'] : 0;
$dxcc['entity'] = (isset($dxcc['entity'])) ? $dxcc['entity'] : 'None';
if ($call->col_dxcc != $dxcc['adif']) {
$result[] = array(
'callsign' => $call->col_call,
'qso_date' => $call->date,
'station_profile' => $call->station_profile_name,
'existing_dxcc' => $call->col_country,
'existing_adif' => $call->col_dxcc,
'result_country' => ucwords(strtolower($dxcc['entity']), "- (/"),
'result_adif' => $dxcc['adif'],
'id' => $call->col_primary_key,
);
}
}
// End clock time in seconds
$end_time = microtime(true);
// Calculate script execution time
$execution_time = ($end_time - $start_time);
$data['execution_time'] = $execution_time;
$data['calls_tested'] = $i;
$data['result'] = $result;
$this->load->view('calltester/result', $data);
}
/* Uses Logbook_model and the normal dxcc lookup, which is slow */
function doDxccCheck2() {
$this->load->model('logbook_model');
$i = 0;
$result = array();
$callarray = $this->getQsos($this->input->post('de', true));
// Starting clock time in seconds
$start_time = microtime(true);

View File

@@ -3,6 +3,7 @@ $i = 0;
echo "<p>" . __("Callsigns tested: ") . $calls_tested . "</p>";
echo "<p>" . __("Execution time: ") . round($execution_time, 2) . "s</p>";
echo "<p>" . __("Number of potential QSOs with wrong DXCC: ") . count($result) . "</p>";
// Get Date format
if($this->session->userdata('user_date_format')) {
// If Logged in and session exists
@@ -11,34 +12,37 @@ if($this->session->userdata('user_date_format')) {
// Get Default date format from /config/wavelog.php
$custom_date_format = $this->config->item('qso_date_format');
}
?>
if ($result) { ?>
<div class="table-responsive" style="max-height:70vh; overflow:auto;">
<table class="table table-sm table-striped table-bordered table-condensed mb-0">
<thead>
<table class="table table-sm table-striped table-bordered table-condensed mb-0">
<thead>
<tr>
<th>#</th>
<th><?= __("Callsign"); ?></th>
<th><?= __("QSO Date"); ?></th>
<th><?= __("Station Profile"); ?></th>
<th><?= __("Existing DXCC"); ?></th>
<th><?= __("Existing ADIF"); ?></th>
<th><?= __("Result DXCC"); ?></th>
<th><?= __("Result ADIF"); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($result as $qso): ?>
<tr>
<th>#</th>
<th><?= __("Callsign"); ?></th>
<th><?= __("QSO Date"); ?></th>
<th><?= __("Station Profile"); ?></th>
<th><?= __("Existing DXCC"); ?></th>
<th><?= __("Existing ADIF"); ?></th>
<th><?= __("Result DXCC"); ?></th>
<th><?= __("Result ADIF"); ?></th>
<td><?php echo ++$i; ?></td>
<td><?php echo '<a id="edit_qso" href="javascript:displayQso(' . $qso['id'] . ')">' . htmlspecialchars($qso['callsign']) . '</a>'; ?></td>
<td><?php echo date($custom_date_format, strtotime($qso['qso_date'])); ?></td>
<td><?php echo $qso['station_profile']; ?></td>
<td><?php echo htmlspecialchars(ucwords(strtolower($qso['existing_dxcc']), "- (/"), ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo $qso['existing_adif']; ?></td>
<td><?php echo htmlspecialchars(ucwords(strtolower($qso['result_country']), "- (/"), ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo $qso['result_adif']; ?></td>
</tr>
</thead>
<tbody>
<?php foreach ($result as $qso): ?>
<tr>
<td><?php echo ++$i; ?></td>
<td><?php echo '<a id="edit_qso" href="javascript:displayQso(' . $qso['id'] . ')">' . htmlspecialchars($qso['callsign']) . '</a>'; ?></td>
<td><?php echo date($custom_date_format, strtotime($qso['qso_date'])); ?></td>
<td><?php echo $qso['station_profile']; ?></td>
<td><?php echo htmlspecialchars(ucwords(strtolower($qso['existing_dxcc']), "- (/"), ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo $qso['existing_adif']; ?></td>
<td><?php echo htmlspecialchars(ucwords(strtolower($qso['result_country']), "- (/"), ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo $qso['result_adif']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php } ?>

View File

@@ -17,8 +17,23 @@ class Dxcc {
$CI =& get_instance();
if (array_key_exists($call, $this->dxccexceptions)) {
return $this->dxccexceptions[$call];
} else {
$exceptions = $this->dxccexceptions[$call];
// Loop through all exceptions for this call
foreach ($exceptions as $exception) {
$startDate = !empty($exception['start']) ? $exception['start'] : null;
$endDate = !empty($exception['end']) ? $exception['end'] : null;
if ($startDate == null && $endDate == null)
return $exception;
if ($date <= $endDate && $date >= $startDate)
return $exception;
if ($endDate == null && $date >= $startDate)
return $exception;
if ($date <= $endDate && $startDate == null)
return $exception;
}
}
if (preg_match('/(^KG4)[A-Z09]{3}/', $call)) { // KG4/ and KG4 5 char calls are Guantanamo Bay. If 4 or 6 char, it is USA
$call = "K";
@@ -76,10 +91,25 @@ class Dxcc {
$result = '';
if (array_key_exists(substr($call, 0, $i), $this->dxcc)) {
return $this->dxcc[substr($call, 0, $i)];
$arraykey = substr($call, 0, $i);
$dxccEntries = $this->dxcc[substr($call, 0, $i)];
// Loop through all entries for this call prefix
foreach ($dxccEntries as $dxccEntry) {
$startDate = !empty($dxccEntry['start']) ? $dxccEntry['start'] : null;
$endDate = !empty($dxccEntry['end']) ? $dxccEntry['end'] : null;
if ($startDate == null && $endDate == null)
return $dxccEntry;
if ($date < $endDate && $date >= $startDate)
return $dxccEntry;
if ($endDate == null && $date >= $startDate)
return $dxccEntry;
if ($date < $endDate && $startDate == null)
return $dxccEntry;
}
}
}
}
return array("Not Found", "Not Found");
}
@@ -223,45 +253,69 @@ class Dxcc {
/*
* Read cty.dat from AD1C
*/
function read_data($date) {
function read_data($date = null) {
$CI =& get_instance();
$dxcc_exceptions = $CI->db->select('`entity`, `adif`, `cqz`, `start`, `end`, `call`, `cont`, `long`, `lat`')
->where('(start <= ', $date)
->or_where('start is null)', NULL, false)
->where('(end >= ', $date)
->or_where('end is null)', NULL, false)
->get('dxcc_exceptions');
if ($date == null) {
$dxcc_exceptions = $CI->db->select('entity, adif, cqz, start, end, call, cont, long, lat')
->get('dxcc_exceptions');
} else {
$dxcc_exceptions = $CI->db->select('entity, adif, cqz, start, end, call, cont, long, lat')
->group_start()
->where('start <=', $date)
->or_where('start IS NULL')
->group_end()
->group_start()
->where('end >=', $date)
->or_where('end IS NULL')
->group_end()
->get('dxcc_exceptions');
}
if ($dxcc_exceptions->num_rows() > 0){
foreach ($dxcc_exceptions->result() as $dxcce) {
$this->dxccexceptions[$dxcce->call]['adif'] = $dxcce->adif;
$this->dxccexceptions[$dxcce->call]['cont'] = $dxcce->cont;
$this->dxccexceptions[$dxcce->call]['entity'] = $dxcce->entity;
$this->dxccexceptions[$dxcce->call]['cqz'] = $dxcce->cqz;
$this->dxccexceptions[$dxcce->call]['start'] = $dxcce->start;
$this->dxccexceptions[$dxcce->call]['end'] = $dxcce->end;
$this->dxccexceptions[$dxcce->call]['long'] = $dxcce->long;
$this->dxccexceptions[$dxcce->call]['lat'] = $dxcce->lat;
$this->dxccexceptions[$dxcce->call][] = [
'adif' => $dxcce->adif,
'cont' => $dxcce->cont,
'entity' => $dxcce->entity,
'cqz' => $dxcce->cqz,
'start' => $dxcce->start,
'end' => $dxcce->end,
'long' => $dxcce->long,
'lat' => $dxcce->lat
];
}
}
$dxcc_result = $CI->db->select('*')
->where('(start <= ', $date)
->or_where("start is null)", NULL, false)
->where('(end >= ', $date)
->or_where("end is null)", NULL, false)
->get('dxcc_prefixes');
if ($date == null) {
$dxcc_result = $CI->db->select('*')
->get('dxcc_prefixes');
} else {
$dxcc_result = $CI->db->select('*')
->group_start()
->where('start <=', $date)
->or_where('start IS NULL')
->group_end()
->group_start()
->where('end >=', $date)
->or_where('end IS NULL')
->group_end()
->get('dxcc_prefixes');
}
if ($dxcc_result->num_rows() > 0){
foreach ($dxcc_result->result() as $dx) {
$this->dxcc[$dx->call]['adif'] = $dx->adif;
$this->dxcc[$dx->call]['cont'] = $dx->cont;
$this->dxcc[$dx->call]['entity'] = $dx->entity;
$this->dxcc[$dx->call]['cqz'] = $dx->cqz;
$this->dxcc[$dx->call]['start'] = $dx->start;
$this->dxcc[$dx->call]['end'] = $dx->end;
$this->dxcc[$dx->call]['long'] = $dx->long;
$this->dxcc[$dx->call]['lat'] = $dx->lat;
$this->dxcc[$dx->call][] = [
'adif' => $dx->adif,
'cont' => $dx->cont,
'entity' => $dx->entity,
'cqz' => $dx->cqz,
'start' => $dx->start,
'end' => $dx->end,
'long' => $dx->long,
'lat' => $dx->lat
];
}
}