Implemented dynamic loading of chart and table. Band and award is now selectable.
这个提交包含在:
父节点
e80c9b8ef8
当前提交
20dc1caa27
共有 4 个文件被更改,包括 286 次插入 和 65 次删除
|
|
@ -18,39 +18,26 @@ class Accumulated extends CI_Controller {
|
||||||
|
|
||||||
$this->load->model('Accumulate_model');
|
$this->load->model('Accumulate_model');
|
||||||
|
|
||||||
if ($this->input->post('band') != NULL) { // Band is not set when page first loads.
|
|
||||||
$band = $this->input->post('band');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$band = 'All';
|
|
||||||
}
|
|
||||||
|
|
||||||
$data['accumulated_dxcc_array'] = $this->Accumulate_model->get_accumulated_dxcc($band);
|
|
||||||
$data['worked_bands'] = $this->Accumulate_model->get_worked_bands();
|
$data['worked_bands'] = $this->Accumulate_model->get_worked_bands();
|
||||||
$data['bandselect'] = $band;
|
|
||||||
|
|
||||||
$this->load->view('interface_assets/header', $data);
|
$this->load->view('interface_assets/header', $data);
|
||||||
$this->load->view('accumulate/index');
|
$this->load->view('accumulate/index');
|
||||||
$this->load->view('interface_assets/footer');
|
$this->load->view('interface_assets/footer');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function details() {
|
/*
|
||||||
$this->load->model('logbook_model');
|
* Used for ajax-call in javascript to fetch the data and insert into table and chart
|
||||||
|
*/
|
||||||
|
public function get_accumulated_data(){
|
||||||
|
//load model
|
||||||
|
$this->load->model('accumulate_model');
|
||||||
|
$band = $this->input->post('Band');
|
||||||
|
$award = $this->input->post('Award');
|
||||||
|
|
||||||
$adif = str_replace('"', "", $this->input->post("Adif"));
|
// get data
|
||||||
$country = $this->logbook_model->get_entity($adif);
|
$data = $this->accumulate_model->get_accumulated_data($band, $award);
|
||||||
$band = str_replace('"', "", $this->input->post("Band"));
|
header('Content-Type: application/json');
|
||||||
$data['results'] = $this->logbook_model->timeline_qso_details($adif, $band);
|
echo json_encode($data);
|
||||||
|
|
||||||
// Render Page
|
|
||||||
$data['page_title'] = "Log View - DXCC";
|
|
||||||
$data['filter'] = "country ". $country['name'];
|
|
||||||
|
|
||||||
if ($band != "All") {
|
|
||||||
$data['filter'] .= " and " . $band;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->load->view('timeline/details', $data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -9,11 +9,22 @@ class Accumulate_model extends CI_Model
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_accumulated_dxcc($band) {
|
function get_accumulated_data($band, $award) {
|
||||||
$CI =& get_instance();
|
$CI =& get_instance();
|
||||||
$CI->load->model('Stations');
|
$CI->load->model('Stations');
|
||||||
$station_id = $CI->Stations->find_active();
|
$station_id = $CI->Stations->find_active();
|
||||||
|
|
||||||
|
switch ($award) {
|
||||||
|
case 'dxcc': $result = $this->get_accumulated_dxcc($band, $station_id); break;
|
||||||
|
case 'was': $result = $this->get_accumulated_was($band, $station_id); break;
|
||||||
|
case 'iota': $result = $this->get_accumulated_iota($band, $station_id); break;
|
||||||
|
case 'waz': $result = $this->get_accumulated_waz($band, $station_id); break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_accumulated_dxcc($band, $station_id) {
|
||||||
$sql = "SELECT year(col_time_on) as year,
|
$sql = "SELECT year(col_time_on) as year,
|
||||||
(select count(distinct b.col_dxcc) from " . $this->config->item('table_name') . " as b where year(col_time_on) <= year and b.station_id = ". $station_id;
|
(select count(distinct b.col_dxcc) from " . $this->config->item('table_name') . " as b where year(col_time_on) <= year and b.station_id = ". $station_id;
|
||||||
|
|
||||||
|
|
@ -29,6 +40,120 @@ class Accumulate_model extends CI_Model
|
||||||
$sql .=") total from " . $this->config->item('table_name') . " as a
|
$sql .=") total from " . $this->config->item('table_name') . " as a
|
||||||
where a.station_id = ". $station_id;
|
where a.station_id = ". $station_id;
|
||||||
|
|
||||||
|
if ($band != 'All') {
|
||||||
|
if ($band == 'SAT') {
|
||||||
|
$sql .= " and col_prop_mode ='" . $band . "'";
|
||||||
|
} else {
|
||||||
|
$sql .= " and col_prop_mode !='SAT'";
|
||||||
|
$sql .= " and col_band ='" . $band . "'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql .= " group by year(a.col_time_on)
|
||||||
|
order by year(a.col_time_on)";
|
||||||
|
|
||||||
|
$query = $this->db->query($sql);
|
||||||
|
|
||||||
|
return $query->result();
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_accumulated_was($band, $station_id) {
|
||||||
|
$sql = "SELECT year(col_time_on) as year,
|
||||||
|
(select count(distinct b.col_state) from " . $this->config->item('table_name') . " as b where year(col_time_on) <= year and b.station_id = ". $station_id;
|
||||||
|
|
||||||
|
if ($band != 'All') {
|
||||||
|
if ($band == 'SAT') {
|
||||||
|
$sql .= " and col_prop_mode ='" . $band . "'";
|
||||||
|
} else {
|
||||||
|
$sql .= " and col_prop_mode !='SAT'";
|
||||||
|
$sql .= " and col_band ='" . $band . "'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql .= " and COL_DXCC in ('291', '6', '110')";
|
||||||
|
$sql .= " and COL_STATE in ('AK','AL','AR','AZ','CA','CO','CT','DE','FL','GA','HI','IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MI','MN','MO','MS','MT','NC','ND','NE','NH','NJ','NM','NV','NY','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VA','VT','WA','WI','WV','WY')";
|
||||||
|
|
||||||
|
$sql .=") total from " . $this->config->item('table_name') . " as a
|
||||||
|
where a.station_id = ". $station_id;
|
||||||
|
|
||||||
|
if ($band != 'All') {
|
||||||
|
if ($band == 'SAT') {
|
||||||
|
$sql .= " and col_prop_mode ='" . $band . "'";
|
||||||
|
} else {
|
||||||
|
$sql .= " and col_prop_mode !='SAT'";
|
||||||
|
$sql .= " and col_band ='" . $band . "'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql .= " and COL_DXCC in ('291', '6', '110')";
|
||||||
|
$sql .= " and COL_STATE in ('AK','AL','AR','AZ','CA','CO','CT','DE','FL','GA','HI','IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MI','MN','MO','MS','MT','NC','ND','NE','NH','NJ','NM','NV','NY','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VA','VT','WA','WI','WV','WY')";
|
||||||
|
|
||||||
|
$sql .= " group by year(a.col_time_on)
|
||||||
|
order by year(a.col_time_on)";
|
||||||
|
|
||||||
|
$query = $this->db->query($sql);
|
||||||
|
|
||||||
|
return $query->result();
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_accumulated_iota($band, $station_id) {
|
||||||
|
$sql = "SELECT year(col_time_on) as year,
|
||||||
|
(select count(distinct b.col_iota) from " . $this->config->item('table_name') . " as b where year(col_time_on) <= year and b.station_id = ". $station_id;
|
||||||
|
|
||||||
|
if ($band != 'All') {
|
||||||
|
if ($band == 'SAT') {
|
||||||
|
$sql .= " and col_prop_mode ='" . $band . "'";
|
||||||
|
} else {
|
||||||
|
$sql .= " and col_prop_mode !='SAT'";
|
||||||
|
$sql .= " and col_band ='" . $band . "'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql .=") total from " . $this->config->item('table_name') . " as a
|
||||||
|
where a.station_id = ". $station_id;
|
||||||
|
|
||||||
|
if ($band != 'All') {
|
||||||
|
if ($band == 'SAT') {
|
||||||
|
$sql .= " and col_prop_mode ='" . $band . "'";
|
||||||
|
} else {
|
||||||
|
$sql .= " and col_prop_mode !='SAT'";
|
||||||
|
$sql .= " and col_band ='" . $band . "'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql .= " group by year(a.col_time_on)
|
||||||
|
order by year(a.col_time_on)";
|
||||||
|
|
||||||
|
$query = $this->db->query($sql);
|
||||||
|
|
||||||
|
return $query->result();
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_accumulated_waz($band, $station_id) {
|
||||||
|
$sql = "SELECT year(col_time_on) as year,
|
||||||
|
(select count(distinct b.col_cqz) from " . $this->config->item('table_name') . " as b where year(col_time_on) <= year and b.station_id = ". $station_id;
|
||||||
|
|
||||||
|
if ($band != 'All') {
|
||||||
|
if ($band == 'SAT') {
|
||||||
|
$sql .= " and col_prop_mode ='" . $band . "'";
|
||||||
|
} else {
|
||||||
|
$sql .= " and col_prop_mode !='SAT'";
|
||||||
|
$sql .= " and col_band ='" . $band . "'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql .=") total from " . $this->config->item('table_name') . " as a
|
||||||
|
where a.station_id = ". $station_id;
|
||||||
|
|
||||||
|
if ($band != 'All') {
|
||||||
|
if ($band == 'SAT') {
|
||||||
|
$sql .= " and col_prop_mode ='" . $band . "'";
|
||||||
|
} else {
|
||||||
|
$sql .= " and col_prop_mode !='SAT'";
|
||||||
|
$sql .= " and col_band ='" . $band . "'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$sql .= " group by year(a.col_time_on)
|
$sql .= " group by year(a.col_time_on)
|
||||||
order by year(a.col_time_on)";
|
order by year(a.col_time_on)";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,59 +1,62 @@
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h2><?php echo $page_title; ?></h1>
|
<h2><?php echo $page_title; ?></h1>
|
||||||
|
|
||||||
<form class="form" action="<?php echo site_url('accumulated'); ?>" method="post" enctype="multipart/form-data">
|
<form class="form">
|
||||||
<fieldset>
|
|
||||||
<!-- Select Basic -->
|
<!-- Select Basic -->
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<label class="col-md-1 control-label" for="band">Band</label>
|
<label class="col-md-1 control-label" for="band">Band</label>
|
||||||
<div class="col-md-2">
|
<div class="col-md-2">
|
||||||
<select id="band2" name="band" class="form-control">
|
<select id="band" name="band" class="form-control custom-select">
|
||||||
<option value="All" <?php if ($this->input->post('band') == "All" || $this->input->method() !== 'post') echo ' selected'; ?> >All</option>
|
<option value="All">All</option>
|
||||||
<?php foreach($worked_bands as $band) {
|
<?php foreach($worked_bands as $band) {
|
||||||
echo '<option value="' . $band . '"';
|
echo '<option value="' . $band . '">' . $band . '</option>'."\n";
|
||||||
if ($this->input->post('band') == $band) echo ' selected';
|
|
||||||
echo '>' . $band . '</option>'."\n";
|
|
||||||
} ?>
|
} ?>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
<!-- Button (Double) -->
|
<div class="form-check">
|
||||||
<div class="form-group row">
|
<input class="form-check-input" type="radio" name="awardradio" id="dxcc" value="dxcc" checked>
|
||||||
<label class="col-md-1 control-label" for="button1id"></label>
|
<label class="form-check-label" for="dxcc">
|
||||||
<div class="col-md-10">
|
DX Century Club (DXCC)
|
||||||
<button id="button1id" type="submit" name="button1id" class="btn btn-success btn-primary">Show</button>
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="radio" name="awardradio" id="was" value="was">
|
||||||
|
<label class="form-check-label" for="was">
|
||||||
|
Worked all states (WAS)
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="radio" name="awardradio" id="iota" value="iota">
|
||||||
|
<label class="form-check-label" for="iota">
|
||||||
|
Islands on the air (IOTA)
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="radio" name="awardradio" id="waz" value="waz">
|
||||||
|
<label class="form-check-label" for="waz">
|
||||||
|
Worked all zones (WAZ)
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</fieldset>
|
|
||||||
|
<!-- Button (Double) -->
|
||||||
|
<div class="form-group row">
|
||||||
|
<div class="col-md-10">
|
||||||
|
<button id="button1id" type="button" name="button1id" class="btn btn-success btn-primary" onclick="accumulatePlot(this.form)">Show</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<?php
|
<div id="accumulateContainer">
|
||||||
$i = 1;
|
<canvas id="myChartAccumulate" width="400" height="150"></canvas>
|
||||||
if ($accumulated_dxcc_array) {
|
<div id="accumulateTable"></div>
|
||||||
echo '<table class="table table-sm table-bordered table-hover table-striped table-condensed text-center">
|
</div>
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<td>#</td>
|
|
||||||
<td>Year</td>
|
|
||||||
<td>Accumulated # of DXCC\'s worked</td>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>';
|
|
||||||
|
|
||||||
foreach ($accumulated_dxcc_array as $line) {
|
|
||||||
echo '<tr>
|
|
||||||
<td>' . $i++ . '</td>
|
|
||||||
<td>' . $line->year . '</td>
|
|
||||||
<td>' . $line->total . '</td>
|
|
||||||
</tr>';
|
|
||||||
}
|
|
||||||
echo '</tfoot></table></div>';
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
echo '<div class="alert alert-danger" role="alert"><a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>Nothing found!</div>';
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1790,6 +1790,112 @@ $(document).ready(function(){
|
||||||
</script>
|
</script>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
|
||||||
|
<?php if ($this->uri->segment(1) == "accumulated") { ?>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0"></script>
|
||||||
|
<script>
|
||||||
|
function accumulatePlot(form) {
|
||||||
|
// using this to change color of legend and label according to background color
|
||||||
|
var background = $('body').css( "background-color");
|
||||||
|
var color = 'grey';
|
||||||
|
if (background != ('rgb(255, 255, 255)')) {
|
||||||
|
color = 'white';
|
||||||
|
}
|
||||||
|
|
||||||
|
var baseURL= "<?php echo base_url();?>";
|
||||||
|
var award = form.awardradio.value;
|
||||||
|
$.ajax({
|
||||||
|
url: baseURL+'index.php/accumulated/get_accumulated_data',
|
||||||
|
type: 'post',
|
||||||
|
data: {'Band': form.band.value, 'Award': award},
|
||||||
|
success: function(data) {
|
||||||
|
// used for switching award text in the table and the chart
|
||||||
|
switch(award) {
|
||||||
|
case 'dxcc': var awardtext = "DXCC\'s"; break;
|
||||||
|
case 'was': var awardtext = "states";break;
|
||||||
|
case 'iota': var awardtext = "IOTA\'s";break;
|
||||||
|
case 'waz': var awardtext = "CQ zones"; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// removing the old chart so that it will not interefere when loading chart again
|
||||||
|
$("#accumulateContainer").empty();
|
||||||
|
$("#accumulateContainer").append("<canvas id=\"myChartAccumulate\" width=\"400\" height=\"150\"></canvas><div id=\"accumulateTable\"></div>");
|
||||||
|
|
||||||
|
// appending table to hold the data
|
||||||
|
$("#accumulateTable").append('<table class="accutable table table-sm table-bordered table-hover table-striped table-condensed text-center"><thead>' +
|
||||||
|
'<tr>' +
|
||||||
|
'<td>#</td>' +
|
||||||
|
'<td>Year</td>' +
|
||||||
|
'<td>Accumulated # of ' + awardtext + ' worked </td>'+
|
||||||
|
'</tr>' +
|
||||||
|
'</thead>' +
|
||||||
|
'<tbody></tbody></table>');
|
||||||
|
var labels = [];
|
||||||
|
var dataDxcc = [];
|
||||||
|
|
||||||
|
var $myTable = $('.accutable');
|
||||||
|
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.year);
|
||||||
|
var $content = $('<td></td>').html(row.total);
|
||||||
|
|
||||||
|
$row.append($iterator, $type, $content);
|
||||||
|
|
||||||
|
return $row;
|
||||||
|
});
|
||||||
|
|
||||||
|
// finally inserting the rows
|
||||||
|
$myTable.append(rowElements);
|
||||||
|
|
||||||
|
$.each(data, function(){
|
||||||
|
labels.push(this.year);
|
||||||
|
dataDxcc.push(this.total);
|
||||||
|
});
|
||||||
|
|
||||||
|
var ctx = document.getElementById("myChartAccumulate").getContext('2d');
|
||||||
|
var myChart = new Chart(ctx, {
|
||||||
|
type: 'bar',
|
||||||
|
data: {
|
||||||
|
labels: labels,
|
||||||
|
datasets: [{
|
||||||
|
label: 'Accumulated number of ' + awardtext + ' worked each year',
|
||||||
|
data: dataDxcc,
|
||||||
|
backgroundColor: 'rgba(54, 162, 235, 0.2)',
|
||||||
|
borderColor: 'rgba(54, 162, 235, 1)',
|
||||||
|
borderWidth: 2,
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
scales: {
|
||||||
|
yAxes: [{
|
||||||
|
ticks: {
|
||||||
|
beginAtZero:true,
|
||||||
|
fontColor: color
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
xAxes: [{
|
||||||
|
ticks: {
|
||||||
|
fontColor: color
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
legend: {
|
||||||
|
labels: {
|
||||||
|
fontColor: color,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
正在加载…
在新工单中引用