Jump to content
Tom

HubStats Class

Recommended Posts

Yarrhar!!!

You are the awesome!!!

I'll give it a run when I get home.

Thank you for doing it. :D

Share this post


Link to post
Share on other sites

Easy as Pie!!!!

Here's an example......

<?php echo HubStats::CountPilots(CYYC); ?>

<?php echo HubStats::CountFlights(CYYC); ?>

Hope you get it.

  • Like 1

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Ok i had it work just tossed it up on a page and it worked i deleted it and now when i redo what i tryed it just shows the code instead of the echo. Not sure what I have done wrong

Share this post


Link to post
Share on other sites

Your ASP Tag is not on, try that......

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

Share this post


Link to post
Share on other sites

Here's an example!!!

I skinned to my Hub Modules that I made and All the stats in!! Thanks Tom!!!

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Hey Tom, We haven't made any flights yet so no problem, I'm still working on my VA. I plan to open it in the Springish hopefuly my timeline will be nice.

Share this post


Link to post
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.

Share this post


Link to post
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 ;)

Share this post


Link to post
Share on other sites

Make sure the module is there and in the correct place. You can also use the code I gave. It is great for if you have multiple hubs.

Share this post


Link to post
Share on other sites

Delete the hubstats class file, and download it from here again, the file may have gotten corrupted while being downloaded. Looks like it is trying to find the

HubStats::CountFlights('EDDF');

and not finding it.

Share this post


Link to post
Share on other sites

Check your capitalisation too. In your quote it's looking for HubStats::countflights(), and it should be HubStats::CountFlights().

Share this post


Link to post
Share on other sites

In his code it is correct, I think maybe something got corrupted during his upload or download, or that is php doing something funny.

Share this post


Link to post
Share on other sites

Just have a look at Sim pilots averages how he call then then add another public function to Tom's class :)

Good idea though, if i get change ill do it for my VA an post the code if im not beaten to it.

Share this post


Link to post
Share on other sites

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)

  • Like 1

Share this post


Link to post
Share on other sites

Ha well why didn't you say :lol:

Looks like im going to be a busy bee ;)

Cheers Jeff that's great and reduced calls to the database.

Top man....

That's an interesting one,

$ret->departures

$ret->arrivals

Hey dood where's my plane :lol:

Share this post


Link to post
Share on other sites

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;
}

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×