Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic continent statistics #1991

Merged
merged 3 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions application/controllers/Continents.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Continents extends CI_Controller {

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();
show_error('Access denied<p>Click <a href="'.site_url('user/login').'">here</a> 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() {

$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($searchCriteria);
$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);
}

}
39 changes: 39 additions & 0 deletions application/models/Logbook_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,45 @@ function total_sat() {
return $query;
}

/* Return total number of QSOs per continent */
function total_continents($searchCriteria) {

$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 !=', '');

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'));

return $query;
}

/* Return total number of CW QSOs */
function total_cw() {

Expand Down
70 changes: 70 additions & 0 deletions application/views/continents/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<style>
#continentChart {
margin: 0 auto;
}
</style>
<div class="container statistics">

<h2>
<?php echo $page_title; ?>
</h2>

<br>
<div hidden class="tabs">
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="continents-tab" data-toggle="tab" href="#continents" role="tab"
aria-controls="continents" aria-selected="true">No of QSOs</a>
</li>
</ul>
</div>

<div class="tab-content" id="myTabContent">

<div class="tab-pane fade active show" id="continents" role="tabpanel" aria-labelledby="continents-tab">
<br />
<form id="searchForm" name="searchForm" action="<?php echo base_url()."index.php/continents/get_continents";?>" method="post">
<div class="form-row">

<div class="form-group col-lg-2">
<label class="form-label" for="band">Band</label>
<select id="band" name="band" class="form-control form-control-sm">
<option value="">All</option>
<?php foreach($bands as $band){ ?>
<option value="<?php echo htmlentities($band);?>"><?php echo htmlspecialchars($band);?> </option>
<?php } ?>
</select>
</div>
<div class="form-group col-lg-2">
<label class="form-label" for="mode">Mode</label>
<select id="mode" name="mode" class="form-control form-control-sm">
<option value="">All</option>
<?php foreach($modes as $modeId => $mode){ ?>
<option value="<?php echo htmlspecialchars($mode);?>"><?php echo htmlspecialchars($mode);?></option>
<?php } ?>
</select>
</div>
<div class="form-group col-lg-2 col-md-3 col-sm-3 col-xl-21">
<label>&nbsp;</label><br>
<button type="submit" class="btn btn-sm btn-primary" id="searchButton">Search</button>
<button type="reset" class="btn btn-sm btn-danger" id="resetButton">Reset</button>
</div>
</div>
</form>
<div style="display: flex;" id="continentContainer">
<div style="flex: 1;"><canvas id="continentChart" width="500" height="500"></canvas></div>
<div style="flex: 1;" id="continentTable">

<table style="width:100%" class="continentstable table table-sm table-bordered table-hover table-striped table-condensed text-center">
<thead>
<tr>
<th>#</th>
<th>Continent</th>
<th># of QSO's worked</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
</div>
6 changes: 6 additions & 0 deletions application/views/interface_assets/footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ function load_was_map() {
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/sections/statistics.js"></script>
<?php } ?>

<?php if ($this->uri->segment(1) == "continents") { ?>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/chart.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/chartjs-plugin-piechart-outlabels.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/sections/continents.js"></script>
<?php } ?>

<?php if ($this->uri->segment(1) == "adif" || $this->uri->segment(1) == "qrz") { ?>
<!-- Javascript used for ADIF Import and Export Areas -->
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/moment.min.js"></script>
Expand Down
2 changes: 2 additions & 0 deletions application/views/interface_assets/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@
<a class="dropdown-item" href="<?php echo site_url('timeplotter');?>" title="View time when worked"><i class="fas fa-chart-area"></i> Timeplotter</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="<?php echo site_url('map/custom');?>" title="Custom Maps of QSOs"><i class="fas fa-globe-europe"></i> Custom Maps</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="<?php echo site_url('continents');?>" title="Continents"><i class="fas fa-globe-europe"></i> Continents</a>
</div>
</li>

Expand Down
160 changes: 160 additions & 0 deletions assets/js/sections/continents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
$(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;
});

$('#searchForm').submit();
});

function totalContinentQsos(data) {
// using this to change color of legend and label according to background color
var color = ifDarkModeThemeReturn('white', 'grey');

if (data.length > 0) {
$('.continentstable > tbody').empty();
$('.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 = $('<tr></tr>');

var $iterator = $('<td></td>').html(i++);
var $type = $('<td></td>').html(row.cont);
var $content = $('<td></td>').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"]

let chartStatus = Chart.getChart("continentChart"); // <canvas> id
if (chartStatus != undefined) {
chartStatus.destroy();
}

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");
}
}
}