[Distance plotting] This now follows chosen distance measurement. MAP file added for broken highstock.js.

pull/715/head
Andreas 2020-11-20 11:55:55 +01:00
rodzic a0fe49e04b
commit 3e59cd3651
4 zmienionych plików z 44 dodań i 11 usunięć

Wyświetl plik

@ -41,8 +41,15 @@ class Distances extends CI_Controller {
//load model
$this->load->model('Distances_model');
if ($this->session->userdata('user_measurement_base') == NULL) {
$measurement_base = $this->config->item('measurement_base');
}
else {
$measurement_base = $this->session->userdata('user_measurement_base');
}
// get data
$data = $this->Distances_model->get_distances($postData);
$data = $this->Distances_model->get_distances($postData, $measurement_base);
return json_encode($data);
}

Wyświetl plik

@ -9,7 +9,7 @@ class Distances_model extends CI_Model
parent::__construct();
}
function get_distances($postdata)
function get_distances($postdata, $measurement_base)
{
$CI =& get_instance();
$CI->load->model('Stations');
@ -29,17 +29,32 @@ class Distances_model extends CI_Model
}
$this->db->where('station_id', $station_id);
$dataarrayata = $this->db->get($this->config->item('table_name'));
$this->plot($dataarrayata->result_array(), $gridsquare);
$this->plot($dataarrayata->result_array(), $gridsquare, $measurement_base);
}
// This functions takes query result from the database and extracts grids from the 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
// The function returns a json-encoded array.
function plot($qsoArray, $gridsquare) {
function plot($qsoArray, $gridsquare, $measurement_base) {
$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
switch ($measurement_base) {
case 'M':
$unit = "mi";
$dist = '13000';
break;
case 'K':
$unit = "km";
$dist = '20000';
break;
case 'N':
$unit = "nmi";
$dist = '11000';
break;
}
if (!$this->valid_locator($stationgrid)) {
header('Content-Type: application/json');
echo json_encode(array('Error' => 'Error. There is a problem with the gridsquare set in your profile!'));
@ -47,8 +62,8 @@ class Distances_model extends CI_Model
else {
// Making the array we will use for plotting, we save occurrences of the length of each qso in the array
$j = 0;
for ($i = 0; $j < 20000; $i++) {
$dataarray[$i]['dist'] = $j . 'km - ' . ($j + 50) . 'km';
for ($i = 0; $j < $dist; $i++) {
$dataarray[$i]['dist'] = $j . $unit . ' - ' . ($j + 50) . $unit;
$dataarray[$i]['count'] = 0;
$dataarray[$i]['calls'] = '';
$dataarray[$i]['callcount'] = 0;
@ -65,7 +80,7 @@ class Distances_model extends CI_Model
foreach ($qsoArray as $qso) {
$qrb['Qsoes']++; // Counts up number of qsoes
$bearingdistance = $this->bearing_dist($stationgrid, $qso['grid']); // 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
if ($bearingdistance > $qrb['Distance']) { // Saves the longest QSO
$qrb['Distance'] = $bearingdistance;
@ -87,6 +102,7 @@ class Distances_model extends CI_Model
$data['ok'] = 'OK';
$data['qrb'] = $qrb;
$data['qsodata'] = $dataarray;
$data['unit'] = $unit;
echo json_encode($data);
}
else {
@ -137,7 +153,7 @@ class Distances_model extends CI_Model
return (M_PI * $deg/180);
}
function bearing_dist($loc1, $loc2) {
function bearing_dist($loc1, $loc2, $measurement_base) {
$loc1 = strtoupper($loc1);
$loc2 = strtoupper($loc2);
@ -154,6 +170,15 @@ class Distances_model extends CI_Model
$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);
return round(6371*$ca);
switch ($measurement_base) {
case 'M':
return round(6371*$ca/1.609344);
case 'K':
return round(6371*$ca);
case 'N':
return round(6371*$ca/1.852);
}
}
}

Wyświetl plik

@ -1292,7 +1292,7 @@ $(document).ready(function(){
xAxis: {
labels: {
formatter: function() {
return this.value * '50' + ' km';
return this.value * '50' + ' ' + tmp.unit;
}
}
}
@ -1331,7 +1331,7 @@ $(document).ready(function(){
$('#information').html(tmp.qrb.Qsoes + " contacts were plotted.<br /> Your furthest contact was with " + tmp.qrb.Callsign
+ " in gridsquare "+ tmp.qrb.Grid
+" the distance was "
+tmp.qrb.Distance +"km.");
+tmp.qrb.Distance + tmp.unit +".");
var chart = new Highcharts.Chart(options);
}

File diff suppressed because one or more lines are too long