Jump to content
simpilot

TouchdownStats 1.0

Recommended Posts

I have noticed this addon isn't pulling the stats any longer...Any ideas...The landing stats aren't updating.

Things seem to be working on my site, is it not showing any, or just the latest?

Share this post


Link to post
Share on other sites

I had a super great landing in one of my aircraft don't remember which now and the system didn't update it.

UPdate: Ok I found it. I had a landing in my B103 of-23 and it doesn't appear in the stats at all for that aircraft. and of course its the top landing for it. THE ONLY DIFFERENCE IS I USED "FSX" FOR THE FIRST TIME

Share this post


Link to post
Share on other sites

Some how you have landed with a + rate not a - rate, this happens sometimes,if you look at the pirep its at 15fpm not -15fpm if you get what i mean, just go in to the database and edit that field to a -15 and it should show up

Share this post


Link to post
Share on other sites

@SimPilot: I was getting an error in your default installation that said it was the wrong argument in foreach, exactly the line where you iterate through statistical records returned by the data layer.

I have no PIREPs filed in my system as I want to iron out all system quirks before doing PR. I found a slight oversight in your code that could be fixed by changing that PHP code in touchdownstats_index.tpl as follows:

<?php
   if ($stats === NULL)
   {
   	echo '<tr><td colspan="5">No PIREPS match search criteria</td></tr>';
   }
   else 
   {
    foreach($stats as $stat)
    {
        $pilot = PilotData::getPilotData($stat->pilotid);
        $aircraft = OperationsData::getAircraftInfo($stat->aircraft);
        echo '<tr>';
        echo '<td>'.PilotData::getPilotCode($pilot->code, $pilot->pilotid).' - '.$pilot->firstname.' '.$pilot->lastname.'</td>';
        echo '<td>'.$aircraft->fullname.'</td>';
        echo '<td>'.$stat->arricao.'</td>';
        echo '<td>'.$stat->landingrate.'</td>';
        echo '<td>'.date(DATE_FORMAT, strtotime($stat->submitdate)).'</td>';
        echo '</tr>';
    }
    }	    
?>

It is always good to check for NULLs ;-)

Also decided to add this to the table code above that script as follows:

<table ....>
   <caption>Touchdown Statistics</caption>
   :
</table>

Share this post


Link to post
Share on other sites

How can you iron out kinks in a statistical function when there are no stats (or pireps in this case) to examine? The module was not designed to work on a vs site with no pireps. As far as adding a caption, I try to leave template files as bland and generic as possible at this point to make it as easy as I can for members to integrate the module into their own skin.

Share this post


Link to post
Share on other sites

Is there a way to display the pilots top 25 greased landings?

I created a data call for vACA for individual pilot stats in my touchdownstatsData.php file like this ->

public function get_pilot_landingstats($pilot, $howmany)    {
       $query = "SELECT *
               FROM   phpvms_pireps
               WHERE landingrate <'0'
               AND pilotid = '$pilot' 
               ORDER BY landingrate DESC
               LIMIT $howmany;";

       return DB::get_results($query);
   }

Then in your module you can set the variable using something like ->

