From cc8c4ae2b80bffe675e0ccfc197db72d831d0174 Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Tue, 13 Aug 2024 10:56:50 +0200 Subject: [PATCH] This fixes activated gridsquares where only a border or corner was worked --- application/controllers/Activators.php | 3 +- application/models/Activators_model.php | 183 +++++++++++++----------- 2 files changed, 101 insertions(+), 85 deletions(-) diff --git a/application/controllers/Activators.php b/application/controllers/Activators.php index f50ce1c21..eb5667f6c 100644 --- a/application/controllers/Activators.php +++ b/application/controllers/Activators.php @@ -30,7 +30,7 @@ class Activators extends CI_Controller if ($this->input->post('mincount') != NULL) { // mincount is not set when page first loads. $mincount = $this->input->post('mincount'); } else { - $mincount = 2; + $mincount = 2; } if ($this->input->post('leogeo') != NULL) { // orbit is not set when page first loads. @@ -46,7 +46,6 @@ class Activators extends CI_Controller $data['maxactivatedgrids'] = $this->Activators_model->get_max_activated_grids(); $data['orbit'] = $orbit; $data['activators_array'] = $this->Activators_model->get_activators($band, $mincount, $orbit); - $data['activators_vucc_array'] = $this->Activators_model->get_activators_vucc($band, $orbit); $data['bandselect'] = $band; $footerData = []; diff --git a/application/models/Activators_model.php b/application/models/Activators_model.php index b863021d4..816ae9001 100644 --- a/application/models/Activators_model.php +++ b/application/models/Activators_model.php @@ -3,100 +3,117 @@ if (!defined('BASEPATH')) exit('No direct script access allowed'); class Activators_model extends CI_Model { - function get_activators($band, $mincount, $leogeo) - { - $this->load->model('logbooks_model'); - $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); - if ($mincount == '' || $mincount == 0 || !is_numeric($mincount)) { - $mincount = 2; - } + function get_activators($band, $mincount, $leogeo) { + $this->load->model('logbooks_model'); + $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); - if (!$logbooks_locations_array) { - return null; - } + if ($mincount == '' || $mincount == 0 || !is_numeric($mincount)) { + $mincount = 2; + } - $location_list = "'" . implode("','", $logbooks_locations_array) . "'"; + if (!$logbooks_locations_array) { + return null; + } - $sql = "SELECT COL_CALL as `call`, - COUNT(DISTINCT(SUBSTR(COL_GRIDSQUARE,1,4))) AS `count`, - GROUP_CONCAT(DISTINCT SUBSTR(`COL_GRIDSQUARE`,1,4) ORDER BY `COL_GRIDSQUARE` SEPARATOR ', ') AS `grids` - FROM " . $this->config->item('table_name') . " WHERE station_id in (" . $location_list . ")"; - - if ($band != 'All') { - if ($band == 'SAT') { - switch ($leogeo) { - case 'both': - $sql .= " and col_prop_mode ='" . $band . "'"; - break; - case 'leo': - $sql .= " and col_prop_mode = '" . $band . "'"; - $sql .= " and col_sat_name != 'QO-100'"; - break; - case 'geo': - $sql .= " and col_prop_mode = '" . $band . "'"; - $sql .= " and col_sat_name = 'QO-100'"; - break; - default: - $sql .= " and col_prop_mode ='" . $band . "'"; - break; - } - } else { - $sql .= " and col_prop_mode !='SAT'"; - $sql .= " and COL_BAND ='" . $band . "'"; - } - } - $sql .= " AND `COL_GRIDSQUARE` != '' GROUP BY `COL_CALL` HAVING `count` >= " . $mincount . " ORDER BY `count` DESC;"; + $location_list = "'" . implode("','", $logbooks_locations_array) . "'"; + $binding = array(); - $query = $this->db->query($sql); + $sql = "select + `call`, + COUNT(distinct(grid)) as `count`, + GROUP_CONCAT(distinct grid order by `grid` separator ', ') as `grids` + from ( + select + distinct COL_CALL as `call`, + SUBSTR(COL_GRIDSQUARE, 1, 4) grid + from + " . $this->config->item('table_name') . " + where + station_id in (" . $location_list . ") + and `COL_GRIDSQUARE` != ''"; - return $query->result(); - } + if ($band != 'All') { + $binding[] = $band; + if ($band == 'SAT') { + switch ($leogeo) { + case 'both': + $sql .= " and col_prop_mode =?"; + break; + case 'leo': + $sql .= " and col_prop_mode = ?"; + $sql .= " and col_sat_name != 'QO-100'"; + break; + case 'geo': + $sql .= " and col_prop_mode = ?"; + $sql .= " and col_sat_name = 'QO-100'"; + break; + default: + $sql .= " and col_prop_mode =?"; + break; + } + } else { + $sql .= " and col_prop_mode !='SAT'"; + $sql .= " and COL_BAND =?"; + } + } - function get_activators_vucc($band, $leogeo) - { - $this->load->model('logbooks_model'); - $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); + $sql .= " union + select distinct COL_CALL as `call`, substr(grid, 1,4) as grid + from ( + select TRIM(SUBSTRING_INDEX(SUBSTRING_INDEX(COL_VUCC_GRIDS, ',', x.x), ',',-1)) as grid, col_call from " . $this->config->item('table_name') . " + cross join ( + select 1 as x + union all + select 2 + union all + select 3 + union all + select 4) x + where x.x <= length(COL_VUCC_GRIDS)-length(replace(COL_VUCC_GRIDS, ',', ''))+ 1 + and coalesce(COL_VUCC_GRIDS, '') <> '' + and station_id in (" . $location_list . ")"; - if (!$logbooks_locations_array) { - return null; - } + if ($band != 'All') { + $binding[] = $band; + if ($band == 'SAT') { + switch ($leogeo) { + case 'both': + $sql .= " and col_prop_mode =?"; + break; + case 'leo': + $sql .= " and col_prop_mode = ?"; + $sql .= " and col_sat_name != 'QO-100'"; + break; + case 'geo': + $sql .= " and col_prop_mode = ?"; + $sql .= " and col_sat_name = 'QO-100'"; + break; + default: + $sql .= " and col_prop_mode =?"; + break; + } + } else { + $sql .= " and col_prop_mode !='SAT'"; + $sql .= " and COL_BAND =?"; + } + } - $location_list = "'" . implode("','", $logbooks_locations_array) . "'"; + $sql .= " GROUP BY 1 + ) as z + ) as x + group by `call` + having `count` >= ? + order by `count` desc"; - $sql = "SELECT DISTINCT COL_CALL AS `call`, - GROUP_CONCAT(COL_VUCC_GRIDS) AS `vucc_grids` FROM " . $this->config->item('table_name') . - " WHERE station_id in (" . $location_list . ")"; + $binding[] = $mincount; - if ($band != 'All') { - if ($band == 'SAT') { - switch ($leogeo) { - case 'both': - $sql .= " and col_prop_mode ='" . $band . "'"; - break; - case 'leo': - $sql .= " and col_prop_mode = '" . $band . "'"; - $sql .= " and col_sat_name != 'QO-100'"; - break; - case 'geo': - $sql .= " and col_prop_mode = '" . $band . "'"; - $sql .= " and col_sat_name = 'QO-100'"; - break; - default: - $sql .= " and col_prop_mode ='" . $band . "'"; - break; - } - } else { - $sql .= " and col_prop_mode !='SAT'"; - $sql .= " and COL_BAND ='" . $band . "'"; - } - } - $sql .= " AND COL_VUCC_GRIDS != '' GROUP BY COL_CALL;"; + $query = $this->db->query($sql, $binding); - $query = $this->db->query($sql); + return $query->result(); + + } - return $query->result(); - } function get_max_activated_grids() { $this->load->model('logbooks_model'); @@ -110,8 +127,8 @@ class Activators_model extends CI_Model // Get max no of activated grids of single operator $data = $this->db->query( - "SELECT COUNT(DISTINCT(SUBSTR(COL_GRIDSQUARE,1,4))) AS `count` from " . $this->config->item('table_name') . - " WHERE station_id in (" . $location_list . ") AND + "SELECT COUNT(DISTINCT(SUBSTR(COL_GRIDSQUARE,1,4))) AS `count` from " . $this->config->item('table_name') . + " WHERE station_id in (" . $location_list . ") AND `COL_GRIDSQUARE` != '' GROUP BY `COL_CALL` ORDER BY `count` DESC LIMIT 1" ); foreach ($data->result() as $row) {