[Advanced Logbook] Rewrote DXCC checker

This commit is contained in:
Andreas Kristiansen
2025-12-23 18:15:59 +01:00
parent a6e98f151e
commit 05a4c08e87
4 changed files with 155 additions and 9 deletions

View File

@@ -1,5 +1,6 @@
<?php
use Wavelog\QSLManager\QSO;
use Wavelog\Dxcc\Dxcc;
class Logbookadvanced_model extends CI_Model {
@@ -1536,8 +1537,10 @@ class Logbookadvanced_model extends CI_Model {
return $this->check_missing_distance();
case 'checkcontinent':
return $this->check_qsos_missing_continent();
case 'checkdxcc':
case 'checkmissingdxcc':
return $this->check_missing_dxcc();
case 'checkdxcc':
return $this->check_dxcc();
case 'checkstate':
return $this->check_missing_state();
case 'checkcqzones':
@@ -1887,4 +1890,65 @@ class Logbookadvanced_model extends CI_Model {
return $query->result();
}
public function check_dxcc() {
$i = 0;
$result = array();
$callarray = $this->getQsos();
// 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;
return $data;
}
function getQsos() {
$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
where station_profile.user_id = ?';
$params[] = array($this->session->userdata('user_id'));
$sql .= ' order by station_profile.station_profile_name asc, date desc';
$query = $this->db->query($sql, $params);
return $query;
}
}

View File

@@ -1,4 +1,14 @@
<?php
// Get Date format
if($this->session->userdata('user_date_format')) {
// If Logged in and session exists
$custom_date_format = $this->session->userdata('user_date_format');
} else {
// Get Default date format from /config/wavelog.php
$custom_date_format = $this->config->item('qso_date_format');
}
switch ($type) {
case 'checkdistance':
check_missing_distance($result);
@@ -6,7 +16,7 @@ switch ($type) {
case 'checkcontinent':
check_qsos_missing_continent($result);
break;
case 'checkdxcc':
case 'checkmissingdxcc':
check_missing_dxcc($result);
break;
case 'checkcqzones':
@@ -18,6 +28,9 @@ switch ($type) {
case 'checkgrids':
check_missing_grids($result);
break;
case 'checkdxcc':
check_dxcc($result, $custom_date_format);
break;
default:
// Invalid type
break;
@@ -97,3 +110,39 @@ function check_missing_grids($result) { ?>
<?= __("Update now") ?><div class="ld ld-ring ld-spin"></div>
</button>
<?php }
function check_dxcc($result, $custom_date_format) { ?>
<h5><?= __("DXCC Check Results") ?></h5>
<?php
echo "<p>" . __("Callsigns tested: ") . $result['calls_tested'] . "</p>";
echo "<p>" . __("Execution time: ") . round($result['execution_time'], 2) . "s</p>";
echo "<p>" . __("Number of potential QSOs with wrong DXCC: ") . count($result['result']) . "</p>";
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>
<tr>
<th><?= __("Callsign"); ?></th>
<th><?= __("QSO Date"); ?></th>
<th><?= __("Station Profile"); ?></th>
<th><?= __("Existing DXCC"); ?></th>
<th><?= __("Result DXCC"); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($result['result'] as $qso): ?>
<tr>
<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 htmlspecialchars(ucwords(strtolower($qso['result_country']), "- (/"), ENT_QUOTES, 'UTF-8'); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php }
}

View File

@@ -1,6 +1,6 @@
<div class="container">
<div class="container-fluid">
<div class="row">
<div class="col-md-6">
<div class="col-md-5">
<h5><?= __("Data Repair Tools") ?>
<a href="https://github.com/wavelog/wavelog/wiki/Advanced-Logbook#database-tools-dbtools" target="_blank" rel="noopener noreferrer" class="btn btn-sm btn-info me-1 ld-ext-right">
<?= __("Wiki Help") ?></a>
@@ -85,8 +85,8 @@
<p class="mb-1 small alert-danger"><?= __("This will overwrite ALL existing DXCC information!") ?></p>
</div>
<div class="d-flex nowrap">
<button type="button" class="btn btn-sm btn-primary me-1 ld-ext-right" id="updateDxccBtn" onclick="fixMissingDxcc(true)">
<?= __("Run") ?><div class="ld ld-ring ld-spin"></div>
<button type="button" class="btn btn-sm btn-success me-1 ld-ext-right" id="checkDxccBtn" onclick="checkDxcc()">
<?= __("Check") ?><div class="ld ld-ring ld-spin"></div>
</button>
</div>
</div>
@@ -107,7 +107,7 @@
</div>
</div>
<div class="col-md-6 result"></div>
<div class="col-md-7 result"></div>
</div>

View File

@@ -1319,7 +1319,7 @@ $(document).ready(function () {
success: function (html) {
BootstrapDialog.show({
title: 'Database tools',
size: BootstrapDialog.SIZE_WIDE,
size: BootstrapDialog.SIZE_EXTRAWIDE,
cssClass: 'options',
nl2br: false,
message: html,
@@ -2059,7 +2059,7 @@ function saveOptions() {
$.ajax({
url: base_url + 'index.php/logbookadvanced/checkDb',
data: {
type: 'checkdxcc'
type: 'checkmissingdxcc'
},
type: 'POST',
success: function(response) {
@@ -2514,3 +2514,36 @@ function saveOptions() {
}
});
}
function checkDxcc() {
$('#checkDxccBtn').prop("disabled", true).addClass("running");
$('#closeButton').prop("disabled", true);
$.ajax({
url: base_url + 'index.php/logbookadvanced/checkDb',
data: {
type: 'checkdxcc'
},
type: 'POST',
success: function(response) {
$('#checkDxccBtn').prop("disabled", false).removeClass("running");
$('#closeButton').prop("disabled", false);
$('.result').html(response);
},
error: function(xhr, status, error) {
$('#checkDxccBtn').prop('disabled', false).text('<?= __("Check") ?>');
$('#closeButton').prop('disabled', false);
let errorMsg = 'Error checking DXCC information';
if (xhr.responseJSON && xhr.responseJSON.message) {
errorMsg += ': ' + xhr.responseJSON.message;
}
BootstrapDialog.alert({
title: 'Error',
message: errorMsg,
type: BootstrapDialog.TYPE_DANGER
});
}
});
}