Jump to content

TouchdownStats 1.0


simpilot

Recommended Posts

  • Administrators

TouchdownStats 1.0

Module to extract and display landing rates from your PIREPS table

----------------------------------------------

A visible link to http://www.simpilotgroup.com must be provided on any webpage utilizing this script for the license to be valid.

----------------------------------------------

Developed by:

simpilot - David Clark

www.simpilotgroup.com

www.david-clark.net

Developed on:

phpVMS 2.1.935

php 5.2.11

mysql 5.0.51

apache 2.2.11

Install:

-Download the attached package.

-unzip the package and place the files as structured in your root phpVMS install.

To show all the landing stats currently in the datbase create a link to

www.yoursite.com/index.php/TouchdownStats

To show a limited number of stats from your database create a link to

www.yoursite.com/index.php/TouchdownStats/top_landings/10

The "10" can be changed to however many you would like to see

The most useful method of the data class would be to use

TouchdownStatsData::get_all_stats()

and

TouchdownStatsData::get_stats('10')

You can use these inside of one of your templates to bring back the data you want and display it as you wish.

An example to fill a variable with data for use in your template you can use

$this->set->('stats', TouchdownStatsData::get_stats('10'));

in your module to pass the data to the template within the $stats variable. Then in your template use the $stats variable to do what you wish with the display.

TouchDownStats Released under the following license:

Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License

Code hosted on Github - Link In Signature.

  • Like 7
Link to comment
Share on other sites

  • Moderators

Yes, awesome! Is it difficult to get the pilots average landings score as well, as a top ten?

Hey, how can i dispaly the landing stats table like on a different page?

i want to dispaly the top 10.

Link to comment
Share on other sites

  • 3 weeks later...

Hi All,

I love this add-on, great work!

Its been a while since I have worked with phpvms and php in general. I cant seem to get this module to show on my front page

I would like to show the best 5 landing rates on the left sidebar of my site I call it using:

<?php echo TouchdownStatsData::get_stats('5'); ?>

But the result just shows the word Array

Would you mind pointing me in the right direction

Link to comment
Share on other sites

  • Administrators

The function does not return anything to echo, it returns a variable filled with the info you requested. An example to use it would be to set the variable, preferably in your module:

$this->set('myvariable', TouchdownStatsData::get_stats('5'));

Then in your template use a foreach command to show what data you want to display:

foreach($myvariable as $variable)
   {
       Do Stuff
   }

To see what is available to echo do a:

print_r($myvariable);

in your template.

If you want to call the data within the template just do:

$myvariable = TouchdownStatsData::get_stats('5');

in your template before you need the info.

Link to comment
Share on other sites

I was looking for the top 10 pilots average for all time, but the more stats the better. Almost like the TopPilot module, but associated as landing stats. Maybe combine them both?! A second table listed below the top pilot data for best monthly touchdown rate, and then a best average as well.

SO, below the top pilot data, it could be:

Best Landing Rate (for month) | Best Landing Rate Average (for month) | Smoothest Pilot (for month)

I don't know, maybe the smoothest pilot could be based on combination of best landing rate + average somehow, possibly with a minimum of 5 flights or something?!

Link to comment
Share on other sites

Hello,

it works very fine but there is an error also at my page:

Warning: Invalid argument supplied for foreach() in /mnt/weba/40/03/52426403/htdocs/core/templates/touchdownstats/touchdownstats_index.tpl on line 21

Im using:

Version 2.1.934

Martin

Link to comment
Share on other sites

  • Administrators

Hello,

it works very fine but there is an error also at my page:

Warning: Invalid argument supplied for foreach() in /mnt/weba/40/03/52426403/htdocs/core/templates/touchdownstats/touchdownstats_index.tpl on line 21

Im using:

Version 2.1.934

Martin

Looks like there is no data coming back from the database. Do you have any PIREPs filed with landing rates?

Link to comment
Share on other sites

  • Administrators

I have the same problem, i usually send manual pireps and I confirm to have landing rates as field .... any help ?

Manual PIREPS do not have a landing rate included to put in the database, generally that is only going to come from an ACARS system PIREP. Check your database to see if there is actually any data in the landing rate column. If there is no data at all in the column you will get the error as there is nothing to make the foreach command work.

Link to comment
Share on other sites

Manual PIREPS do not have a landing rate included to put in the database, generally that is only going to come from an ACARS system PIREP. Check your database to see if there is actually any data in the landing rate column. If there is no data at all in the column you will get the error as there is nothing to make the foreach command work.

Hey I have entered manualy 3 landing rate data in the rate field but all the other fields for the remaining flights have the landing rate still 0

