[Days with QSOs] Fix if no QSOs found

这个提交包含在:
Andreas 2021-11-14 17:49:35 +01:00
父节点 6e6fe817fe
当前提交 341e8f4a33
共有 2 个文件被更改,包括 136 次插入115 次删除

查看文件

@ -9,6 +9,10 @@ class Dayswithqso_model extends CI_Model
$CI->load->model('logbooks_model'); $CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
if (!$logbooks_locations_array) {
return null;
}
$location_list = "'".implode("','",$logbooks_locations_array)."'"; $location_list = "'".implode("','",$logbooks_locations_array)."'";
$sql = "select year(COL_TIME_ON) Year, COUNT(DISTINCT TO_DAYS(COL_TIME_ON)) as Days from " $sql = "select year(COL_TIME_ON) Year, COUNT(DISTINCT TO_DAYS(COL_TIME_ON)) as Days from "
@ -25,35 +29,38 @@ class Dayswithqso_model extends CI_Model
*/ */
function getCurrentStreak() { function getCurrentStreak() {
$dates = $this->getDates(); $dates = $this->getDates();
$dates = array_reverse($dates);
$streak = 1;
$firstrun = true;
$dateprev = date_create(date('Y-m-d')); if ($dates) {
$dates = array_reverse($dates);
foreach($dates as $date) { // Loop through the result set $streak = 1;
$datecurr = date_create($date->date); $firstrun = true;
$diff = $dateprev->diff($datecurr)->format("%a"); // Getting date difference between current date and previous date in array
$dateprev = date_create(date('Y-m-d'));
if ($diff == 0) {
$streaks['highstreak'] = $streak; foreach($dates as $date) { // Loop through the result set
$streaks['endstreak'] = $datecurr->format('Y-m-d'); $datecurr = date_create($date->date);
$streaks['beginstreak'] = $datecurr->format('Y-m-d'); $diff = $dateprev->diff($datecurr)->format("%a"); // Getting date difference between current date and previous date in array
$firstrun = false;
if ($diff == 0) {
$streaks['highstreak'] = $streak;
$streaks['endstreak'] = $datecurr->format('Y-m-d');
$streaks['beginstreak'] = $datecurr->format('Y-m-d');
$firstrun = false;
}
else if ($diff == 1 and !$firstrun) { // If diff = 1, means that we are on a streak
$streaks['highstreak'] = ++$streak;
$streaks['beginstreak'] = date_create($streaks['endstreak'])->sub(new DateInterval('P'.($streak-1).'D'))->format('Y-m-d');
} else {
break;
}
$dateprev = date_create($date->date);
} }
else if ($diff == 1 and !$firstrun) { // If diff = 1, means that we are on a streak
$streaks['highstreak'] = ++$streak; if (isset($streaks) && is_array($streaks)) {
$streaks['beginstreak'] = date_create($streaks['endstreak'])->sub(new DateInterval('P'.($streak-1).'D'))->format('Y-m-d'); return $streaks;
} else { } else {
break; return null;
} }
$dateprev = date_create($date->date);
}
if (isset($streaks) && is_array($streaks)) {
return $streaks;
} else {
return null;
} }
} }
@ -62,36 +69,40 @@ class Dayswithqso_model extends CI_Model
*/ */
function getAlmostCurrentStreak() { function getAlmostCurrentStreak() {
$dates = $this->getDates(); $dates = $this->getDates();
$dates = array_reverse($dates);
$streak = 1;
$firstrun = true;
$dateprev = date_create(date('Y-m-d')); if ($dates) {
$dates = array_reverse($dates);
foreach($dates as $date) { // Loop through the result set $streak = 1;
$datecurr = date_create($date->date); $firstrun = true;
$diff = $dateprev->diff($datecurr)->format("%a"); // Getting date difference between current date and previous date in array
$dateprev = date_create(date('Y-m-d'));
if ($diff == 1 && $firstrun == true) {
$streaks['highstreak'] = $streak++; foreach($dates as $date) { // Loop through the result set
$streaks['endstreak'] = $datecurr->format('Y-m-d'); $datecurr = date_create($date->date);
$streaks['beginstreak'] = $datecurr->format('Y-m-d'); $diff = $dateprev->diff($datecurr)->format("%a"); // Getting date difference between current date and previous date in array
$firstrun = false;
} if ($diff == 1 && $firstrun == true) {
else if ($diff == 1 && $firstrun == false) {
$streaks['highstreak'] = $streak++; $streaks['highstreak'] = $streak++;
$streaks['beginstreak'] = date_create($streaks['endstreak'])->sub(new DateInterval('P'.($streak-2).'D'))->format('Y-m-d'); $streaks['endstreak'] = $datecurr->format('Y-m-d');
} else { $streaks['beginstreak'] = $datecurr->format('Y-m-d');
break; $firstrun = false;
}
else if ($diff == 1 && $firstrun == false) {
$streaks['highstreak'] = $streak++;
$streaks['beginstreak'] = date_create($streaks['endstreak'])->sub(new DateInterval('P'.($streak-2).'D'))->format('Y-m-d');
} else {
break;
}
$dateprev = date_create($date->date);
}
if (isset($streaks) && is_array($streaks)) {
return $streaks;
} else {
return null;
} }
$dateprev = date_create($date->date);
} }
if (isset($streaks) && is_array($streaks)) {
return $streaks;
} else {
return null;
}
} }
/* /*
@ -103,35 +114,39 @@ class Dayswithqso_model extends CI_Model
$dateprev = date_create('1900-01-01'); // init variable with an old date $dateprev = date_create('1900-01-01'); // init variable with an old date
$i = 0; $i = 0;
foreach($dates as $date) { // Loop through the result set if ($dates) {
$datecurr = date_create($date->date); foreach($dates as $date) { // Loop through the result set
if ($dateprev == date_create('1900-01-01')) { // If first run $datecurr = date_create($date->date);
$dateprev = $datecurr; if ($dateprev == date_create('1900-01-01')) { // If first run
} $dateprev = $datecurr;
else { }
$diff = $dateprev->diff($datecurr)->format("%a"); // Getting date difference between current date and previous date in array else {
if ($diff == 1) { // If diff = 1, means that we are on a streak $diff = $dateprev->diff($datecurr)->format("%a"); // Getting date difference between current date and previous date in array
$streak++; if ($diff == 1) { // If diff = 1, means that we are on a streak
$endstreak = $datecurr; // As long as the streak continues, we update the end date $streak++;
} else { $endstreak = $datecurr; // As long as the streak continues, we update the end date
if ($streak > 1) { } else {
$streaks[$i]['highstreak'] = $streak; if ($streak > 1) {
$streaks[$i]['endstreak'] = $endstreak->format('Y-m-d'); $streaks[$i]['highstreak'] = $streak;
$streaks[$i]['beginstreak'] = $endstreak->sub(new DateInterval('P'.($streak-1).'D'))->format('Y-m-d'); $streaks[$i]['endstreak'] = $endstreak->format('Y-m-d');
$i++; $streaks[$i]['beginstreak'] = $endstreak->sub(new DateInterval('P'.($streak-1).'D'))->format('Y-m-d');
} $i++;
$streak = 1; }
$streak = 1;
}
$dateprev = date_create($date->date);
} }
$dateprev = date_create($date->date);
} }
}
if (isset($streaks) && is_array($streaks)) {
usort($streaks, array($this,'compareStreak')); // Sort array, highest streak first if (isset($streaks) && is_array($streaks)) {
$streaks_trimmed = array_slice($streaks, 0,10); // We only want top 10, so we trim the array usort($streaks, array($this,'compareStreak')); // Sort array, highest streak first
return $streaks_trimmed; $streaks_trimmed = array_slice($streaks, 0,10); // We only want top 10, so we trim the array
} else { return $streaks_trimmed;
return null; } else {
return null;
}
} }
} }
@ -150,6 +165,10 @@ class Dayswithqso_model extends CI_Model
$CI->load->model('logbooks_model'); $CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
if (!$logbooks_locations_array) {
return null;
}
$location_list = "'".implode("','",$logbooks_locations_array)."'"; $location_list = "'".implode("','",$logbooks_locations_array)."'";
$sql = "select distinct cast(col_time_on as date) as date from " $sql = "select distinct cast(col_time_on as date) as date from "

查看文件

@ -1,46 +1,48 @@
$.ajax({ $.ajax({
url: base_url+'index.php/dayswithqso/get_days', url: base_url + 'index.php/dayswithqso/get_days',
success: function(data) { success: function (data) {
var labels = []; if ($.trim(data)) {
var dataDxcc = []; var labels = [];
$.each(data, function(){ var dataDxcc = [];
labels.push(this.Year); $.each(data, function () {
dataDxcc.push(this.Days); labels.push(this.Year);
}); dataDxcc.push(this.Days);
var ctx = document.getElementById("myChartDiff").getContext('2d'); });
var color = ifDarkModeThemeReturn('white', 'grey'); var ctx = document.getElementById("myChartDiff").getContext('2d');
var myChart = new Chart(ctx, { var color = ifDarkModeThemeReturn('white', 'grey');
type: 'bar', var myChart = new Chart(ctx, {
data: { type: 'bar',
labels: labels, data: {
datasets: [{ labels: labels,
label: 'Days with QSOs', datasets: [{
data: dataDxcc, label: 'Days with QSOs',
backgroundColor: 'rgba(54, 162, 235, 0.2)', data: dataDxcc,
borderColor: 'rgba(54, 162, 235, 1)', backgroundColor: 'rgba(54, 162, 235, 0.2)',
borderWidth: 2 borderColor: 'rgba(54, 162, 235, 1)',
}] borderWidth: 2
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true,
fontColor: color
}
}],
xAxes: [{
ticks: {
fontColor: color
}
}] }]
}, },
legend: { options: {
labels: { scales: {
fontColor: color yAxes: [{
ticks: {
beginAtZero: true,
fontColor: color
}
}],
xAxes: [{
ticks: {
fontColor: color
}
}]
},
legend: {
labels: {
fontColor: color
}
} }
} }
} });
}); }
} }
}); });