Jump to content

Recommended Posts

Posted

I think it would be real sweet if we could show hub finance stats as well such as how much money the hub has made and how much was spent on fuel. I am not so sure we will ever be able to do that though.

But on another note, thank you all very much for working on this and helping so many of us out with it. I really appreciate it! I have been wanting to add hub pages for quite some time now. This is the icing on the cake for me.

Thanks!

Ray

Guest lorathon
Posted

I think it would be real sweet if we could show hub finance stats as well such as how much money the hub has made and how much was spent on fuel. I am not so sure we will ever be able to do that though.

But on another note, thank you all very much for working on this and helping so many of us out with it. I really appreciate it! I have been wanting to add hub pages for quite some time now. This is the icing on the cake for me.

Thanks!

Ray

TAV,

Did you look at the function that I posted in this thread? It has the items you are looking for. Look up a few posts.

Posted

TAV,

Did you look at the function that I posted in this thread? It has the items you are looking for. Look up a few posts.

I must have read it wrong. I will go back and look. Thanks for pointing that out to me.

Posted

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)

Where does this little ditty of code go?

I am looking at it but not sure where to place it and when I do how to call it on a tpl file to show info.

This is very interesting to say the least.

Guest lorathon
Posted

You can put it directly into Tom's HubStats Class. It can then be called as such.....

<?php
$hub = "KLAX";
$stats = HubStats::getHubStats($hub);
?>

The $stats array will then be filled with the info I have shown in $ret.

$stats->total.... etc....

Posted

I can't seem to get it to work. I placed that info in the hubstats and then placed the call in the tpl file and nothing is coming up. I am 100% sure it is not the code....It is the end user as usual. :blink:;)

Guest lorathon
Posted

Here is how to debug. It might be that I have left something in that is not standard for phpVMS. I have added quite a bit to my copy that I always seem to forget what was original and what was modified. Any way replace the above with the following until you can get the bugs worked out.

This will stop it from loading the cached version (very necessary for debugging) and also display any MySql errors that are generated. (Like I said I may have left something in there :) )

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

               echo DB::$error;

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

Guest lorathon
Posted

On the template add the following

print_r(HubStats::getHubStats($hubicao));

This will print to the screen all data that is returned (if any)

Posted

On the template add the following

print_r(HubStats::getHubStats($hubicao));

This will print to the screen all data that is returned (if any)

Tried the code you just gave and it was a no go.

I then added the print function and came up with this.

stdClass Object ( [total] => 0 [landAvg] => [gross] => [expenses] => [pilotpay] => [revenue] => [pax] => [fuelused] => [fuelprice] => [fuelAvg] => [time] => [distance] => [pilots] => 0 [departures] => 0 [arrivals] => 0 [airframes] => 0 )

Posted

Tried the code you just gave and it was a no go.

I then added the print function and came up with this.

stdClass Object ( [total] => 0 [landAvg] => [gross] => [expenses] => [pilotpay] => [revenue] => [pax] => [fuelused] => [fuelprice] => [fuelAvg] => [time] => [distance] => [pilots] => 0 [departures] => 0 [arrivals] => 0 [airframes] => 0 )

Same here,

Regards,

Cor

Guest lorathon
Posted

TAV - Try this in the template. (This should pull the stats for hub St Louis)

<?php
print_r(HubStats::getHubStats('KSTL'));
?>

COR - Try this in the template. (this should pull the stats for hub San Fransisco)

<?php
print_r(HubStats::getHubStats('KSFO'));
?>

Posted

I actually put an the hub code. I just think I did the code wrong.

I tried it again and came up with

stdClass Object ( [total] => 6 [landAvg] => -211.833333333333 [gross] => 75608 [expenses] => 100 [pilotpay] => 168 [revenue] => 51073.9459228516 [pax] => 392 [fuelused] => 25123.200012207 [fuelprice] => 24203.2344360352 [fuelAvg] => 1.03801002624683 [time] => 533.0000 [distance] => 3045 [pilots] => 1 [departures] => 3 [arrivals] => 4 [airframes] => 3 )

That time it worked. Thanks Lor.

Posted

Im looking to do this but I am a noob and no coding knowledge........We operate FBO's which has 3 airports for each region, So what I am looking to do is insert 3 airports for each stat ,I am willing to pay for some one to do this....

West Coast Region Central Region East Coast Region

thanks in advance

Regards,

Allan

  • 2 weeks later...
  • 8 months later...
  • 1 month later...
Posted

I am trying to put this into an externalt page, I have writtne a basic module to call a tpl file, but it says it is trying to call to an undefine method HubStats::gethubstats. But I have it in the hubstats class file, and it is properly cased. I have changed the hubicao to just icao. Anyone know how to fix this?

[url="http://malaysiava.org/index.php/hubstats#"]Fatal[/url] error:  [url="http://malaysiava.org/index.php/hubstats#"]Call[/url] to undefined method HubStats::gethubstats() in /home/globalai/public_html/malaysiava.org/lib/skins/cityportal/hubstats.tpl on line 4

  • 4 weeks later...
Posted

Hi Tom,

Don't suppose you still have the full php code do you please? I can't download it from the original post and really need it for my site as we were running it before.

Thanks,

Thomas.

  • 1 month later...
Posted

How do I have the stats to show whle nmbers for the hours?

Fairbanks Pilots:55
Fairbanks Flights: 1194
Fairbanks Hours: 1846.019999999998

You can use round() to round it to however many places you'd like :)

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