[Statistics] Raw QSO data and unique callsigns

This commit is contained in:
Andreas 2022-09-25 20:39:55 +02:00
parent df6622084e
commit aa17f4f438
6 changed files with 438 additions and 34 deletions

View File

@ -146,4 +146,31 @@ class Statistics extends CI_Controller {
header('Content-Type: application/json');
echo json_encode($satstats);
}
public function get_unique_callsigns() {
$this->load->model('stats');
$result = $this->stats->unique_callsigns();
$total_qsos['qsoarray'] = $result['qsoView'];
$total_qsos['bandunique'] = $result['bandunique'];
$total_qsos['modeunique'] = $result['modeunique'];
$total_qsos['total'] = $result['total'];
$total_qsos['bands'] = $this->stats->get_bands();
$this->load->view('statistics/uniquetable', $total_qsos);
}
public function get_total_qsos() {
$this->load->model('stats');
$totalqsos = array();
$result = $this->stats->total_qsos();
$total_qsos['qsoarray'] = $result['qsoView'];
$total_qsos['bandtotal'] = $result['bandtotal'];
$total_qsos['modetotal'] = $result['modetotal'];
$total_qsos['bands'] = $this->stats->get_bands();
$this->load->view('statistics/qsotable', $total_qsos);
}
}

View File

@ -70,6 +70,242 @@
return $this->db->get($this->config->item('table_name'));
}
function unique_callsigns() {
$qsoView = array();
$bands = $this->get_bands();
$modes = $this->get_modes();
$bandunique = $this->getUniqueCallsignsBands();
$modeunique = $this->getUniqueCallsignsModes();
// Generating the band/mode table
foreach ($bands as $band) {
$bandtotal[$band] = 0;
foreach ($modes as $mode) {
$qsoView [$mode][$band] = '-';
}
}
foreach ($bandunique as $band) {
$bandcalls[$band->band] = $band->calls;
}
foreach ($modeunique as $mode) {
if ($mode->col_submode == null) {
$modecalls[$mode->col_mode] = $mode->calls;
} else {
$modecalls[$mode->col_submode] = $mode->calls;
}
}
// Populating array with worked
$workedQso = $this->getUniqueCallsigns();
foreach ($workedQso as $line) {
if ($line->col_submode == null) {
$qsoView [$line->col_mode] [$line->band] = $line->calls;
} else {
$qsoView [$line->col_submode] [$line->band] = $line->calls;
}
}
$result['qsoView'] = $qsoView;
$result['bandunique'] = $bandcalls;
$result['modeunique'] = $modecalls;
$result['total'] = $this->getUniqueCallsignsTotal();
return $result;
}
function getUniqueCallsigns() {
$CI =& get_instance();
$CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
if (!$logbooks_locations_array) {
return null;
}
$bands = array();
$this->db->select('count(distinct col_call) as calls, col_band as band, col_mode, col_submode', FALSE);
$this->db->where_in('station_id', $logbooks_locations_array);
$this->db->group_by('col_band, col_mode, col_submode');
$query = $this->db->get($this->config->item('table_name'));
return $query->result();
}
function getUniqueCallsignsModes() {
$CI =& get_instance();
$CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
if (!$logbooks_locations_array) {
return null;
}
$bands = array();
$this->db->select('count(distinct col_call) as calls, col_mode, col_submode', FALSE);
$this->db->where_in('station_id', $logbooks_locations_array);
$this->db->group_by('col_mode, col_submode');
$query = $this->db->get($this->config->item('table_name'));
return $query->result();
}
function getUniqueCallsignsBands() {
$CI =& get_instance();
$CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
if (!$logbooks_locations_array) {
return null;
}
$bands = array();
$this->db->select('count(distinct col_call) as calls, col_band as band', FALSE);
$this->db->where_in('station_id', $logbooks_locations_array);
$this->db->group_by('col_band');
$query = $this->db->get($this->config->item('table_name'));
return $query->result();
}
function getUniqueCallsignsTotal() {
$CI =& get_instance();
$CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
if (!$logbooks_locations_array) {
return null;
}
$bands = array();
$this->db->select('count(distinct col_call) as calls', FALSE);
$this->db->where_in('station_id', $logbooks_locations_array);
$query = $this->db->get($this->config->item('table_name'));
return $query->row();
}
function total_qsos() {
$qsoView = array();
$bands = $this->get_bands();
$modes = $this->get_modes();
$bandtotal = array();
$modetotal = array();
// Generating the band/mode table
foreach ($bands as $band) {
$bandtotal[$band] = 0;
foreach ($modes as $mode) {
$qsoView [$mode][$band] = '-';
$modetotal[$mode] = 0;
}
}
// Populating array with worked
$workedQso = $this->modeBandQso();
foreach ($workedQso as $line) {
if ($line->col_submode == null) {
$qsoView [$line->col_mode] [$line->band] = $line->count;
$modetotal[$line->col_mode] += $line->count;
} else {
$qsoView [$line->col_submode] [$line->band] = $line->count;
$modetotal[$line->col_submode] += $line->count;
}
$bandtotal[$line->band] += $line->count;
}
$result['qsoView'] = $qsoView;
$result['bandtotal'] = $bandtotal;
$result['modetotal'] = $modetotal;
return $result;
}
function modeBandQso() {
$CI =& get_instance();
$CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
if (!$logbooks_locations_array) {
return null;
}
$bands = array();
$this->db->select('count(*) as count, col_band as band, col_mode, col_submode', FALSE);
$this->db->where_in('station_id', $logbooks_locations_array);
$this->db->group_by('col_band, col_mode, col_submode');
$query = $this->db->get($this->config->item('table_name'));
return $query->result();
}
function get_bands() {
$CI =& get_instance();
$CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
if (!$logbooks_locations_array) {
return null;
}
$bands = array();
$this->db->select('distinct col_band+0 as bandsort, col_band as band', FALSE);
$this->db->where_in('station_id', $logbooks_locations_array);
$this->db->order_by('bandsort', 'desc');
$query = $this->db->get($this->config->item('table_name'));
foreach($query->result() as $band){
array_push($bands, $band->band);
}
return $bands;
}
function get_modes() {
$CI =& get_instance();
$CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
if (!$logbooks_locations_array) {
return null;
}
$modes = array();
$this->db->select('distinct col_mode, col_submode', FALSE);
$this->db->where_in('station_id', $logbooks_locations_array);
$this->db->order_by('col_mode, col_submode', 'ASC');
$query = $this->db->get($this->config->item('table_name'));
foreach($query->result() as $mode){
if ($mode->col_submode == null) {
array_push($modes, $mode->col_mode);
} else {
array_push($modes, $mode->col_submode);
}
}
return $modes;
}
}
?>

