Jump to content

% complete flight


fsx

Recommended Posts

Its something I have being trying to work out for a while now. No one seems to be able to give me the code for the total flight distance of a route in the acars map. Then Lorathon decides to add it to his website while im still trying to work out how to show the total distance for a route..

Link to comment
Share on other sites

Guest lorathon

I can not share my code since I use much more data then the standard phpVMS does. I have modified mine so much that my code no longer works with the standard. But I can point in the right direction,

It is actually quite simple when you think about it. You need two distances. TD = Total Distance (depicao to arricao). And AD = Actual distance (A/C to arricao) this is already in the ACARS table (distremain). The TD can be calculated using the SchedulesData::distanceBetweenPoints($lat1, $lng1, $lat2, $lng2) function. The departure lat/lng and arrival lat/lng are already pulled for the map. Now you have the two distances. The calculation for percentage is ((TD-AD)/TD)*100. Now you have the percent complete. Use the ACARS module to load the data into the json needed for the ACARS Map (Inside of the foreach loop).

The data can now be used inside of the template.

NOTE - You have to do some checks on the TD. If a zero ('0') is returned you have to skip the calc or you will get a divide by zero error!

Link to comment
Share on other sites

Guest lorathon

I did it like this

$totaldistance = round(SchedulesData::distanceBetweenPoints($flight->deplat, $flight->deplng, $flight->arrlat, $flight->arrlng));
$percomplete = ABS(number_format(((($totaldistance - $flight->distremain) / $totaldistance) * 100), 2));
$c['percomplete'] = $percomplete;

This will give you a nice number to work with.

Link to comment
Share on other sites

Hi everybody,

@lorathon

If I click on the map plane, appears out a table shows (Time Altitude Heading LAT LNG Fuel Phase V SPD SPD G)it is from these data that run the mathematical operation ? or it is an additional table ?

Link to comment
Share on other sites

@James i know the code is there i mean the full code where exactly to put that code to work ........smile.gif

Thanks in Advance

Ahmad

Put the above code in your acars.php file (core/modules/acars) then put <%=flight.percomplete%> in your acarsmap.tpl file (core/templates)

Link to comment
Share on other sites

Put the above code in your acars.php file (core/modules/acars) then put <%=flight.percomplete%> in your acarsmap.tpl file (core/templates)

I can understand that, but at which place in the script, because I have put the code in and nothing happens. Maybe put the whole part

of the code here.

I have another question what to do with charterflights. How do you calculated that.

As always with regards,

Cor

Link to comment
Share on other sites

I can understand that, but at which place in the script, because I have put the code in and nothing happens. Maybe put the whole part

of the code here.

I have another question what to do with charterflights. How do you calculated that.

As always with regards,

Cor

Heres mine:

<?php
/**
* phpVMS - Virtual Airline Administration Software
* Copyright (c) 2008 Nabeel Shahzad
* For more information, visit www.phpvms.net
*	Forums: http://www.phpvms.net/forum
*	Documentation: http://www.phpvms.net/docs
*
* phpVMS is licenced under the following license:
*   Creative Commons Attribution Non-commercial Share Alike (by-nc-sa)
*   View license.txt in the root, or visit http://creativecommons.org/licenses/by-nc-sa/3.0/
*
* @author Nabeel Shahzad
* @copyright Copyright (c) 2008, Nabeel Shahzad
* @link http://www.phpvms.net
* @license http://creativecommons.org/licenses/by-nc-sa/3.0/
*/

