Refactored Distances_model to use Qra-Lib. Still Debug-Output in it
这个提交包含在:
父节点
2f694e060e
当前提交
b947b76fb0
共有 1 个文件被更改,包括 51 次插入 和 107 次删除
|
|
@ -4,8 +4,7 @@ if (!defined('BASEPATH')) exit('No direct script access allowed');
|
|||
class Distances_model extends CI_Model
|
||||
{
|
||||
|
||||
function get_distances($postdata, $measurement_base)
|
||||
{
|
||||
function get_distances($postdata, $measurement_base) {
|
||||
$CI =& get_instance();
|
||||
$CI->load->model('logbooks_model');
|
||||
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
|
||||
|
|
@ -122,7 +121,7 @@ class Distances_model extends CI_Model
|
|||
// It builds an array, which has 50km intervals, then inputs each length into the correct spot
|
||||
// The function returns a json-encoded array.
|
||||
function plot($qsoArray, $gridsquare, $measurement_base) {
|
||||
|
||||
$this->load->library('Qra');
|
||||
$stationgrid = strtoupper($gridsquare[0]); // We use only the first entered gridsquare from the active profile
|
||||
if (strlen($stationgrid) == 4) $stationgrid .= 'MM'; // adding center of grid if only 4 digits are specified
|
||||
|
||||
|
|
@ -169,9 +168,9 @@ class Distances_model extends CI_Model
|
|||
|
||||
foreach ($qsoArray as $qso) {
|
||||
$qrb['Qsos']++; // Counts up number of qsos
|
||||
$bearingdistance = $this->bearing_dist($stationgrid, $qso['grid'], $measurement_base); // Calculates distance based on grids
|
||||
if (($qso['COL_DISTANCE'] ?? -1) != $bearingdistance) {
|
||||
log_message("error",$qso['COL_PRIMARY_KEY'].' from '.$qso['COL_DISTANCE'].' to '.$bearingdistance);
|
||||
$bearingdistance = $this->qra->distance($stationgrid, $qso['grid'], $measurement_base);
|
||||
if ($bearingdistance != $qso['COL_DISTANCE']) {
|
||||
log_message("error",$qso['COL_PRIMARY_KEY'].'/'.$qso['callsign'].' from '.$qso['COL_DISTANCE'].' to '.$bearingdistance);
|
||||
}
|
||||
$arrayplacement = (int)($bearingdistance / 50); // Resolution is 50, calculates where to put result in array
|
||||
if ($bearingdistance > $qrb['Distance']) { // Saves the longest QSO
|
||||
|
|
@ -213,61 +212,6 @@ class Distances_model extends CI_Model
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Converts locator to latitude and longitude
|
||||
* Input: locator
|
||||
* Returns: array with longitude and latitude
|
||||
*/
|
||||
function loc_to_latlon ($loc) {
|
||||
/* lat */
|
||||
$l[0] =
|
||||
(ord(substr($loc, 1, 1))-65) * 10 - 90 +
|
||||
(ord(substr($loc, 3, 1))-48) +
|
||||
(ord(substr($loc, 5, 1))-65) / 24 + 1/48;
|
||||
$l[0] = $this->deg_to_rad($l[0]);
|
||||
/* lon */
|
||||
$l[1] =
|
||||
(ord(substr($loc, 0, 1))-65) * 20 - 180 +
|
||||
(ord(substr($loc, 2, 1))-48) * 2 +
|
||||
(ord(substr($loc, 4, 1))-65) / 12 + 1/24;
|
||||
$l[1] = $this->deg_to_rad($l[1]);
|
||||
|
||||
return $l;
|
||||
}
|
||||
|
||||
function deg_to_rad ($deg) {
|
||||
return (M_PI * $deg/180);
|
||||
}
|
||||
|
||||
function bearing_dist($loc1, $loc2, $measurement_base) {
|
||||
$loc1 = strtoupper($loc1);
|
||||
$loc2 = strtoupper($loc2);
|
||||
|
||||
if (strlen($loc1) == 4) $loc1 .= 'MM';
|
||||
if (strlen($loc2) == 4) $loc2 .= 'MM';
|
||||
|
||||
if (!$this->valid_locator($loc1) || !$this->valid_locator($loc2)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$l1 = $this->loc_to_latlon($loc1);
|
||||
$l2 = $this->loc_to_latlon($loc2);
|
||||
|
||||
$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);
|
||||
|
||||
switch ($measurement_base) {
|
||||
case 'M':
|
||||
return ceil(6371*$ca/1.609344);
|
||||
case 'K':
|
||||
return ceil(6371*$ca);
|
||||
case 'N':
|
||||
return ceil(6371*$ca/1.852);
|
||||
default:
|
||||
return ceil(6371*$ca);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Used to fetch QSOs from the logbook in the awards
|
||||
*/
|
||||
|
|
|
|||
正在加载…
在新工单中引用