View File

@ -16,40 +16,73 @@
<br>
<div hidden class="tabs">
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">General</a>
</li>
<li class="nav-item">
<a class="nav-link" id="satellite-tab" data-toggle="tab" href="#satellite" role="tab" aria-controls="satellite" aria-selected="false">Satellites</a>
</li>
</ul>
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">General</a>
</li>
<li class="nav-item">
<a class="nav-link" id="satellite-tab" data-toggle="tab" href="#satellite" role="tab" aria-controls="satellite" aria-selected="false">Satellites</a>
</li>
</ul>
</div>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
<div class="years">
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
<br />
<ul class="nav nav-pills" id="myTab2" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="years-tab" data-toggle="tab" href="#yearstab" role="tab" aria-controls="yearstab" aria-selected="true">Years</a>
</li>
<li class="nav-item">
<a class="nav-link" id="mode-tab" data-toggle="tab" href="#modetab" role="tab" aria-controls="modetab" aria-selected="false">Mode</a>
</li>
<li class="nav-item">
<a class="nav-link" id="band-tab" data-toggle="tab" href="#bandtab" role="tab" aria-controls="bandtab" aria-selected="false">Bands</a>
</li>
<li class="nav-item">
<a class="nav-link" id="qso-tab" data-toggle="tab" href="#qsotab" role="tab" aria-controls="bandtab" aria-selected="false">QSOs</a>
</li>
<li class="nav-item">
<a class="nav-link" id="unique-tab" data-toggle="tab" href="#uniquetab" role="tab" aria-controls="uniquetab" aria-selected="false">Unique callsigns</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane fade show active" id="yearstab" role="tabpanel" aria-labelledby="years-tab">
<div class="years">
</div>
</div>
<div class="tab-pane fade" id="modetab" role="tabpanel" aria-labelledby="mode-tab">
<div class="mode">
</div>
</div>
<div class="tab-pane fade" id="bandtab" role="tabpanel" aria-labelledby="band-tab">
<div class="band">
</div>
</div>
<div class="tab-pane fade" id="qsotab" role="tabpanel" aria-labelledby="qso-tab">
<div class="qsos">
</div>
</div>
<div class="tab-pane fade" id="uniquetab" role="tabpanel" aria-labelledby="unique-tab">
<div class="unique">
</div>
</div>
</div>
</div>
<div class="mode">
</div>
<div class="band">
<div class="tab-pane fade" id="satellite" role="tabpanel" aria-labelledby="satellite-tab">
<br/>
<div style="display: flex;" id="satContainer"><div style="flex: 1;"><canvas id="satChart" width="500" height="500"></canvas></div><div style="flex: 1;" id="satTable">
<table style="width:100%" class="sattable table table-sm table-bordered table-hover table-striped table-condensed text-center"><thead>
<tr>
<td>#</td>
<td>Satellite</td>
<td># of QSO's worked</td>
</tr>
</thead>
<tbody></tbody>
</table></div></div>
</div>
</div>
<div class="tab-pane fade" id="satellite" role="tabpanel" aria-labelledby="satellite-tab">
<br/>
<div style="display: flex;" id="satContainer"><div style="flex: 1;"><canvas id="satChart" width="500" height="500"></canvas></div><div style="flex: 1;" id="satTable">
<table style="width:100%" class="sattable table table-sm table-bordered table-hover table-striped table-condensed text-center"><thead>
<tr>
<td>#</td>
<td>Satellite</td>
<td># of QSO's worked</td>
</tr>
</thead>
<tbody></tbody>
</table></div></div>
</div>
</div>
</div>

