Tom Posted February 7, 2011 Report Posted February 7, 2011 To display various stats per hub: Readme + File available on GitHub: https://github.com/t...erritt/HubStats I think that pretty much covers everything? Enjoy 6 Quote
Moderators Kyle Posted February 7, 2011 Moderators Report Posted February 7, 2011 Yarrhar!!! You are the awesome!!! I'll give it a run when I get home. Thank you for doing it. Quote
smoke2312 Posted February 7, 2011 Report Posted February 7, 2011 Can you explain to me how i use this module.... I am not that good with the code just yet Quote
Moderators Kyle Posted February 7, 2011 Moderators Report Posted February 7, 2011 Easy as Pie!!!! Here's an example...... <?php echo HubStats::CountPilots(CYYC); ?> <?php echo HubStats::CountFlights(CYYC); ?> Hope you get it. 1 Quote
Tom Posted February 7, 2011 Author Report Posted February 7, 2011 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. 1 Quote
smoke2312 Posted February 7, 2011 Report Posted February 7, 2011 Thanks so much works like a charm... now I need to configure a table for it Quote
flyalaska Posted February 7, 2011 Report Posted February 7, 2011 I been looking for something like this from day one. TY!! Quote
smoke2312 Posted February 7, 2011 Report Posted February 7, 2011 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 Quote
Moderators Kyle Posted February 7, 2011 Moderators Report Posted February 7, 2011 Your ASP Tag is not on, try that...... <?php echo HubStats::CountPilots('EGKK'); ?> Quote
Moderators Kyle Posted February 8, 2011 Moderators Report Posted February 8, 2011 Here's an example!!! I skinned to my Hub Modules that I made and All the stats in!! Thanks Tom!!! Quote
Tom Posted February 8, 2011 Author Report Posted February 8, 2011 >.< 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. Quote
Moderators Kyle Posted February 8, 2011 Moderators Report Posted February 8, 2011 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. Quote
Strider Posted February 8, 2011 Report Posted February 8, 2011 <?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. Quote
dimitris Posted February 8, 2011 Report Posted February 8, 2011 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 Quote
Strider Posted February 8, 2011 Report Posted February 8, 2011 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. Quote
dimitris Posted February 8, 2011 Report Posted February 8, 2011 module is here :/ but no success... again the same Quote
Strider Posted February 8, 2011 Report Posted February 8, 2011 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. Quote
Tom Posted February 8, 2011 Author Report Posted February 8, 2011 Check your capitalisation too. In your quote it's looking for HubStats::countflights(), and it should be HubStats::CountFlights(). Quote
Strider Posted February 9, 2011 Report Posted February 9, 2011 In his code it is correct, I think maybe something got corrupted during his upload or download, or that is php doing something funny. Quote
md82 Posted February 12, 2011 Report Posted February 12, 2011 Is it possible we could have average landing stats for each hub ? Quote
Moderators mark1million Posted February 12, 2011 Moderators Report Posted February 12, 2011 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. Quote
Guest lorathon Posted February 12, 2011 Report Posted February 12, 2011 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) Quote
Moderators mark1million Posted February 12, 2011 Moderators Report Posted February 12, 2011 Ha well why didn't you say 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 Quote
Guest lorathon Posted February 13, 2011 Report Posted February 13, 2011 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; } Quote
TAV1702 Posted March 7, 2011 Report Posted March 7, 2011 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. Quote
Moderators Kyle Posted March 7, 2011 Moderators Report Posted March 7, 2011 On 3/7/2011 at 12:15 AM, TAV1702 said: 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. 2 Quote
TAV1702 Posted March 7, 2011 Report Posted March 7, 2011 Thanks Vansers. I will give that a go. I really appreciate it. +1 1 Quote
TAV1702 Posted March 7, 2011 Report Posted March 7, 2011 Worked like a charm! Thank you very much! 1 Quote
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.