Jump to content

HubStats Class


Tom

Recommended Posts

You place the file in the core/common/ folder

Then to use the data, add the code to your template, for example:

<? echo HubStats::CountPilots('EGKK'); ?>

Will display a number on the page.

For something like Pilots or FlightsDetails:

<?
$pilots = HubStats::Pilots('CYYC');
foreach($pilots as $pilot){
echo 'Name: '.$pilot->firstname.', ';
} ?>

Will display "Name: John, Bill, Bob" and so on. Obviously you can change this to use any of the fields you want.

  • Like 1
Link to comment
Share on other sites

>.< Forgot people don't always have <? set... seriouslyyyyyy web hosts, get on it.

Glad everyone likes it, and damn Kyle it seems I neglected to add something if there are 0 records. My bad. If it's a problem let me know and I'll throw something together.

Link to comment
Share on other sites

<?php
echo "<strong>Hub stats for". " " . $userinfo->hub . "</strong>";
echo "<br />";
echo "Number of pilots:". " " .HubStats::CountPilots($userinfo->hub);
echo "<br />";
echo "Number of Flights flown:". " " .HubStats::CountFlights($userinfo->hub);
echo "<br />";
echo "Total miles flown:". " " .HubStats::TotalMiles($userinfo->hub)."nm";
echo "<br />";
echo "Total hours flown:". " " .HubStats::TotalHours($userinfo->hub); 
?>

That is code I use to get the hubstats for the hub a pilot is in. It gets the information from the db. This is only for the profile_main.tpl. It saves on having to use a load of if/else statements.

Link to comment
Share on other sites

with this:

<table width="100%" border="0">
     <tr>
       <td>HUB STATS</td>
     </tr>
     <tr>
       <td>Total Flights: <?php echo HubStats::CountFlights('EDDF'); ?></td>
     </tr>
     <tr>
       <td>Total Hours Flown: <?php echo HubStats::TotalHours('EDDF'); ?></td>
     </tr>
     <tr>
       <td>Total Active Pilots Assigned: <?php echo HubStats::CountPilots('EDDF'); ?></td>
     </tr>
   </table>

I get:

HUB STATS
Total Flights:
Fatal error: Call to undefined method HubStats::countflights() in E:\AppServ\www\fss\lib\skins\crystalogre\eddf_hub.tpl on line 44

and line 44 is:

        <td>Total Flights: <?php echo HubStats::CountFlights('EDDF'); ?></td>

But always thank you for this GREAT! module ;)

Link to comment
Share on other sites

Guest lorathon

I think that you could have combined a lot of these to get better results. Here is a hubstats function that I use.

public static function getHubStats($hubicao)
{	
$key = 'HubStats_Stats_'.$hubicao;

$ret = CodonCache::read($key);

if($ret === false)
{
	$params = array(
		'u.hub'		 	=> $hubicao,
		'p.accepted'	=> PIREP_ACCEPTED
		);

	$sql = 'SELECT
		COUNT(p.pirepid) as total,
		SUM(p.landingrate)/COUNT(*) as landAvg,
		SUM(p.gross) as gross,	
		SUM(p.expenses) as expenses,
		SUM(p.pilotpay) as pilotpay,
		SUM(p.revenue) as revenue,
		SUM(p.load) as pax,	
		SUM(p.fuelused) as fuelused,
		SUM(p.fuelprice) as fuelprice,
		SUM(p.fuelused)/SUM(p.fuelprice) as fuelAvg,
		SUM((TIME_TO_SEC(flighttime_stamp)/60)) as time,
		SUM(p.distance) as distance,	
		COUNT(DISTINCT(p.pilotid)) as pilots,
		COUNT(DISTINCT(p.depicao)) as departures,
		COUNT(DISTINCT(p.arricao)) as arrivals,
		COUNT(DISTINCT(a.icao)) as airframes														
	        FROM '.TABLE_PREFIX.'pireps p	
		LEFT JOIN '.TABLE_PREFIX.'pilots u ON u.pilotid = p.pilotid
		LEFT JOIN '.TABLE_PREFIX.'aircraft a ON a.id = p.aircraft		
		';

	$sql .= DB::build_where($params);

	$ret = DB::get_row($sql);		

	CodonCache::write($key, $ret, 'long');
}
return $ret;	
}

