Jump to content

TouchdownStats 1.0


simpilot

Recommended Posts

  • 2 weeks later...

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

Link to comment
Share on other sites

  • 2 weeks later...
  • 3 weeks later...

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

Link to comment
Share on other sites

  • Administrators

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.

Link to comment
Share on other sites

  • Administrators

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.

Link to comment
Share on other sites

  • 3 weeks later...

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

Link to comment
Share on other sites

  • Administrators

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'

Link to comment
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!

Link to comment
Share on other sites

  • 3 weeks later...
  • Moderators

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.

Link to comment
Share on other sites

  • 2 weeks later...

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

Link to comment
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?!

Link to comment
Share on other sites

  • 2 weeks later...
  • Moderators

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.

Take a look here

http://forum.phpvms.net/topic/2989-touchdownstats-10/page__view__findpost__p__29230

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