From 6f2e7a9dd2c408737af6a1f1068b88f74c2d18ff Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Fri, 22 Nov 2024 09:54:30 +0100 Subject: [PATCH] Reworked page. Added azimuth chart with filters --- application/controllers/Statistics.php | 20 ++- application/models/Stats.php | 53 +++++++ .../views/statistics/antennaanalytics.php | 150 ++++++++++++++---- assets/js/sections/antennastats.js | 77 ++++++++- 4 files changed, 263 insertions(+), 37 deletions(-) diff --git a/application/controllers/Statistics.php b/application/controllers/Statistics.php index 5a1014015..bc17d92c7 100644 --- a/application/controllers/Statistics.php +++ b/application/controllers/Statistics.php @@ -239,13 +239,18 @@ class Statistics extends CI_Controller { public function antennaanalytics() { $this->load->model('stats'); + $this->load->model('logbookadvanced_model'); + $this->load->model('bands'); $data = array(); $data['azelarray'] = $this->stats->azeldata(); $data['satellites'] = $this->stats->get_sats(); - + $data['bands'] = $this->bands->get_worked_bands(); + $data['modes'] = $this->logbookadvanced_model->get_modes(); + $data['sats'] = $this->bands->get_worked_sats(); + $data['orbits'] = $this->bands->get_worked_orbits(); $footerData = []; $footerData['scripts'] = [ @@ -258,4 +263,17 @@ class Statistics extends CI_Controller { $this->load->view('statistics/antennaanalytics', $data); $this->load->view('interface_assets/footer', $footerData); } + + public function get_azimuth_data() { + $band = xss_clean($this->input->post('band')); + $mode = xss_clean($this->input->post('mode')); + $sat = xss_clean($this->input->post('sat')); + $orbit = xss_clean($this->input->post('orbit')); + + $this->load->model('stats'); + $azimutharray = $this->stats->azimuthdata($band, $mode, $sat, $orbit); + + header('Content-Type: application/json'); + echo json_encode($azimutharray); + } } diff --git a/application/models/Stats.php b/application/models/Stats.php index 45cf65e66..ce9ccbade 100644 --- a/application/models/Stats.php +++ b/application/models/Stats.php @@ -703,6 +703,59 @@ $result = $this->db->query($sql); return $result->result(); } + + function azimuthdata($band, $mode, $sat, $orbit) { + $conditions = []; + $binding = []; + + $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 ($band !== 'All') { + if($band != "SAT") { + $conditions[] = "COL_BAND = ? and COL_PROP_MODE != 'SAT'"; + $binding[] = trim($band); + } else { + $conditions[] = "COL_PROP_MODE = 'SAT'"; + if ($sat !== 'All') { + $conditions[] = "COL_SAT_NAME = ?"; + $binding[] = trim($sat); + } + } + } + + if ($mode !== 'All') { + $conditions[] = "(COL_MODE = ? or COL_SUBMODE = ?)"; + $binding[] = $mode; + $binding[] = $mode; + } + + if ($orbit !== 'All' && $orbit !== '') { + $conditions[] = "orbit = ?"; + $binding[] = $orbit; + } + + $where = trim(implode(" AND ", $conditions)); + if ($where != "") { + $where = "AND $where"; + } + + $sql = "SELECT count(*) qsos, round(COL_ANT_AZ) azimuth + FROM logbook + where station_id in (" . implode(',',$logbooks_locations_array) . ") + and coalesce(col_ant_az, '') <> '' + $where + group by round(col_ant_az)"; + + $result = $this->db->query($sql, $binding); + return $result->result(); + } } ?> diff --git a/application/views/statistics/antennaanalytics.php b/application/views/statistics/antennaanalytics.php index 29c4fc99a..a9143459a 100644 --- a/application/views/statistics/antennaanalytics.php +++ b/application/views/statistics/antennaanalytics.php @@ -5,44 +5,124 @@ echo json_encode($azelarray); ?>;
-
-
-
- +
+

+
+
+
-
-
- - +
+

+ + +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
- - - - '; - echo ''; - echo ''.__("Elevation").''; - echo ''.__("# QSOs").''; - echo ' - - '; - foreach ($azelarray as $qso) { - echo ''; - echo '' . $qso->elevation . ''; - echo '' . $qso->qsos . ''; - echo ''; - } - echo ''; - } +
+ +
+
- ?> - -
+ + +
+ +

+
+
+ +
+ +
+ +
+ +
+
+
+
+ + '; + echo ''; + echo ''.__("Elevation").''; + echo ''.__("# QSOs").''; + echo ' + + '; + foreach ($azelarray as $qso) { + echo ''; + echo '' . $qso->elevation . ''; + echo '' . $qso->qsos . ''; + echo ''; + } + echo ''; + } + + ?> + +
diff --git a/assets/js/sections/antennastats.js b/assets/js/sections/antennastats.js index 6d8815e92..88451a1f4 100644 --- a/assets/js/sections/antennastats.js +++ b/assets/js/sections/antennastats.js @@ -1,4 +1,79 @@ -makeChart(); +//makeChart(); + +function plot_sat() { + alert ('Yeah right'); +} + +function plot_azimuth() { + $.ajax({ + url: base_url+'index.php/statistics/get_azimuth_data', + type: 'post', + data: {'band': $('#band').val(), + 'mode': $('#mode').val(), + 'sat': $('#sat').val(), + 'orbit': $('#orbit').val() + }, + success: function(tmp) { + var dataQso = []; + var labels = []; + $.each(tmp, function () { + // labels.push('Azimuth ' + this.azimuth + '°'); + labels.push(this.azimuth); + dataQso.push(this.qsos); + }); + + // using this to change color of legend and label according to background color + var color = ifDarkModeThemeReturn('white', 'grey'); + var ctx = document.getElementById("azimuthchart").getContext('2d'); + var myChart = new Chart(ctx, { + type: 'radar', + data: { + labels: labels, + datasets: [{ + label: '# QSOs', + data: dataQso, + backgroundColor: 'rgba(54, 162, 235, 1)', + borderColor: 'rgba(54, 162, 235, 1)', + borderWidth: 2, + color: color + }] + }, + options: { + plugins: { + legend: { + labels: { + color: color + } + } + }, + scales: { + r: { // Radial scale (angle and radius) + // startAngle: -Math.PI / 2, // Start at the top (default is 0, which starts at the right) + pointLabels: { + callback: (label, index) => { + // Show labels only for every 5 degrees + return label % 10 === 0 ? `${label}°` : ''; + }, + color: color + }, + grid: { + circular: true, // Show circular grid lines + color: color + } + } + } + }, + }); + + // 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"); + } + } + }); +} function makeChart() { var labels = [];