Jump to content

Average Real Fuel/ Time used in Schedule Search


Nighthawk

Recommended Posts

Hi made a little Snippet in /core/templates/schedule_results.tpl

It shows like this :

avg%20Fuel.jpg

Here is the code (Line 14-78 in my code)

<tbody>
<?php foreach($schedule_list as $schedule) { ?>
<tr>
<td>
 <a href="<?php echo url('/schedules/details/'.$schedule->id);?>"><?php echo $schedule->code . $schedule->flightnum?>
  <?php echo '('.$schedule->depicao.' - '.$schedule->arricao.')'?>
 </a>
 <br />

 <strong>Departure: </strong><?php echo $schedule->deptime;?>         <strong>Arrival: </strong><?php echo $schedule->arrtime;?><br />
 <strong>Equipment: </strong><?php echo $schedule->aircraft; ?> (<?php echo $schedule->registration;?>)  <strong>Distance: </strong><?php echo $schedule->distance . Config::Get('UNITS');?>
 <br />
 <strong>Days Flown: </strong><?php echo Util::GetDaysCompact($schedule->daysofweek); ?><br />
 <?php echo ($schedule->route=='') ? '' : '<strong>Route: </strong>'.$schedule->route.'<br />' ?>
 <?php echo ($schedule->notes=='') ? '' : '<strong>Notes: </strong>'.html_entity_decode($schedule->notes).'<br />' ?>
 <?php
 # Note: this will only show if the above code to
 # skip the schedule is commented out
 if($schedule->bidid != 0) {
  echo 'This route has been bid on';
 }
 ?>
 </br>
 <?php
//Routes Flown  
$Tesla2=("$schedule->flightnum");
$result2 = mysql_query("SELECT COUNT(*) FROM phpvms_pireps WHERE flightnum='$Tesla2'");
$num_rows2 = mysql_result($result2,0);
?>
Route flown:<?php print  "$num_rows2" ?></br>
<?php
//Average Fuel used
$Tesla2=("$schedule->flightnum");
$result3 = mysql_query("SELECT sum(fuelused) FROM phpvms_pireps WHERE flightnum='$Tesla2'");
$num_rows3 = mysql_result($result3,0);
?>
Real Average Fuel used:<?php echo"$num_rows3"/"$num_rows2"?> <?php echo Config::Get('CARGO_UNITS');?></br>
<?php 
//Average Time
$result4 = mysql_query("SELECT SUM(flighttime)  FROM phpvms_pireps WHERE flightnum='$Tesla2'");
$num_rows4 = mysql_result($result4,0);
$array=explode(".", $num_rows4);
$hours2=$array[0];
$min2=$array[1];
$min2calc=(("$hours2"*60)+"$min2");
$min3calc=$min2calc/"$num_rows2";
$hourcalc=$min3calc/60;
$hours3=("$hours2"/"$num_rows2");
$hours4=floor($hours3);
$Difmin=$min3calc-(("$hours2"/"$num_rows2")*60);
$totaltime2=$hours4+("$Difmin"/100);
?>
Real Average Flight duration: <?php print $totaltime2;?> hrs 


</td>

Link to comment
Share on other sites

I got it working for me, but I changed a couple of things. The main reason it didn't work for me was the API hook wasn't schedule->, but route->.

This is what I have:

//Routes Flown  
$Tesla2=("$route->flightnum");
$result2 = mysql_query("SELECT COUNT(*) FROM phpvms_pireps WHERE flightnum='$Tesla2'");
$num_rows2 = mysql_result($result2,0);
?>
<b>Route flown:</b><br /><?php echo "$num_rows2" ?> times</br>


<?php
//Average Fuel used
$Tesla2=("$route->flightnum");
$result3 = mysql_query("SELECT sum(fuelused) FROM phpvms_pireps WHERE flightnum='$Tesla2'");
$num_rows3 = mysql_result($result3,0);
?>
<b>Average Fuel consumption:</b><br />
<?php echo round($num_rows3, 0, PHP_ROUND_HALF_UP); ?> <?php echo Config::Get('CARGO_UNITS');?></br>

<?php
//Average Time
$result4 = mysql_query("SELECT SUM(flighttime) FROM phpvms_pireps WHERE flightnum='$Tesla2'");
$num_rows4 = mysql_result($result4,0);
$array=explode(".", $num_rows4);
$hours2=$array[0];
$min2=$array[1];
$min2calc=(("$hours2"*60)+"$min2");
$min3calc=$min2calc/"$num_rows2";
$hourcalc=$min3calc/60;
$hours3=("$hours2"/"$num_rows2");
$hours4=floor($hours3);
$Difmin=$min3calc-(("$hours2"/"$num_rows2")*60);
$totaltime2=$hours4+("$Difmin"/100);
?>
<b>Average Flight duration:</b><br />
<?php echo round($totaltime2, 2); ?> hrs

Used echo round on the results to round results to 2 decimals for duration and to round up to the next whole number for fuel.

Link to comment
Share on other sites

Tried that first, got loads of errors.

For the division by zero errors, add an @ symbol before the calculation to suppress the error as it will go away once the route has been flown once. Like so:

$min3calc=@($min2calc/"$num_rows2");

For the round errors, you can either remove the round, like this:

<li><b>Average Fuel used:</b> <?php echo round($num_rows3, 0, PHP_ROUND_HALF_UP); ?> <?php echo Config::Get('CARGO_UNITS');?></li>

becomes

<li><b>Average Fuel used:</b> <?php echo ($num_rows3); ?> <?php echo Config::Get('CARGO_UNITS');?></li>

and

<li><b>Average Flight time:</b> <?php echo round($totaltime2, 2); ?> hrs</li>

becomes

<li><b>Average Flight time:</b> <?php echo ($totaltime2); ?> hrs</li>

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...