$this->set('stats' = TouchdownstatsData::get_pilot_landingstats($pilotid, 5);

You will just need to load the $pilotid ahead of it to call the pilot you are looking for, and the '5' is how many records you want returned in the array.

Share this post


Link to post
Share on other sites

Add this to TouchdownstatsData ->

public function pilot_stats($pilotid)   {
       $query = "SELECT pilotid, code, flightnum, depicao, arricao, aircraft, landingrate, submitdate FROM `".TABLE_PREFIX."pireps`
                   WHERE landingrate < '0'
                   AND pilotid = '$pilotid'
                   ORDER BY landingrate DESC";

       return DB::get_results($query);
   }

   public function pilot_average($pilotid) {
       $stats = self::pilot_stats($pilotid);
       $total = 0;
       $count = 0;

       foreach ($stats as $stat)
           {
           $total = $total + $stat->landingrate;
           $count++;
       }
       $average = $total / $count;

       return $average;
   }

   public function airline_average() {
       $stats = self::get_all_stats();
       $total = 0;
       $count = 0;

       foreach ($stats as $stat)
           {
           $total = $total + $stat->landingrate;
           $count++;
       }
       $average = $total / $count;

       return $average;
   }

Then where you want to show a pilots average do ->

<?php echo 'Pilot average landing rate '.TouchdownStatsData::pilot_average('pilot#'); ?>

and replace pilot# with the database id for the pilot you want to show the stat for - ie in pilot_public_profile it would be $userinfo->pilotid

or for the VA's average ->

<?php echo 'VA average landing rate '.TouchdownStatsData::airline_average(); ?>

Hey Simpilot,

I was wondering if it's possible to show the average landingrate for the year 2010 and for this year, 2011 ?

All the best wishes by the way!!

Regards

Lucas

Share this post


Link to post
Share on other sites

Hey Simpilot,

I was wondering if it's possible to show the average landingrate for the year 2010 and for this year, 2011 ?

All the best wishes by the way!!

Regards

Lucas

You can follow the structure you quoted above and just change the call to the database to collect only records from the year you want and the loop thorugh and average them. The native cache function probably should be used if the va has a substantial number of pireps, if not it will slow things down everytime someone views that page for the server to recalculate the stat.

WHERE YEAR(submitdate) = '2010'

Share this post


Link to post
Share on other sites

You can follow the structure you quoted above and just change the call to the database to collect only records from the year you want and the loop thorugh and average them. The native cache function probably should be used if the va has a substantial number of pireps, if not it will slow things down everytime someone views that page for the server to recalculate the stat.

WHERE YEAR(submitdate) = '2010'

Aren't you getting tired of being right all the time ;-) hahahaha

Thanks!

Share this post


Link to post
Share on other sites

Im being really lazy here but could someone tell me how to get the variable $pilotid loaded, ps im in the profile main tpl.

<li><strong><?php echo 'Your Average Landing Rate: '.round(TouchdownStatsData::pilot_average($pilotid), 2); ?></strong></li>

Share this post


Link to post
Share on other sites

No worries i have the variable :)

<li><strong><?php echo 'Your Average Landing Rate: '.round(TouchdownStatsData::pilot_average($userinfo->pilotid), 2); ?></strong></li>

Share this post


Link to post
Share on other sites

Dave,

I have been trying to get this to display on the top pilot page for hours now, i just cant seem to get it.

<h3>Top 10 Landings for <?php echo date("F Y");?></h3> 
<table width="700" border="1" cellspacing="1" cellpadding="1">
   <tr>
       <th>Pilot</th>
       <th>Aircraft</th>
       <th>Arrival Field</th>
       <th>Landing Rate</th>
       <th>Date Flown</th>
   </tr>

<?php
   foreach($stats as $stat)
   {
       $pilot = PilotData::getPilotData($stat->pilotid);
       $aircraft = OperationsData::getAircraftInfo($stat->aircraft);
       echo '<tr>';
       echo '<td>'.PilotData::getPilotCode($pilot->code, $pilot->pilotid).' - '.$pilot->firstname.' '.$pilot->lastname.'</td>';
       echo '<td align="center">'.$aircraft->fullname.'</td>';
       echo '<td align="center">'.$stat->arricao.'</td>';
       echo '<td align="center">'.$stat->landingrate.'</td>';
       echo '<td align="center">'.date(DATE_FORMAT, strtotime($stat->submitdate)).'</td>';
       echo '</tr>';
   }
?>
</table>

