From 8b38d28122e1961675b8c5a67d0b94ed37adffbc Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 9 Feb 2023 01:05:36 +0100 Subject: [PATCH 1/3] Add basis continent statistics --- application/controllers/Continents.php | 48 ++++++ application/models/Logbook_model.php | 22 +++ application/views/continents/index.php | 38 +++++ application/views/interface_assets/footer.php | 6 + application/views/interface_assets/header.php | 2 + assets/js/sections/continents.js | 137 ++++++++++++++++++ 6 files changed, 253 insertions(+) create mode 100644 application/controllers/Continents.php create mode 100644 application/views/continents/index.php create mode 100644 assets/js/sections/continents.js diff --git a/application/controllers/Continents.php b/application/controllers/Continents.php new file mode 100644 index 000000000..a3f48ff8d --- /dev/null +++ b/application/controllers/Continents.php @@ -0,0 +1,48 @@ +load->model('user_model'); + $this->load->model('bands'); + if(!$this->user_model->authorize($this->config->item('auth_mode'))) { + if($this->user_model->validate_session()) { + $this->user_model->clear_session(); + show_error('Access denied

Click here to log in as another user', 403); + } else { + redirect('user/login'); + } + } + // Render User Interface + + // Set Page Title + $data['page_title'] = "Continents"; + + // Load Views + $this->load->view('interface_assets/header', $data); + $this->load->view('continents/index'); + $this->load->view('interface_assets/footer'); + } + + + public function get_continents() { + $this->load->model('logbook_model'); + + $continentsstats = array(); + + $total_continents = $this->logbook_model->total_continents(); + $i = 0; + + if ($total_continents) { + foreach($total_continents->result() as $qso_numbers) { + $continentsstats[$i]['cont'] = $qso_numbers->COL_CONT; + $continentsstats[$i++]['count'] = $qso_numbers->count; + } + } + + header('Content-Type: application/json'); + echo json_encode($continentsstats); + } + +} diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 1ca2f4da3..6a94d7719 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -1630,6 +1630,28 @@ function total_sat() { return $query; } + /* Return total number of QSOs per continent */ + function total_continents() { + + $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; + } + + $this->db->select('COL_CONT, COUNT( * ) as count', FALSE); + $this->db->where_in('station_id', $logbooks_locations_array); + $this->db->where('COL_CONT is not null'); + $this->db->where('COL_CONT !=', ''); + $this->db->order_by('count DESC'); + $this->db->group_by('COL_CONT'); + $query = $this->db->get($this->config->item('table_name')); + + return $query; + } + /* Return total number of CW QSOs */ function total_cw() { diff --git a/application/views/continents/index.php b/application/views/continents/index.php new file mode 100644 index 000000000..da349ee2d --- /dev/null +++ b/application/views/continents/index.php @@ -0,0 +1,38 @@ + +

+ +

+ +

+ +
+ + +
+ +
+
+
+ + + + + + + + + +
#Continent# of QSO's worked
+
+
+
diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 68b731e57..c66bc8ada 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -64,6 +64,12 @@ function load_was_map() { +uri->segment(1) == "continents") { ?> + + + + + uri->segment(1) == "adif" || $this->uri->segment(1) == "qrz") { ?> diff --git a/application/views/interface_assets/header.php b/application/views/interface_assets/header.php index 03ee041ab..4cb69d2d7 100644 --- a/application/views/interface_assets/header.php +++ b/application/views/interface_assets/header.php @@ -110,6 +110,8 @@ Timeplotter Custom Maps + + Continents diff --git a/assets/js/sections/continents.js b/assets/js/sections/continents.js new file mode 100644 index 000000000..e58a2422d --- /dev/null +++ b/assets/js/sections/continents.js @@ -0,0 +1,137 @@ +totalContinentQsos(); + +// Needed for continentstable header fix, will be squished without +$("a[href='#continents']").on('shown.bs.tab', function(e) { + $(".continentstable").DataTable().columns.adjust(); +}); + +function totalContinentQsos() { + // using this to change color of legend and label according to background color + var color = ifDarkModeThemeReturn('white', 'grey'); + + $.ajax({ + url: base_url+'index.php/continents/get_continents', + type: 'post', + success: function (data) { + if (data.length > 0) { + $('.tabs').removeAttr('hidden'); + + var labels = []; + var dataQso = []; + var totalQso = Number(0); + + var $myTable = $('.continentstable'); + var i = 1; + + // building the rows in the table + var rowElements = data.map(function (row) { + + var $row = $(''); + + var $iterator = $('').html(i++); + var $type = $('').html(row.cont); + var $content = $('').html(row.count); + + $row.append($iterator, $type, $content); + + return $row; + }); + + // finally inserting the rows + $myTable.append(rowElements); + + $.each(data, function () { + labels.push(this.cont); + dataQso.push(this.count); + totalQso = Number(totalQso) + Number(this.count); + }); + + const COLORS = ["#3366cc", "#dc3912", "#ff9900", "#109618", "#990099", "#0099c6", "#dd4477", "#66aa00", "#b82e2e", "#316395", "#994499"] + var ctx = document.getElementById("continentChart").getContext('2d'); + var myChart = new Chart(ctx, { + plugins: [ChartPieChartOutlabels], + type: 'doughnut', + data: { + labels: labels, + datasets: [{ + borderColor: 'rgba(54, 162, 235, 1)', + label: 'Number of QSO\'s worked', + data: dataQso, + backgroundColor: ["#3366cc", "#dc3912", "#ff9900", "#109618", "#990099", "#0099c6", "#dd4477", "#66aa00", "#b82e2e", "#316395", "#994499"], + borderWidth: 1, + labels: labels, + }] + }, + + options: { + layout: { + padding: 100 + }, + title: { + fontColor: color, + fullSize: true, + }, + responsive: false, + maintainAspectRatio: true, + plugins: { + legend: { + display: false, + labels: { + boxWidth: 15, + color: color, + font: { + size: 14, + } + }, + position: 'right', + align: "middle" + }, + outlabels: { + display: function(context) { // Hide labels with low percentage + return ((context.dataset.data[context.dataIndex] / totalQso * 100) > 1) + }, + backgroundColor: COLORS, + borderColor: COLORS, + borderRadius: 2, // Border radius of Label + borderWidth: 2, // Thickness of border + color: 'white', + stretch: 10, + padding: 0, + font: { + resizable: true, + minSize: 12, + maxSize: 25, + family: Chart.defaults.font.family, + size: Chart.defaults.font.size, + style: Chart.defaults.font.style, + lineHeight: Chart.defaults.font.lineHeight, + }, + zoomOutPercentage: 100, + textAlign: 'start', + backgroundColor: COLORS, + } + } + } + }); + + // using this to change color of csv-button if dark mode is chosen + var background = $('body').css("background-color"); + + if (background != ('rgb(255, 255, 255)')) { + $(".buttons-csv").css("color", "white"); + } + + $('.continentstable').DataTable({ + responsive: false, + ordering: false, + "scrollY": "330px", + "scrollX": true, + "ScrollCollapse": true, + "paging": false, + bFilter: false, + bInfo: false, + }); + } + } + }); +} From 36de0301518c862bc0aa7d67f8f98077681d2a78 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Thu, 9 Feb 2023 12:35:30 +0100 Subject: [PATCH 2/3] [Continents] Added band and mode filter --- application/controllers/Continents.php | 13 +++- application/models/Logbook_model.php | 19 +++++- application/views/continents/index.php | 94 +++++++++++++++++--------- assets/js/sections/continents.js | 67 ++++++++++++------ 4 files changed, 138 insertions(+), 55 deletions(-) diff --git a/application/controllers/Continents.php b/application/controllers/Continents.php index a3f48ff8d..5858652d1 100644 --- a/application/controllers/Continents.php +++ b/application/controllers/Continents.php @@ -6,6 +6,11 @@ public function index() { $this->load->model('user_model'); $this->load->model('bands'); + $this->load->model('logbookadvanced_model'); + + $data['bands'] = $this->bands->get_worked_bands(); + $data['modes'] = $this->logbookadvanced_model->get_modes(); + if(!$this->user_model->authorize($this->config->item('auth_mode'))) { if($this->user_model->validate_session()) { $this->user_model->clear_session(); @@ -27,11 +32,17 @@ public function index() public function get_continents() { + + $searchCriteria = array( + 'mode' => xss_clean($this->input->post('mode')), + 'band' => xss_clean($this->input->post('band')), + ); + $this->load->model('logbook_model'); $continentsstats = array(); - $total_continents = $this->logbook_model->total_continents(); + $total_continents = $this->logbook_model->total_continents($searchCriteria); $i = 0; if ($total_continents) { diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 6a94d7719..5dbe5e8e4 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -1631,7 +1631,7 @@ function total_sat() { } /* Return total number of QSOs per continent */ - function total_continents() { + function total_continents($searchCriteria) { $CI =& get_instance(); $CI->load->model('logbooks_model'); @@ -1645,6 +1645,23 @@ function total_continents() { $this->db->where_in('station_id', $logbooks_locations_array); $this->db->where('COL_CONT is not null'); $this->db->where('COL_CONT !=', ''); + + if ($searchCriteria['mode'] !== '') { + $this->db->group_start(); + $this->db->where('COL_MODE', $searchCriteria['mode']); + $this->db->or_where('COL_SUBMODE', $searchCriteria['mode']); + $this->db->group_end(); + } + + if ($searchCriteria['band'] !== '') { + if($searchCriteria['band'] != "SAT") { + $this->db->where('COL_BAND', $searchCriteria['band']); + $this->db->where('COL_PROP_MODE != "SAT"'); + } else { + $this->db->where('COL_PROP_MODE', 'SAT'); + } + } + $this->db->order_by('count DESC'); $this->db->group_by('COL_CONT'); $query = $this->db->get($this->config->item('table_name')); diff --git a/application/views/continents/index.php b/application/views/continents/index.php index da349ee2d..a03b8d3f6 100644 --- a/application/views/continents/index.php +++ b/application/views/continents/index.php @@ -1,38 +1,70 @@
-

- -

+

+ +

-
- +
+ -
+
-
-
-
- - - - - - - - - -
#Continent# of QSO's worked
-
-
-
+
+
+
" method="post"> +
+ +
+ + +
+
+ + +
+
+
+ + +
+
+
+
+
+
+ + + + + + + + + + +
#Continent# of QSO's worked
+
+
+
\ No newline at end of file diff --git a/assets/js/sections/continents.js b/assets/js/sections/continents.js index e58a2422d..0b53400ec 100644 --- a/assets/js/sections/continents.js +++ b/assets/js/sections/continents.js @@ -1,19 +1,49 @@ -totalContinentQsos(); +$(document).ready(function () { + // Needed for continentstable header fix, will be squished without + $("a[href='#continents']").on('shown.bs.tab', function(e) { + $(".continentstable").DataTable().columns.adjust(); + }); + + $('#searchForm').submit(function (e) { + $('#searchButton').prop("disabled", true); + + $.ajax({ + url: this.action, + type: 'post', + data: { + mode: this.mode.value, + band: this.band.value, + }, + dataType: 'json', + success: function (data) { + $('#searchButton').prop("disabled", false); + totalContinentQsos(data); + }, + error: function (data) { + $('#searchButton').prop("disabled", false); + BootstrapDialog.alert({ + title: 'ERROR', + message: 'An error ocurred while making the request', + type: BootstrapDialog.TYPE_DANGER, + closable: false, + draggable: false, + callback: function (result) { + } + }); + }, + }); + return false; + }); -// Needed for continentstable header fix, will be squished without -$("a[href='#continents']").on('shown.bs.tab', function(e) { - $(".continentstable").DataTable().columns.adjust(); + $('#searchForm').submit(); }); -function totalContinentQsos() { +function totalContinentQsos(data) { // using this to change color of legend and label according to background color var color = ifDarkModeThemeReturn('white', 'grey'); - $.ajax({ - url: base_url+'index.php/continents/get_continents', - type: 'post', - success: function (data) { if (data.length > 0) { + $('.continentstable > tbody').empty(); $('.tabs').removeAttr('hidden'); var labels = []; @@ -47,6 +77,12 @@ function totalContinentQsos() { }); const COLORS = ["#3366cc", "#dc3912", "#ff9900", "#109618", "#990099", "#0099c6", "#dd4477", "#66aa00", "#b82e2e", "#316395", "#994499"] + + let chartStatus = Chart.getChart("continentChart"); // id + if (chartStatus != undefined) { + chartStatus.destroy(); + } + var ctx = document.getElementById("continentChart").getContext('2d'); var myChart = new Chart(ctx, { plugins: [ChartPieChartOutlabels], @@ -120,18 +156,5 @@ function totalContinentQsos() { if (background != ('rgb(255, 255, 255)')) { $(".buttons-csv").css("color", "white"); } - - $('.continentstable').DataTable({ - responsive: false, - ordering: false, - "scrollY": "330px", - "scrollX": true, - "ScrollCollapse": true, - "paging": false, - bFilter: false, - bInfo: false, - }); } - } - }); } From 066ed107ede7c88d01e35aab555b64274345ad52 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Thu, 9 Feb 2023 12:44:51 +0100 Subject: [PATCH 3/3] [Continents] Removed filter for labels with low percentage --- assets/js/sections/continents.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/assets/js/sections/continents.js b/assets/js/sections/continents.js index 0b53400ec..b0acfd95e 100644 --- a/assets/js/sections/continents.js +++ b/assets/js/sections/continents.js @@ -123,9 +123,6 @@ function totalContinentQsos(data) { align: "middle" }, outlabels: { - display: function(context) { // Hide labels with low percentage - return ((context.dataset.data[context.dataIndex] / totalQso * 100) > 1) - }, backgroundColor: COLORS, borderColor: COLORS, borderRadius: 2, // Border radius of Label