but since I'm using FsCaptain I have its own landing rate fields and table in my phpvms that it might be interesting if I link your add-on to it instead of the phpvms_pireps table. If you could please help me do this because I'm not a programmer and I understand few of coding...

Here's the structure of my FsCaptain table witch is called "flights"

CREATE TABLE IF NOT EXISTS `flights` (
 `id` int(16) unsigned NOT NULL auto_increment,
 `datestamp` datetime NOT NULL default '0000-00-00 00:00:00',
 `UserName` varchar(22) NOT NULL default '',
 `CompanyName` varchar(35) NOT NULL default '',
 `PilotName` varchar(35) NOT NULL default '',
 `FlightId` varchar(10) NOT NULL default '',
 `OnlineNetworkNbr` tinyint(4) NOT NULL default '0',
 `FlightDate` date NOT NULL default '0000-00-00',
 `AircraftName` varchar(50) NOT NULL default '',
 `AircraftType` varchar(5) NOT NULL default '',
 `NbrPassengers` smallint(2) NOT NULL default '0',
 `CargoWeight` varchar(15) NOT NULL default '',
 `Mtow` varchar(15) NOT NULL default '',
 `StartAircraftWeight` varchar(15) NOT NULL default '',
 `EndAircraftWeight` varchar(15) NOT NULL default '',
 `StartFuelQuantity` varchar(15) NOT NULL default '',
 `EndFuelQuantity` varchar(15) NOT NULL default '',
 `DepartureIcaoName` varchar(50) NOT NULL default '',
 `ArrivalIcaoName` varchar(50) NOT NULL default '',
 `DepartureLocalHour` time NOT NULL default '00:00:00',
 `ArrivalLocalHour` time NOT NULL default '00:00:00',
 `DepartureGmtHour` time NOT NULL default '00:00:00',
 `ArrivalGmtHour` time NOT NULL default '00:00:00',
 `TotalBlockTime` time NOT NULL default '00:00:00',
 `TotalBlockTimeNight` time NOT NULL default '00:00:00',
 `TotalAirbornTime` time NOT NULL default '00:00:00',
 `TotalTimeOnGround` time NOT NULL default '00:00:00',
 `TotalDistance` varchar(18) NOT NULL default '',
 `MaxAltitude` varchar(15) NOT NULL default '',
 `CruiseSpeed` varchar(15) NOT NULL default '',
 `CruiseMachSpeed` varchar(15) NOT NULL default '',
 `CruiseTimeStartSec` time NOT NULL default '00:00:00',
 `CruiseTimeStopSec` time NOT NULL default '00:00:00',
 `CruiseFuelStart` varchar(15) NOT NULL default '',
 `CruiseFuelStop` varchar(15) NOT NULL default '',
 `LandingSpeed` varchar(15) NOT NULL default '',
 `LandingPitch` varchar(15) NOT NULL default '',
 `TouchDownVertSpeedFt` float NOT NULL default '0',
 `CaptainSentMayday` tinyint(3) NOT NULL default '0',
 `CrashFlag` tinyint(3) NOT NULL default '0',
 `FlightResult` varchar(15) NOT NULL default '',
 `PassengersOpinion` tinyint(4) NOT NULL default '0',
 `PassengersOpinionText` text NOT NULL,
 `FailureText` text NOT NULL,
 `CasualtiesText` text NOT NULL,
 `PilotBonusText` text NOT NULL,
 `BonusPoints` int(10) NOT NULL default '0',
 `PilotPenalityText` text NOT NULL,
 `PenalityPoints` int(10) NOT NULL default '0',
 PRIMARY KEY  (`id`),
 KEY `datestamp` (`datestamp`),
 KEY `UserName` (`UserName`),
 KEY `CompanyName` (`CompanyName`),
 KEY `PilotName` (`PilotName`),
 KEY `AircraftName` (`AircraftName`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=70 ;

STEPS TO FOLLOW:

1- the first thing to do is to modify both entries ".TABLE_PREFIX." in the file TouchdownStatsData.class.php of your add-on found in the folder "common" to ".flights." is that correct ?

2- to show only the best five I have to open the file TouchdownStats.php and modify the entry at line 15

$this->set('stats', TouchdownStatsData::get_all_stats());

to

$this->set->('stats', TouchdownStatsData::get_stats('5'));

so the whole code would look like this :

<?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_stats('5'));
       $this->show('touchdownstats/touchdownstats_index.tpl');
   }

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

3- Please show me how to change the entries in touchdownstats_index.tpl so it communicates with the "flights" table.