I have added a new call to the module TouchdownStats.php,

    }
   public function top_landing_this_month () {
       $this->set('stats', TouchdownStatsData::get_stats_by_cur_month());
       $this->show('touchdownstats/touchdownstats_index.tpl');

And also a new sql query to the TouchdownStatsData.class.php

//added By Mark Grant 03-02-2011
public function get_stats_by_cur_month () {
       $query =  "SELECT pilotid, code, flightnum, depicao, arricao, aircraft, landingrate, submitdate FROM `".TABLE_PREFIX."pireps`
              WHERE landingrate < '0' 
		AND MONTH(submitdate)=MONTH(now())
		AND YEAR(submitdate)=YEAR(now())
		ORDER BY landingrate DESC
		LIMIT 10";

return DB::get_results($query);
   }

Everything works fine when i use the url to call, http://www.easyjetva.com/index.php/TouchdownStats/top_landing_this_month but when i add that code to the tp_index.php i keep getting Invalid argument supplied for foreach(), i have tried renaming the variables but i cant seem to get it, any help would be appreciated.

Thanks.

Share this post


Link to post
Share on other sites

Mark

There are a couple of ways, the easiest may be to put this in your tp_index.tpl page where you want the table to display;

<?php MainController::Run('TopPilot', 'top_landing_this_month '); ?>

Share this post


Link to post
Share on other sites

Hey guys, I'm trying to install the average landing function, it works for pilots who have flights logged, but for pilots with no flights yet it shows this:

Warning: Invalid argument supplied for foreach() in /home/flynryan/public_html/allegiantvirtual.com/core/common/TouchdownStatsData.class.php on line 30

Warning: Division by zero in /home/flynryan/public_html/allegiantvirtual.com/core/common/TouchdownStatsData.class.php on line 35

Your Average Landing Rate: 0

my touchdown stats data class

<?php

//simpilotgroup addon module for phpVMS virtual airline system

//

//simpilotgroup addon modules are licenced under the following license:

//Creative Commons Attribution Non-commercial Share Alike (by-nc-sa)

//To view full license text visit http://creativecommons.org/licenses/by-nc-sa/3.0/

//

//@author David Clark (simpilot)

//@copyright Copyright © 2009-2010, David Clark

//@license http://creativecommons.org/licenses/by-nc-sa/3.0/

class TouchdownStatsData extends CodonData

{

public function pilot_stats($pilotid) {

$query = "SELECT pilotid, code, flightnum, depicao, arricao, aircraft, landingrate, submitdate FROM `".TABLE_PREFIX."pireps`

WHERE landingrate < '0'

AND pilotid = '$pilotid'

ORDER BY landingrate DESC";

return DB::get_results($query);

}

public function pilot_average($pilotid) {

$stats = self::pilot_stats($pilotid);

$total = 0;

$count = 0;

foreach ($stats as $stat)

{

$total = $total + $stat->landingrate;

$count++;

}

$average = $total / $count;

return $average;

}

public function airline_average() {

$stats = self::get_all_stats();

$total = 0;

$count = 0;

foreach ($stats as $stat)

{

$total = $total + $stat->landingrate;

$count++;

}

$average = $total / $count;

return $average;

}

public function get_all_stats() {

$query = "SELECT pilotid, code, flightnum, depicao, arricao, aircraft, landingrate, submitdate FROM `".TABLE_PREFIX."pireps`

WHERE landingrate < '0'

ORDER BY landingrate DESC";

return DB::get_results($query);

}

public function get_stats($howmany) {

$query = "SELECT pilotid, code, flightnum, depicao, arricao, aircraft, landingrate, submitdate FROM `".TABLE_PREFIX."pireps`

WHERE landingrate < '0'

ORDER BY landingrate DESC

LIMIT $howmany";

return DB::get_results($query);

}

}

any help appreciated

Share this post


Link to post
Share on other sites

Hi thats normal, just put this at the top of that tpl

<?php error_reporting(0); ?>

What the error saying is correct devision by zero as it has nothing to devide to make an average :)

Share this post


Link to post
Share on other sites

Sorry, but how do I round to 2 decimal places again for:

<?php echo 'VA average landing rate '.TouchdownStatsData::airline_average(); ?>

Share this post


Link to post
Share on other sites

<li><strong><?php echo 'Your Average Landing Rate: '.round(TouchdownStatsData::pilot_average($userinfo->pilotid), 2); ?></strong></li>

That works fine, but I want the other to do the same!?

<?php echo 'VA average landing rate '.TouchdownStatsData::airline_average(); ?>

<li><strong><?php echo 'VA average landing rate: '.round(TouchdownStatsData::airline_average(), 2); ?></strong></li>

That doesn't seem to work?!

Share this post


Link to post
Share on other sites

Hello all!

I 'm making the new pilot_public_profile.tpl for my va and i would like to get the last 5 landings per pilot. So if i m looking at pilot 25 i would like to see the last 5 landings for this pilot.

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

×