This uses the cache function of phpVMS and also returns the following data.

  • $ret->total = Total number of accepted pireps
  • $ret->landAvg = Landing Average of all accepted pireps
  • $ret->gross = Total Gross revenue of accepted pireps
  • $ret->expenses = Total expenses of all accepted pireps
  • $ret->pilotpay = Total pilotpay of all accepted pireps
  • $ret->revenue = Total revenue of all accepted pireps
  • $ret->pax = Total load count (this one is tricky if you run pax and cargo then this wont work correctly it just adds all of the load fields)
  • $ret->fuelused = Total fuel used of all accepted pireps
  • $ret->fuelprice = Total cost of all fuel of all accepted pireps
  • $ret->fuelAvg = Average fuel per unit price of all accepted pireps
  • $ret->time = Total flightime of all accepted pireps (returned as minutes use a different function to convert to hours:minutes)
  • $ret->distance = Total distance flown of all accepted pireps
  • $ret->pilots = Total pilots who have actually filed an accepted pirep
  • $ret->departures = Total number of airport departures (counts an airport only once)
  • $ret->arrivals = Same as above except arrival airports
  • $ret->airframes = Total number of airframes flown (uses aircraft icao to count)

Link to comment
Share on other sites

Guest lorathon

Here is the function to return Hours:Minutes from Minutes. I did not write this. I found it somewhere on the vast vast wilderness of the www. Just can not remember where.

public function ConvertMinutes2Hours($Minutes)
{
   	if ($Minutes < 0)
   	{
   	    $Min = Abs($Minutes);
   	}
   	else
   	{
   	    $Min = $Minutes;
   	}
   	$iHours = Floor($Min / 60);
   	$Minutes = ($Min - ($iHours * 60)) / 100;
   	$tHours = $iHours + $Minutes;
   	if ($Minutes < 0)
   	{
   	    $tHours = $tHours * (-1);
   	}
   	$aHours = explode(".", $tHours);
   	$iHours = $aHours[0];
   	if (empty($aHours[1]))
   	{
   	    $aHours[1] = "00";
   	}
   	$Minutes = $aHours[1];
   	if (strlen($Minutes) < 2)
   	{
   	    $Minutes = $Minutes ."0";
   	}
   	$tHours = $iHours .":". $Minutes;
   	return $tHours;
}

Link to comment
Share on other sites

  • 4 weeks later...
  • Moderators

This is pretty cool and works like a charm. The only issue I am having is getting a list of pilots from a hub to show up. I have my table built, just not sure how it needs to pull info for the pilots.

Hey, here's the code that I ripped off from my Hub Module for the Pilots Per Hub.

<?php $pilots = PilotData::getAllPilotsByHub('CYYC'); ?>
<?php
if(!$pilots)
{
	echo 'There are no pilots in that hub, so there must be at least one pilot so the hub can run.';
	return;
}
?>
<table width="800" border="0">
 <tr>
   <td width="350"><table width="669" border="0">
   <tr>
       <th width="212"><div align="center"><u>Pilot ID</u></div></th>
       <th width="185"><u>Pilot Name</u></th>
       <th width="210"><u>Rank</u></th>
       <th width="210"><u>Total Hours</u></th>
       <th width="210"><u>Total Flights</u></th>
   </tr>
   <?php
   foreach ($pilots as $pilot) {
   ?>
       <tr>
           <td align="left"><div align="center"><a href="<?php echo url('/profile/view/'.$pilot->pilotid);?>">
           <?php echo PilotData::GetPilotCode($pilot->code, $pilot->pilotid)?></a></div></td>
           <td><div align="center"><?php echo $pilot->firstname.' '.$pilot->lastname?></div></td>
           <td><div align="center"><?php echo $pilot->rank;?></div></td>
           <td><div align="center"><?php echo $pilot->totalhours; ?></div></td>
           <td><div align="center"><?php echo $pilot->totalflights; ?></div></td>
       </tr>
   <?php
   }
   ?>
</table>
</td>
</tr>
</table>



It's a starch code from my Hub Module....

Change the Hub ICAO from the Line...

<?php $pilots = PilotData::getAllPilotsByHub('CYYC'); ?>

To your current Hub ICAO.

  • Like 2
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...