diff --git a/application/controllers/Statistics.php b/application/controllers/Statistics.php index 802d1123..4e3a33ec 100644 --- a/application/controllers/Statistics.php +++ b/application/controllers/Statistics.php @@ -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); + } } diff --git a/application/models/Stats.php b/application/models/Stats.php index f839876c..d137aa83 100644 --- a/application/models/Stats.php +++ b/application/models/Stats.php @@ -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; + } } ?> \ No newline at end of file diff --git a/application/views/statistics/index.php b/application/views/statistics/index.php index fb3124fd..9498d9d8 100644 --- a/application/views/statistics/index.php +++ b/application/views/statistics/index.php @@ -16,40 +16,73 @@
-
-
-
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+ +
+
+
+ + + + + + + + + +
#Satellite# of QSO's worked
- -
-
-
- - - - - - - - - -
#Satellite# of QSO's worked
-
-
-
diff --git a/application/views/statistics/qsotable.php b/application/views/statistics/qsotable.php new file mode 100644 index 00000000..049e002c --- /dev/null +++ b/application/views/statistics/qsotable.php @@ -0,0 +1,32 @@ + + + '; + echo ''; + foreach($bands as $band) { + echo ''; + } + echo ''; + echo ' + + '; + foreach ($qsoarray as $mode => $value) { + echo ' + '; + foreach ($value as $key => $val) { + echo ''; + } + echo ''; + echo ''; + } + echo ''; + + $grandtotal = 0; + foreach ($bandtotal as $band => $value) { + echo ''; + $grandtotal += $value; + } + echo ''; + echo '
' . $band . 'Total
'. $mode .'' . $val . '' . $modetotal[$mode] . '
Total' . $value . '' . $grandtotal . '
'; +} diff --git a/application/views/statistics/uniquetable.php b/application/views/statistics/uniquetable.php new file mode 100644 index 00000000..93dc84aa --- /dev/null +++ b/application/views/statistics/uniquetable.php @@ -0,0 +1,30 @@ + + + '; + echo ''; + foreach($bands as $band) { + echo ''; + } + echo ''; + echo ' + + '; + foreach ($qsoarray as $mode => $value) { + echo ' + '; + foreach ($value as $key => $val) { + echo ''; + } + echo ''; + echo ''; + } + echo ''; + + foreach($bands as $band) { + echo ''; + } + echo ''; + echo '
' . $band . 'Total
'. $mode .'' . $val . '' . $modeunique[$mode] . '
Total' . $bandunique[$band] . '' . $total->calls . '
'; +} \ No newline at end of file diff --git a/assets/js/sections/statistics.js b/assets/js/sections/statistics.js index a8f12908..b3612dbc 100644 --- a/assets/js/sections/statistics.js +++ b/assets/js/sections/statistics.js @@ -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,