Jump to content

TouchdownStats 1.0


simpilot

Recommended Posts

You can add a WHERE statement to the sql call to only pull data that matches the month you want.

something like ->

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

return DB::get_results($query);
}

$month would be the numerical representation of the month you want. Probably will want to name the year as well or you will get the data from that month for every year that is in the db.

If I write another version I will include some monthly stats capability.

where i put this code ???

Link to comment
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(); ?>

I did all this but how would I get the data to show the pilot's avg rate in their crew center? I want it to automatically get the pilot id.

Link to comment
Share on other sites

  • Administrators

Any help?

You have copied the necessary code into your post

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

Replace the 'pilot#' with the variable that contains the raw pilot id from the database for the page that you are on, it varies from page to page and is unavailable on some.

Link to comment
Share on other sites

  • 6 months later...

sorry is this covered? i want to display the top 10 landing rates of the current month here http://skybahamasvirtual.net/index.php/TouchdownStats

So i don't want that full table i just wanna replace all codes with what needs to be added in an taken out. I don't want to take out or add in the wrong info So i do apologies if i asked for a bit too much.

This is the Template:

<h2>Top 10 Landings for <?php echo date("F Y");?> NOTE* Landing Rates -600 and Below were not accepted</h2>
<br>
<br>
<br>
<?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 (c) 2009-2010, David Clark
//@license http://creativecommons.org/licenses/by-nc-sa/3.0/
?>
<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>';
    }
?>

This is the TouchdownStatsData.class.php

<?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 (c) 2009-2010, David Clark
//@license http://creativecommons.org/licenses/by-nc-sa/3.0/
class TouchdownStatsData extends CodonData  {
   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);
   }

   public function get_airline_stats($airline) {
    $query = "SELECT * FROM `".TABLE_PREFIX."pireps`
			    WHERE landingrate < '0'
			    AND code = '$airline'
			    ORDER BY landingrate DESC";
    return DB::get_results($query);
   }

   public function get_worst_stats($howmany) {
    $query = "SELECT pilotid, code, flightnum, depicao, arricao, aircraft, landingrate, submitdate FROM `".TABLE_PREFIX."pireps`
			    WHERE landingrate < '0'
			    ORDER BY landingrate ASC
			    LIMIT $howmany";
    return DB::get_results($query);
   }

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

   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;
    if(!empty($stats))
    {
	    foreach ($stats as $stat)
		    {
		    $total = $total + $stat->landingrate;
		    $count++;
	    }
	    return $total / $count;
    }
    else
    {return '0';}
   }
   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;
   }
}

This is the TouchdownStats.php

<?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 (c) 2009-2010, David Clark
//@license http://creativecommons.org/licenses/by-nc-sa/3.0/
class TouchdownStats extends CodonModule {
   public function index() {
    $this->set('stats', TouchdownStatsData::get_all_stats());
    $this->show('touchdownstats/touchdownstats_index.tpl');
   }
   public function top_landings($howmany)  {
    $this->set('stats', TouchdownStatsData::get_stats($howmany));
    $this->show('touchdownstats/touchdownstats_index.tpl');
   }
}

Link to comment
Share on other sites

Curshad, you want this? limit the number of row pilots?

How i can limit the number of the tochdownstats 10 pilots to 5 pilot.

Not sure exactly what you are looking for but the function "top_landings($howmany)" will return the top landings in order and limit it by the "$howmany" variable.

Link to comment
Share on other sites

  • 4 weeks later...
  • 3 months later...

Hii,

I'm using Monthly Touch Down Rates in my homepage limited by 5. Hovewer, some pilots have really really good T/D rates. For example;

Pilot A: -9,-12-15

Pilot B: -23,-26

Pilot C: -30,-34

Pilot D:-40,-41,43

Pilot E:-45,-47

The output automatically shows

Pilot A:-9

Pilot A:-12

Pilot A:-15

Pilot B:-23

Pilot B:-26

Now: I would like to show Top 5 pilots top rate.Any pilot's rates should not repeated. I want to show only the best one so more pilots can enter the list . Example:

Pilot A:-9

Pilot B:-23

Pilot C:-30

Pilot D:-40

Pilot E:-45

I Mean Top 5 Pilots greatest landing according to that month.

How Should I Change the codes?

Thanks,

Kıvanç

Link to comment
Share on other sites

  • Administrators

Maybe something like this as a new function in your data class:

public static function get_unique_monthly($month, $year, $howmany)    {
$query = "SELECT pilotid, code, flightnum, depicao, arricao, aircraft, MAX(landingrate) as landingrate, submitdate FROM `".TABLE_PREFIX."pireps`
		    WHERE landingrate < '0'
		    AND MONTH(submitdate) = $month
		    AND YEAR(submitdate) = $year
		    GROUP BY pilotid
		    ORDER BY landingrate DESC
		    LIMIT $howmany";

return DB::get_results($query);
}

Link to comment
Share on other sites

  • 1 month later...

What is your website url? The errors means that the variable which is called from the foreach does not have any data. Have your pilots sent any flights on your virtual airline using acars?

We still making the web so no reports were sent yet. So I will post again when I hace a report

Link to comment
Share on other sites

  • Moderators

So that's the case. The variable that is used on the foreach does not include any data (there are not any reports on your system) and that's why it returns an error. You can add the foreach inside an if statement if you wish to remove the error. Of course, the error will disapear as soon as someone sends a flight on your system.

