fsx Posted June 21, 2011 Report Share Posted June 21, 2011 how can I get this? Quote Link to comment Share on other sites More sharing options...
James142 Posted June 21, 2011 Report Share Posted June 21, 2011 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.. Quote Link to comment Share on other sites More sharing options...
stuartpb Posted June 21, 2011 Report Share Posted June 21, 2011 Its something I have being trying to work out for a while now. I've been scratching my head on this one too I have tried and failed a few times on it. Would be very cool if the code could be shared. 1 Quote Link to comment Share on other sites More sharing options...
Guest lorathon Posted June 21, 2011 Report Share Posted June 21, 2011 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! Quote Link to comment Share on other sites More sharing options...
stuartpb Posted June 21, 2011 Report Share Posted June 21, 2011 Thanks Jeff. I'm going to have another go at it later. Quote Link to comment Share on other sites More sharing options...
stuartpb Posted June 21, 2011 Report Share Posted June 21, 2011 Jeff, would the code to go in the ACARS module's for each loop go like this: $td = SchedulesData::distanceBetweenPoints($depicao->lat, $depicao->lng, $arricao->lat, $arricao->lng); $percentleft = (($TD-$c['distremaining'])/$TD)*100; 1 Quote Link to comment Share on other sites More sharing options...
Guest lorathon Posted June 21, 2011 Report Share Posted June 21, 2011 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. Quote Link to comment Share on other sites More sharing options...
stuartpb Posted June 21, 2011 Report Share Posted June 21, 2011 Thanks Jeff, much appreciated +1 rep to you! 1 Quote Link to comment Share on other sites More sharing options...
James142 Posted June 21, 2011 Report Share Posted June 21, 2011 Finally! Thanks Quote Link to comment Share on other sites More sharing options...
stuartpb Posted June 21, 2011 Report Share Posted June 21, 2011 Well I did give you rep Jeff, but someone's playing silly peeps with the repping 2 Quote Link to comment Share on other sites More sharing options...
Guest lorathon Posted June 21, 2011 Report Share Posted June 21, 2011 No problem. Guess someone is out to get me Quote Link to comment Share on other sites More sharing options...
James142 Posted June 21, 2011 Report Share Posted June 21, 2011 No problem. Guess someone is out to get me Sorry guys that was me, I tried to give you both +1 but for some reason I hit the -1 by mistake. I gave you both +1 in your second posts though Again sorry about that 2 Quote Link to comment Share on other sites More sharing options...
stuartpb Posted June 21, 2011 Report Share Posted June 21, 2011 No worries, and thanks for the rep! Have some back. 2 Quote Link to comment Share on other sites More sharing options...
James142 Posted June 21, 2011 Report Share Posted June 21, 2011 No worries, and thanks for the rep! Have some back. Haha thanks 1 Quote Link to comment Share on other sites More sharing options...
Moderators joeri Posted June 21, 2011 Moderators Report Share Posted June 21, 2011 lets all have some reps 2 Quote Link to comment Share on other sites More sharing options...
James142 Posted June 21, 2011 Report Share Posted June 21, 2011 lets all have some reps action failed: you have reached your quota of positive votes for the day D: I'll do it tomorrow Quote Link to comment Share on other sites More sharing options...
stuartpb Posted June 21, 2011 Report Share Posted June 21, 2011 There you go Joeri Quote Link to comment Share on other sites More sharing options...
Moderators joeri Posted June 21, 2011 Moderators Report Share Posted June 21, 2011 action failed: you have reached your quota of positive votes for the day D: I'll do it tomorrow haha i had the same Quote Link to comment Share on other sites More sharing options...
Ahmad Posted June 21, 2011 Report Share Posted June 21, 2011 can someone please post the code here so we can also take advantage as we are not much expert in modifying codes i will really appreciate it. Thanx in advance Quote Link to comment Share on other sites More sharing options...
fsx Posted June 22, 2011 Author Report Share Posted June 22, 2011 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 ? Quote Link to comment Share on other sites More sharing options...
James142 Posted June 22, 2011 Report Share Posted June 22, 2011 can someone please post the code here so we can also take advantage as we are not much expert in modifying codes i will really appreciate it. Thanx in advance Its there. Scroll up Quote Link to comment Share on other sites More sharing options...
Ahmad Posted June 22, 2011 Report Share Posted June 22, 2011 @James i know the code is there i mean the full code where exactly to put that code to work ........ Thanks in Advance Ahmad 2 Quote Link to comment Share on other sites More sharing options...
James142 Posted June 22, 2011 Report Share Posted June 22, 2011 @James i know the code is there i mean the full code where exactly to put that code to work ........ 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) Quote Link to comment Share on other sites More sharing options...
Moderators Kyle Posted June 22, 2011 Moderators Report Share Posted June 22, 2011 Thanks for the share Jeffrey. Quote Link to comment Share on other sites More sharing options...
Cor Posted June 22, 2011 Report Share Posted June 22, 2011 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 Quote Link to comment Share on other sites More sharing options...
James142 Posted June 22, 2011 Report Share Posted June 22, 2011 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); } } Quote Link to comment Share on other sites More sharing options...
stuartpb Posted June 22, 2011 Report Share Posted June 22, 2011 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 Quote Link to comment Share on other sites More sharing options...
Guest lorathon Posted June 22, 2011 Report Share Posted June 22, 2011 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. Quote Link to comment Share on other sites More sharing options...
Cor Posted June 22, 2011 Report Share Posted June 22, 2011 Tnx, works now. I see the percentages. How to make a nice box like Jeffrey has? Regards, Cor Quote Link to comment Share on other sites More sharing options...
stuartpb Posted June 22, 2011 Report Share Posted June 22, 2011 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! 3 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.