View File

@ -0,0 +1,32 @@
<?php
if ($qsoarray) {
echo '<br />
<table style="width:100%" class="qsotable table-sm table table-bordered table-hover table-striped table-condensed text-center">
<thead>';
echo '<tr><th></th>';
foreach($bands as $band) {
echo '<th>' . $band . '</th>';
}
echo '<th>Total</th>';
echo '</tr>
</thead>
<tbody>';
foreach ($qsoarray as $mode => $value) {
echo '<tr>
<th>'. $mode .'</th>';
foreach ($value as $key => $val) {
echo '<td>' . $val . '</td>';
}
echo '<th>' . $modetotal[$mode] . '</th>';
echo '</tr>';
}
echo '</tbody><tfoot><tr><th>Total</th>';
$grandtotal = 0;
foreach ($bandtotal as $band => $value) {
echo '<th>' . $value . '</th>';
$grandtotal += $value;
}
echo '<th>' . $grandtotal . '</th>';
echo '</tr></tfoot></table>';
}

View File

@ -0,0 +1,30 @@
<?php
if ($qsoarray) {
echo '<br />
<table style="width:100%" class="uniquetable table-sm table table-bordered table-hover table-striped table-condensed text-center">
<thead>';
echo '<tr><th></th>';
foreach($bands as $band) {
echo '<th>' . $band . '</th>';
}
echo '<th>Total</th>';
echo '</tr>
</thead>
<tbody>';
foreach ($qsoarray as $mode => $value) {
echo '<tr>
<th>'. $mode .'</th>';
foreach ($value as $key => $val) {
echo '<td>' . $val . '</td>';
}
echo '<th>' . $modeunique[$mode] . '</th>';
echo '</tr>';
}
echo '</tbody><tfoot><tr><th>Total</th>';
foreach($bands as $band) {
echo '<th>' . $bandunique[$band] . '</th>';
}
echo '<th>' . $total->calls . '</th>';
echo '</tr></tfoot></table>';
}

View File

@ -1,13 +1,59 @@
totalSatQsos();
totalQsosPerYear();
totalModeQsos();
totalBandQsos();
// Needed for sattable header fix, will be squished without
$("a[href='#satellite']").on('shown.bs.tab', function(e) {
$(".sattable").DataTable().columns.adjust();
});
$("a[href='#bandtab']").on('shown.bs.tab', function(e) {
if (!($('.bandtable').length > 0)) {
totalBandQsos();
}
});
$("a[href='#modetab']").on('shown.bs.tab', function(e) {
if (!($('.modetable').length > 0)) {
totalModeQsos();
}
});
$("a[href='#qsotab']").on('shown.bs.tab', function(e) {
if (!($('.qsotable').length > 0)) {
totalQsos();
}
});
$("a[href='#uniquetab']").on('shown.bs.tab', function(e) {
if (!($('.uniquetable').length > 0)) {
uniqueCallsigns();
}
});
function uniqueCallsigns() {
$.ajax({
url: base_url+'index.php/statistics/get_unique_callsigns',
type: 'post',
success: function (data) {
if (data.length > 0) {
$(".unique").html(data);
}
}
});
}
function totalQsos() {
$.ajax({
url: base_url+'index.php/statistics/get_total_qsos',
type: 'post',
success: function (data) {
if (data.length > 0) {
$(".qsos").html(data);
}
}
});
}
function totalQsosPerYear() {
// using this to change color of legend and label according to background color
var color = ifDarkModeThemeReturn('white', 'grey');
@ -100,7 +146,7 @@ function totalQsosPerYear() {
$('.yeartable').DataTable({
responsive: false,
ordering: false,
"scrollY": "170px",
"scrollY": "320px",
"scrollCollapse": true,
"paging": false,
"scrollX": true,