Link to comment
Share on other sites

On my website how can I show in this table the stats of the best landings of the month?

<div class="art-postcontent art-postcontent-0 clearfix"><div class="art-content-layout-wrapper layout-item-0">
<div class="art-content-layout layout-item-1">
<div class="art-content-layout-row">
<div class="art-layout-cell layout-item-2" style="width: 100%" >
<div class="art-blockheader">
<h3 class="t">Mejores tomas del mes</h3>
</div>
<p style="color: rgb(46, 59, 62);">
Here must be the table/graph </p>
</div>
</div>

Link to comment
Share on other sites

  • Administrators

On my website how can I show in this table the stats of the best landings of the month?

<div class="art-postcontent art-postcontent-0 clearfix"><div class="art-content-layout-wrapper layout-item-0">
<div class="art-content-layout layout-item-1">
<div class="art-content-layout-row">
<div class="art-layout-cell layout-item-2" style="width: 100%" >
<div class="art-blockheader">
<h3 class="t">Mejores tomas del mes</h3>
</div>
<p style="color: rgb(46, 59, 62);">
Here must be the table/graph </p>
</div>
</div>

The information is in the thread on the second page.

Link to comment
Share on other sites

It has come up inside this thread. Search and you will find a solution. ;)

Yep I read that and I did it, but the page doesn´t work, I mean when I go to index.php/TouchDownStats there it works, but when I return to the main page on the table I showed before, it shows array, I didn´t find any solution yet, applying also the topic "solutions"

Link to comment
Share on other sites

  • 1 month later...

Maybe something like this as a new function in your data class:

public static function get_unique_monthly($month, $year, $howmany) {
$query = "SELECT pilotid, code, flightnum, depicao, arricao, aircraft, MAX(landingrate) as landingrate, submitdate FROM `".TABLE_PREFIX."pireps`
		 WHERE landingrate < '0'
		 AND MONTH(submitdate) = $month
		 AND YEAR(submitdate) = $year
		 GROUP BY pilotid
		 ORDER BY landingrate DESC
		 LIMIT $howmany";

return DB::get_results($query);
}

I have just noticed something related to this.

When data is listed, only name and touchdown is correct. Arr icao and plane are wrong. It takes pilots first flight.

For example:

Pilots first flights is:

Oytun B737-600 VQPR -20 ft/m 04/02

Second one is:

Oytun B737-800 KJFK -12 ft/m 06/02

On the list:

Oytun B737-600 VQPR -12 ft/m 04/02

The correct one must be Second one on the list but it is not.

How can I solve this one?

Link to comment
Share on other sites

Here is my Touchdownstatsdataclass.php :

public function tdunic () {

		 $query = "SELECT pirepid, pilotid, code, flightnum, depicao, arricao, aircraft, MAX(landingrate) as landingrate, submitdate FROM `".TABLE_PREFIX."pireps`
				 WHERE landingrate < '0'
				 AND MONTH(submitdate)=MONTH(now())
				 AND YEAR(submitdate)=YEAR(now())

 GROUP BY pilotid

						 ORDER BY landingrate DESC
						 LIMIT 5";
 return DB::get_results($query);
 }

Here is my touchdowns.php :

<?php $stats = TouchdownStatsData::tdunic();
if ($stats) { ?>
<table class="table table-condensed">
<tr>
 <th>Pilot</th>
 <th>Aircraft</th>
 <th>Arrival</th>
 <th>V/S</th>
 <th>Date</th>
</tr>
<?php



foreach($stats as $stat)
 {

		 $pilot = PilotData::getPilotData($stat->pilotid);
		 $aircraft = OperationsData::getAircraftInfo($stat->aircraft);
		 echo '<tr>';
		 echo '<td>'.$pilot->firstname.'</td>';
		 echo '<td>'.$aircraft->name.'</td>';
		 echo '<td>'.$stat->arricao.'</td>';
		 echo '<td><font color="red">'.$stat->landingrate.' ft/m</font></td>';
		 echo '<td>'.date('d/m', strtotime($stat->submitdate)).'</td>';
		 echo '</tr>';

 }
}else {
echo 'No ' . date('F') . ' Flights Recorded';
}


?>
</table>

Here is my frontpagemain.php :

<?php MainController::Run('content', 'pilotlandings', '5'); ?>

Link to comment
Share on other sites

Hello everyone just need little help if for example from touchdown table i wanted to skip any of the aircraft how should i get the final result.

from all the touchdowns i wanted one or more aircraft should not show up what will be the code i can use to skip any aircraft?

i used this code but still no luck

<?php
   foreach($stats as $stat)
   {
    $pilot = PilotData::getPilotData($stat->pilotid);
    $aircraft = OperationsData::getAircraftInfo($stat->aircraft);
    If($aircraft->code == “C172â€) { Continue; } else {
    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>';
   }
}
?>

Thank you

Link to comment
Share on other sites

  • 3 weeks later...
  • 3 months later...
  • 1 month later...

Hi all,

Not sure if anyone else has had this problem but I am getting this error above the landing stats

Deprecated: Non-static method TouchdownStatsData::get_stats_by_cur_month() should not be called statically, assuming $this from incompatible context in /home/angelair/public_html/test/core/modules/TouchdownStats/TouchdownStats.php on line 36

I have tried to add this to the Touchdownstats.php

public static function top_landing_this_month () {

but that just breaks the frontpage.

any ideas for a workaround?

Thanks in advance

Scott

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