[Distances Worked] Updated code (with a rewrite) to support station logbooks
这个提交包含在:
父节点
38963ce887
当前提交
f369b172bd
共有 2 个文件被更改,包括 110 次插入 和 51 次删除
|
|
@ -31,12 +31,14 @@ class Distances_model extends CI_Model
|
||||||
"1.25cm"=>0);
|
"1.25cm"=>0);
|
||||||
|
|
||||||
function get_worked_sats() {
|
function get_worked_sats() {
|
||||||
$CI =& get_instance();
|
$CI =& get_instance();
|
||||||
$CI->load->model('Stations');
|
$CI->load->model('logbooks_model');
|
||||||
$station_id = $CI->Stations->find_active();
|
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
|
||||||
|
|
||||||
|
$location_list = "'".implode("','",$logbooks_locations_array)."'";
|
||||||
|
|
||||||
// get all worked sats from database
|
// get all worked sats from database
|
||||||
$sql = "SELECT distinct col_sat_name FROM ".$this->config->item('table_name')." WHERE station_id = ".$station_id . " and coalesce(col_sat_name, '') <> '' ORDER BY col_sat_name";
|
$sql = "SELECT distinct col_sat_name FROM ".$this->config->item('table_name')." WHERE station_id in (" . $location_list . ") and coalesce(col_sat_name, '') <> '' ORDER BY col_sat_name";
|
||||||
|
|
||||||
$data = $this->db->query($sql);
|
$data = $this->db->query($sql);
|
||||||
|
|
||||||
|
|
@ -49,12 +51,14 @@ class Distances_model extends CI_Model
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_worked_bands() {
|
function get_worked_bands() {
|
||||||
$CI =& get_instance();
|
$CI =& get_instance();
|
||||||
$CI->load->model('Stations');
|
$CI->load->model('logbooks_model');
|
||||||
$station_id = $CI->Stations->find_active();
|
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
|
||||||
|
|
||||||
|
$location_list = "'".implode("','",$logbooks_locations_array)."'";
|
||||||
|
|
||||||
// get all worked slots from database
|
// get all worked slots from database
|
||||||
$sql = "SELECT distinct LOWER(COL_BAND) as COL_BAND FROM ".$this->config->item('table_name')." WHERE station_id = ".$station_id;
|
$sql = "SELECT distinct LOWER(COL_BAND) as COL_BAND FROM ".$this->config->item('table_name')." WHERE station_id in (" . $location_list . ")";
|
||||||
|
|
||||||
$data = $this->db->query($sql);
|
$data = $this->db->query($sql);
|
||||||
$worked_slots = array();
|
$worked_slots = array();
|
||||||
|
|
@ -74,30 +78,93 @@ class Distances_model extends CI_Model
|
||||||
|
|
||||||
function get_distances($postdata, $measurement_base)
|
function get_distances($postdata, $measurement_base)
|
||||||
{
|
{
|
||||||
$CI =& get_instance();
|
$CI =& get_instance();
|
||||||
$CI->load->model('Stations');
|
$CI->load->model('logbooks_model');
|
||||||
$station_id = $CI->Stations->find_active();
|
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
|
||||||
|
|
||||||
$station_gridsquare = $CI->Stations->find_gridsquare();
|
|
||||||
$gridsquare = explode(',', $station_gridsquare); // We need to convert to an array, since a user can enter several gridsquares
|
|
||||||
|
|
||||||
$this->db->select('col_call callsign, col_gridsquare grid');
|
$result = array();
|
||||||
$this->db->where('LENGTH(col_gridsquare) >', 0);
|
|
||||||
|
foreach ($logbooks_locations_array as $station_id) {
|
||||||
|
|
||||||
|
$station_gridsquare = $this->find_gridsquare($station_id);
|
||||||
|
|
||||||
|
if ($station_gridsquare != "") {
|
||||||
|
$gridsquare = explode(',', $station_gridsquare); // We need to convert to an array, since a user can enter several gridsquares
|
||||||
|
|
||||||
|
$this->db->select('col_call callsign, col_gridsquare grid');
|
||||||
|
$this->db->where('LENGTH(col_gridsquare) >', 0);
|
||||||
|
|
||||||
|
if ($postdata['band'] == 'sat') {
|
||||||
|
$this->db->where('col_prop_mode', $postdata['band']);
|
||||||
|
if ($postdata['sat'] != 'All') {
|
||||||
|
$this->db->where('col_sat_name', $postdata['sat']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->db->where('col_band', $postdata['band']);
|
||||||
|
}
|
||||||
|
$this->db->where('station_id', $station_id);
|
||||||
|
$dataarrayata = $this->db->get($this->config->item('table_name'));
|
||||||
|
|
||||||
|
$temp = $this->plot($dataarrayata->result_array(), $gridsquare, $measurement_base);
|
||||||
|
|
||||||
|
$result = $this->mergeresult($result, $temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
echo json_encode($result);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
echo json_encode(array('Error' => 'No QSOs found to plot.'));
|
||||||
|
}
|
||||||
|
|
||||||
if ($postdata['band'] == 'sat') {
|
|
||||||
$this->db->where('col_prop_mode', $postdata['band']);
|
|
||||||
if ($postdata['sat'] != 'All') {
|
|
||||||
$this->db->where('col_sat_name', $postdata['sat']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$this->db->where('col_band', $postdata['band']);
|
|
||||||
}
|
|
||||||
$this->db->where('station_id', $station_id);
|
|
||||||
$dataarrayata = $this->db->get($this->config->item('table_name'));
|
|
||||||
$this->plot($dataarrayata->result_array(), $gridsquare, $measurement_base);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We merge the result from several station_id's. They can have different gridsquares, so we need to use the correct gridsquare to calculate the correct distance.
|
||||||
|
*/
|
||||||
|
function mergeresult($result, $add) {
|
||||||
|
if (sizeof($result) > 0) {
|
||||||
|
if ($result['qrb']['Distance'] < $add['qrb']['Distance']) {
|
||||||
|
$result['qrb']['Distance'] = $add['qrb']['Distance'];
|
||||||
|
$result['qrb']['Grid'] = $add['qrb']['Grid'];
|
||||||
|
$result['qrb']['Callsign'] = $add['qrb']['Callsign'];
|
||||||
|
}
|
||||||
|
$result['qrb']['Qsos'] += $add['qrb']['Qsos'];
|
||||||
|
|
||||||
|
for ($i = 0; $i <= 399; $i++) {
|
||||||
|
$result['qsodata'][$i]['count'] += $add['qsodata'][$i]['count'];
|
||||||
|
|
||||||
|
if ($result['qsodata'][$i]['callcount'] < 5 && $add['qsodata'][$i]['callcount'] > 0) {
|
||||||
|
$calls = explode(',', $add['qsodata'][$i]['calls']);
|
||||||
|
foreach ($calls as $c) {
|
||||||
|
if ($result['qsodata'][$i]['callcount'] < 5) {
|
||||||
|
if ($result['qsodata'][$i]['callcount'] > 0) {
|
||||||
|
$result['qsodata'][$i]['calls'] .= ', ';
|
||||||
|
}
|
||||||
|
$result['qsodata'][$i]['calls'] .= $c;
|
||||||
|
$result['qsodata'][$i]['callcount']++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $add;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Fetches the gridsquare from the station_id
|
||||||
|
*/
|
||||||
|
function find_gridsquare($station_id) {
|
||||||
|
$this->db->where('station_id', $station_id);
|
||||||
|
return $this->db->get('station_profile')->row()->station_gridsquare;
|
||||||
|
}
|
||||||
|
|
||||||
// This functions takes query result from the database and extracts grids from the qso,
|
// This functions takes query result from the database and extracts grids from the qso,
|
||||||
// then calculates distance between homelocator and locator given in qso.
|
// then calculates distance between homelocator and locator given in qso.
|
||||||
// It builds an array, which has 50km intervals, then inputs each length into the correct spot
|
// It builds an array, which has 50km intervals, then inputs each length into the correct spot
|
||||||
|
|
@ -138,17 +205,17 @@ class Distances_model extends CI_Model
|
||||||
$dataarray[$i]['callcount'] = 0;
|
$dataarray[$i]['callcount'] = 0;
|
||||||
$j += 50;
|
$j += 50;
|
||||||
}
|
}
|
||||||
|
|
||||||
$qrb = array ( // Used for storing the QSO with the longest QRB
|
$qrb = array ( // Used for storing the QSO with the longest QRB
|
||||||
'Callsign' => '',
|
'Callsign' => '',
|
||||||
'Grid' => '',
|
'Grid' => '',
|
||||||
'Distance' => '',
|
'Distance' => '',
|
||||||
'Qsoes' => '',
|
'Qsos' => '',
|
||||||
'Grids' => ''
|
'Grids' => ''
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($qsoArray as $qso) {
|
foreach ($qsoArray as $qso) {
|
||||||
$qrb['Qsoes']++; // Counts up number of qsoes
|
$qrb['Qsos']++; // Counts up number of qsos
|
||||||
$bearingdistance = $this->bearing_dist($stationgrid, $qso['grid'], $measurement_base); // Calculates distance based on grids
|
$bearingdistance = $this->bearing_dist($stationgrid, $qso['grid'], $measurement_base); // Calculates distance based on grids
|
||||||
$arrayplacement = $bearingdistance / 50; // Resolution is 50, calculates where to put result in array
|
$arrayplacement = $bearingdistance / 50; // Resolution is 50, calculates where to put result in array
|
||||||
if ($bearingdistance > $qrb['Distance']) { // Saves the longest QSO
|
if ($bearingdistance > $qrb['Distance']) { // Saves the longest QSO
|
||||||
|
|
@ -156,7 +223,7 @@ class Distances_model extends CI_Model
|
||||||
$qrb['Callsign'] = $qso['callsign'];
|
$qrb['Callsign'] = $qso['callsign'];
|
||||||
$qrb['Grid'] = $qso['grid'];
|
$qrb['Grid'] = $qso['grid'];
|
||||||
}
|
}
|
||||||
$dataarray[$arrayplacement]['count']++; // Used for counting total qsoes plotted
|
$dataarray[$arrayplacement]['count']++; // Used for counting total qsos plotted
|
||||||
if ($dataarray[$arrayplacement]['callcount'] < 5) { // Used for tooltip in graph, set limit to 5 calls shown
|
if ($dataarray[$arrayplacement]['callcount'] < 5) { // Used for tooltip in graph, set limit to 5 calls shown
|
||||||
if ($dataarray[$arrayplacement]['callcount'] > 0) {
|
if ($dataarray[$arrayplacement]['callcount'] > 0) {
|
||||||
$dataarray[$arrayplacement]['calls'] .= ', ';
|
$dataarray[$arrayplacement]['calls'] .= ', ';
|
||||||
|
|
@ -165,19 +232,13 @@ class Distances_model extends CI_Model
|
||||||
$dataarray[$arrayplacement]['callcount']++;
|
$dataarray[$arrayplacement]['callcount']++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$qrb['Qsoes'] == 0) { // We have a result :)
|
$data['ok'] = 'OK';
|
||||||
header('Content-Type: application/json');
|
$data['qrb'] = $qrb;
|
||||||
$data['ok'] = 'OK';
|
$data['qsodata'] = $dataarray;
|
||||||
$data['qrb'] = $qrb;
|
$data['unit'] = $unit;
|
||||||
$data['qsodata'] = $dataarray;
|
|
||||||
$data['unit'] = $unit;
|
return $data;
|
||||||
echo json_encode($data);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
header('Content-Type: application/json');
|
|
||||||
echo json_encode(array('Error' => 'No QSOs found to plot.'));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -225,7 +286,7 @@ class Distances_model extends CI_Model
|
||||||
function bearing_dist($loc1, $loc2, $measurement_base) {
|
function bearing_dist($loc1, $loc2, $measurement_base) {
|
||||||
$loc1 = strtoupper($loc1);
|
$loc1 = strtoupper($loc1);
|
||||||
$loc2 = strtoupper($loc2);
|
$loc2 = strtoupper($loc2);
|
||||||
|
|
||||||
if (strlen($loc1) == 4) $loc1 .= 'MM';
|
if (strlen($loc1) == 4) $loc1 .= 'MM';
|
||||||
if (strlen($loc2) == 4) $loc2 .= 'MM';
|
if (strlen($loc2) == 4) $loc2 .= 'MM';
|
||||||
|
|
||||||
|
|
@ -239,8 +300,6 @@ class Distances_model extends CI_Model
|
||||||
$co = cos($l1[1] - $l2[1]) * cos($l1[0]) * cos($l2[0]) + sin($l1[0]) * sin($l2[0]);
|
$co = cos($l1[1] - $l2[1]) * cos($l1[0]) * cos($l2[0]) + sin($l1[0]) * sin($l2[0]);
|
||||||
$ca = atan2(sqrt(1 - $co*$co), $co);
|
$ca = atan2(sqrt(1 - $co*$co), $co);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
switch ($measurement_base) {
|
switch ($measurement_base) {
|
||||||
case 'M':
|
case 'M':
|
||||||
return round(6371*$ca/1.609344);
|
return round(6371*$ca/1.609344);
|
||||||
|
|
@ -252,4 +311,4 @@ class Distances_model extends CI_Model
|
||||||
return round(6371*$ca);
|
return round(6371*$ca);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ function distPlot(form) {
|
||||||
|
|
||||||
options.series.push(series);
|
options.series.push(series);
|
||||||
|
|
||||||
$('#information').html(tmp.qrb.Qsoes + " contacts were plotted.<br /> Your furthest contact was with " + tmp.qrb.Callsign
|
$('#information').html(tmp.qrb.Qsos + " contacts were plotted.<br /> Your furthest contact was with " + tmp.qrb.Callsign
|
||||||
+ " in gridsquare "+ tmp.qrb.Grid
|
+ " in gridsquare "+ tmp.qrb.Grid
|
||||||
+"; the distance was "
|
+"; the distance was "
|
||||||
+tmp.qrb.Distance + tmp.unit +".");
|
+tmp.qrb.Distance + tmp.unit +".");
|
||||||
|
|
|
||||||
正在加载…
在新工单中引用