class ACARS extends CodonModule
{
public $title = 'ACARS';
public $acarsflights;

public function index()
{
	$this->viewmap();

}

public function viewmap()
{
	$this->title = 'ACARS Map';
	$this->set('acarsdata', ACARSData::GetACARSData());
	$this->render('acarsmap.tpl');

}

/**
 *  We didn't list a function for each ACARS client,
 *	so call this, which will include the acars peice in
 */
public function __call($name, $args)
{
	$acars_action = $args[0];

	// clean the name...
	$name = preg_replace("/[^a-z0-9-]/", "", strtolower($name));
	if(dirname(__FILE__).DS.$name.'.php')
	{
		include_once dirname(__FILE__).DS.$name.'.php';
		return;
	}
}

public function data()
{
	$flights = ACARSData::GetACARSData();

	if(!$flights) 
		$flights = array();

	$this->acarsflights = array();
	foreach($flights as $flight)
	{	
		if($flight->route == '')
		{
			$flight->route_details = array();
		}
		else
		{
			$flight->route_details = NavData::parseRoute($flight->route);
		}

		$c = (array) $flight; // Convert the object to an array

		$c['pilotid'] = PilotData::GetPilotCode($c['code'], $c['pilotid']);

		$totaldistance = round(SchedulesData::distanceBetweenPoints($flight->deplat, $flight->deplng, $flight->arrlat, $flight->arrlng));
$percomplete = ABS(number_format(((($totaldistance - $flight->distremain) / $totaldistance) * 100), 2));
$c['percomplete'] = $percomplete;

		// Normalize the data
		if($c['timeremaining'] == '')
		{
			$c['timeremaining'] ==  '-';
		}

		if(trim($c['phasedetail']) == '')
		{
			$c['phasedetail'] = 'Enroute';
		}

		/* If no heading was passed via ACARS app then calculate it
			This should probably move to inside the ACARSData function, so then
			 the heading is always there for no matter what the calcuation is
			*/
		if($flight->heading == '')
		{
			/* Calculate an angle based on current coords and the
				destination coordinates */

			$flight->heading = intval(atan2(($flight->lat - $flight->arrlat), ($flight->lng - $flight->arrlng)) * 180 / 3.14);
			//$flight->heading *= intval(180/3.14159);

			if(($flight->lng - $flight->arrlng) < 0)
			{
				$flight->heading += 180;
			}

			if($flight->heading < 0)
			{
				$flight->heading += 360;
			}
		}

		// Little one-off fixes to normalize data
		$c['distremaining'] = $c['distremain'];
		$c['pilotname'] = $c['firstname'] . ' ' . $c['lastname'];

		unset($c['messagelog']);

		$this->acarsflights[] = $c;

		continue;
	}

	CodonEvent::Dispatch('refresh_acars', 'ACARS');

	echo json_encode($this->acarsflights);
}

public function routeinfo()
{		
	if($this->get->depicao == '' || $this->get->arricao == '')
		return;

	$depinfo = OperationsData::GetAirportInfo($this->get->depicao);
	if(!$depinfo)
	{
		$depinfo = OperationsData::RetrieveAirportInfo($this->get->depicao);
	}

	$arrinfo = OperationsData::GetAirportInfo($this->get->arricao);
	if(!$arrinfo)
	{
		$arrinfo = OperationsData::RetrieveAirportInfo($this->get->arricao);
	}

	// Convert to json format
	$c = array();
	$c['depapt'] = (array) $depinfo;
	$c['arrapt'] = (array) $arrinfo;

	echo json_encode($c);
}

public function fsacarsconfig()
{
	$this->write_config('fsacars_config.tpl', Auth::$userinfo->code.'.ini');
}

public function fspaxconfig()
{
	$this->write_config('fspax_config.tpl', Auth::$userinfo->code.'_config.cfg');
}

public function xacarsconfig()
{
	$this->write_config('xacars_config.tpl', 'xacars.ini');
}

/**
 * Write out a config file to the user, give the template name and
 *	the filename to save the template as to the user
 *
 * @param mixed $template_name Template to use for config (fspax_config.tpl)
 * @param mixed $save_as File to save as (xacars.ini)
 * @return mixed Nothing, sends the file to the user
 *
 */
public function write_config($template_name, $save_as)
{
	if(!Auth::LoggedIn())
	{
		echo 'You are not logged in!';
		break;
	}

	$this->set('pilotcode', PilotData::GetPilotCode(Auth::$userinfo->code, Auth::$userinfo->pilotid));
	$this->set('userinfo', Auth::$userinfo);

	$acars_config = Template::GetTemplate($template_name, true);
	$acars_config = str_replace("\n", "\r\n", $acars_config);

	Util::downloadFile($acars_config, $save_as);
}
}

Link to comment
Share on other sites

I can understand that, but at which place in the script, because I have put the code in and nothing happens. Maybe put the whole part

of the code here.

I have another question what to do with charterflights. How do you calculated that.

As always with regards,

Cor

Regards the charter flights, we are using Kacars custom, and have stipulated that pilots must enter the route into Kacars before the flight commences. That way the route and % remaining are shown correctly in the ACARS & PIREPS data. We can't physically force them to enter the routes, but we can refuse PIREPS submitted without them.

Find the line shown below in the ACARS.php module file:

$c['pilotid'] = PilotData::GetPilotCode($c['code'], $c['pilotid']);

And add this after that line:

$totaldistance = round(SchedulesData::distanceBetweenPoints($flight->deplat, $flight->deplng, $flight->arrlat, $flight->arrlng));
$percomplete = ABS(number_format(((($totaldistance - $flight->distremain) / $totaldistance) * 100), 2));
$c['percomplete'] = $percomplete;

Once you have done that, you can call the percent in the acarsmap.tpl file with the following:

<%=flight.percomplete%>

This will give the completion percentage in a whole number and two decimal places. You can simply use the text output, or use the value with CSS to create a progress bar, below is one example of how to, but there are many other ways too:

http://cssglobe.com/post/1468/pure-css-animated-progress-bar

Cheers,

Stuart

Link to comment
Share on other sites

Guest lorathon

You also need to change the acars map template. This part depends on how you want to display the percentage. There are many ways to use the data. Using the code I have given loads the acars map template with the percentage complete data. It is up to use it as you see fit.

As for charters? Not sure. If the lat/lng of dep and arr are available then it should work. If not then you will need to do some error checking and load the percomplete with a default value.

Link to comment
Share on other sites

EDIT: Forget that, I think I ballsed the code up. For a really quick and easy way to get a progress bar that looks good, and is easy to modify:

http://blog.leetsoft.com/2006/8/22/super-simple-css-bars

You would need to amend the following line:

<div class="progress-container">          
   <div style="width: 95%"></div>
</div>

To:

<div class="progress-container">          
   <div style="width: <%=flight.percomplete%>%"></div>
</div>

Create a new table column, and place that code in between the <td></td>. Use the CSS as shown on the website in your skins stylesheet, and bobs your mothers brother!

  • Like 3
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...