[Distances Worked] Updated code (with a rewrite) to support station logbooks
这个提交包含在:
		
							父节点
							
								
									38963ce887
								
							
						
					
					
						当前提交
						f369b172bd
					
				
					共有  2 个文件被更改,包括 110 次插入 和 51 次删除
				
			
		|  | @ -32,11 +32,13 @@ class Distances_model extends CI_Model | ||||||
| 
 | 
 | ||||||
|     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); | ||||||
| 
 | 
 | ||||||
|  | @ -50,11 +52,13 @@ 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(); | ||||||
|  | @ -75,10 +79,16 @@ 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(); | 		$result = array(); | ||||||
|  | 
 | ||||||
|  | 		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
 | 				$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->select('col_call callsign, col_gridsquare grid'); | ||||||
|  | @ -95,7 +105,64 @@ class Distances_model extends CI_Model | ||||||
| 				} | 				} | ||||||
| 				$this->db->where('station_id', $station_id); | 				$this->db->where('station_id', $station_id); | ||||||
| 				$dataarrayata = $this->db->get($this->config->item('table_name')); | 				$dataarrayata = $this->db->get($this->config->item('table_name')); | ||||||
|         $this->plot($dataarrayata->result_array(), $gridsquare, $measurement_base); | 
 | ||||||
|  | 				$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.')); | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /* | ||||||
|  |      * 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,
 | ||||||
|  | @ -143,12 +210,12 @@ class Distances_model extends CI_Model | ||||||
|                 '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'] .= ', '; | ||||||
|  | @ -166,18 +233,12 @@ class Distances_model extends CI_Model | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             if (!$qrb['Qsoes'] == 0) {  // We have a result :)
 |  | ||||||
|                 header('Content-Type: application/json'); |  | ||||||
| 			$data['ok'] = 'OK'; | 			$data['ok'] = 'OK'; | ||||||
| 			$data['qrb'] = $qrb; | 			$data['qrb'] = $qrb; | ||||||
| 			$data['qsodata'] = $dataarray; | 			$data['qsodata'] = $dataarray; | ||||||
| 			$data['unit'] = $unit; | 			$data['unit'] = $unit; | ||||||
|                 echo json_encode($data); | 
 | ||||||
|             } |             return $data; | ||||||
|             else { |  | ||||||
|                 header('Content-Type: application/json'); |  | ||||||
|                 echo json_encode(array('Error' => 'No QSOs found to plot.')); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -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); | ||||||
|  |  | ||||||
|  | @ -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 +"."); | ||||||
|  |  | ||||||
		正在加载…
	
		在新工单中引用