<?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>'.$aircraft->fullname.'</td>';
       echo '<td>'.$stat->arricao.'</td>';
       echo '<td>'.$stat->landingrate.'</td>';
       echo '<td>'.date(DATE_FORMAT, strtotime($stat->submitdate)).'</td>';
       echo '</tr>';
   }
?>

Link to comment
Share on other sites

  • Administrators

@maiochine

You will have to make some changes to the data class to start (TouchdownData.class.php)

this ->

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

would change to something like ->

public function get_all_stats() {
       $query = "SELECT * FROM flights
                   WHERE TouchDownVertSpeedFt < '0'
                   ORDER BY TouchDownVertSpeedFt DESC";

       return DB::get_results($query);
   }

You can leave touchdownstats.php as it is and make changes to your tpl file to reflect the new db column names.

For example in touchdownstats_index.tpl

this->

echo '<td>'.$stat->landingrate.'</td>';

would change to ->

echo '<td>'.$stat->TouchDownVertSpeedFt.'</td>';

All the other variable names will need to be changed to match the db table as well.

Link to comment
Share on other sites

  • Administrators

Is there a quick way to limit this to the month? as you have done with the Toppilot release.

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.

Link to comment
Share on other sites

@simpilot

I have tried the modification you told me about but still have a small issue, please take a look at this result : http://www.cargoitaliavirtual.com/index.php/TouchdownStats/

As you can see there's no pilot name nor aircraft name....

my touchdownstats_index.tpl look like this now

<?php
   foreach($stats as $stat)
   {
       $pilot = PilotData::getPilotData($stat->PilotName);
       $aircraft = OperationsData::getAircraftInfo($stat->AircraftName);
       echo '<tr>';
       echo '<td>'.PilotData::getPilotCode($pilot->UserName, $pilot->PilotName).' - '.$pilot->PilotName.'</td>';
       echo '<td>'.$aircraft->AircraftName.'</td>';
       echo '<td>'.$stat->ArrivalIcaoName.'</td>';
       echo '<td>'.$stat->TouchDownVertSpeedFt.'</td>';
       echo '<td>'.$stat->datestamp.'</td>';
	echo '</tr>';
   }
?>
</table>

could you please help me for this one too ?

thanks again

Link to comment
Share on other sites

  • Administrators

Your PIREP system does not record pilotid or the aircraft id so you are not going to be able to use the native phpVMS functions for callsigns and getting aircraft data from the db.

Without having a db in front of me to work with it looks like the best you may do is something like this ->

<?php 
   foreach($stats as $stat) 
   { 
       echo '<tr>'; 
       echo '<td>'.$stat->PilotName.'</td>'; 
       echo '<td>'.$stat->AircraftName.'</td>'; 
       echo '<td>'.$stat->ArrivalIcaoName.'</td>'; 
       echo '<td>'.$stat->TouchDownVertSpeedFt.'</td>'; 
       echo '<td>'.$stat->datestamp.'</td>'; 
               echo '</tr>'; 
   } 
?> 

also, how do you get a landing rate of +63 ft/min :blink: thats taking off isnt it? lol

Link to comment
Share on other sites

Your PIREP system does not record pilotid or the aircraft id so you are not going to be able to use the native phpVMS functions for callsigns and getting aircraft data from the db.

Without having a db in front of me to work with it looks like the best you may do is something like this ->

<?php 
   foreach($stats as $stat) 
   { 
       echo '<tr>'; 
       echo '<td>'.$stat->PilotName.'</td>'; 
       echo '<td>'.$stat->AircraftName.'</td>'; 
       echo '<td>'.$stat->ArrivalIcaoName.'</td>'; 
       echo '<td>'.$stat->TouchDownVertSpeedFt.'</td>'; 
       echo '<td>'.$stat->datestamp.'</td>'; 
               echo '</tr>'; 
   } 
?> 

also, how do you get a landing rate of +63 ft/min :blink: thats taking off isnt it? lol

Im gonna try this out and see what I can get !

I dont know how the landing rate works !!! it shouldn't be -120 ft/m it should be 120ft/m but eh +69 I have no idea how that was since I was not flying that flight :rolleyes:

Link to comment
Share on other sites

also, how do you get a landing rate of +63 ft/min :blink: thats taking off isnt it? lol

Maybe he landed upside down. :huh:

This is how I have mine setup you can look into it.

<?php

foreach($stats as $stat)

{

$pilot = PilotData::getPilotData($stat->pilotid);

$aircraft = OperationsData::getAircraftInfo($stat->aircraft);

echo '<tr align="center" valign="middle" bgcolor="#DFF4FF">';

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

}

?>

</table>

</div>

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