Jump to content

Landing rates and condition


Jakes

Recommended Posts

Hi there,

I have installed the Step 1 Aircraft buying Mod Version 0.91, and in the database, Under Aircraft, it added a table named 'cond' for aircraft condition.

Is there a way that when filing a pirep with kACARS, it reads the current condition of the aircraft, and based on the landing rate, it write a new condition to the table?

The idea is with a landing with a rate between -200 and -300 to subtract 7% from the condition. From -300 to -400 to subtract 15% from the condition and -400 to -500 subtract 30%. any landing harder than -500 subtract 50%.

I was thinking of the core/modules/KACARS_Free/kACARS_Free.php module, maybe it can be write into that?

my own UNSUCCESFULL and incomplete attempt so far:

//START ADD CONDITION TO LANDING RATE

 $selsql = "SELECT cond FROM MySQLaircraft where aircraftID=$ac";

 $result = mysql_query($selsql);
 $no_record = mysql_num_rows($result);
 if($no_record > 0)
 while($row = mysql_fetch_array($result))
 {
  echo '<tr><td>'.$row['cond'].'</td></tr>';
 }

 if( $landing > -200 && $landing < -300 )
 {
 $cond = $cond -7%
 }
 else if ( $landing > -300 && $landing < -400 )
 {
 $cond = $cond -15%
 }
 else if ( $landing > -400 && $landing < -500 )
 {
 $cond = $cond -30%
 }
 else if ( $landing > -500  )
 {
 $cond = $cond -50%
 }

 // END ADD CONDITION TO LANDING RATE

Any help perhaps?

Link to comment
Share on other sites

  • Replies 94
  • Created
  • Last Reply

Top Posters In This Topic

Guest lorathon

I would be better to add the code to the pirep acceptance code. That way all pireps no matter where they come from would run through the script.

Link to comment
Share on other sites

I would be better to add the code to the pirep acceptance code. That way all pireps no matter where they come from would run through the script.

what is the filename PIREPAdmin.php? and where have no expirience messing around with the PIREP functions

thanks in advance!

Thomas

Link to comment
Share on other sites

I can`t help with the coding but just wanted to say that -7% condition for a almost perfect landing seems a little bit much to me? also -500ft/m isn`t that much to reduce the aircraft condition by -50%!?...so i if you are looking for realistic settings i would reduce this values.

Link to comment
Share on other sites

Thanks for the response, gents,

first,

I would be better to add the code to the pirep acceptance code. That way all pireps no matter where they come from would run through the script.

Well, manual pireps does not have a landing rate (although I am sure it could file a default of foe example -150) But even if the code is added there, I guess it is basically the same?

I can`t help with the coding but just wanted to say that -7% condition for a almost perfect landing seems a little bit much to me? also -500ft/m isn`t that much to reduce the aircraft condition by -50%!?...so i if you are looking for realistic settings i would reduce this values.

The values I have entered is not exact, it must be played around to get the set that works the best. Tanks for the input!

Ok, so now I have this:

public function updateCondition()

 $Landing = $xml->$xml->pirep->landing,
 $AircraftID =>$xml->liveupdate->registration,

 {
  return DB::get_row('SELECT cond FROM ' . TABLE_PREFIX . 'aircraft
	   WHERE `id`=' . $AircraftID);
 }
 }

 if( $landing > -200 && $landing < -300 ){
 $cond = $cond -7
 }
 else if ( $landing > -300 && $landing < -400 ){
 $cond = $cond -15
 }
 else if ( $landing > -400 && $landing < -500 ){
 $cond = $cond -30
 }
 else if ( $landing > -500  ){
 $cond = $cond -50
 }



The idea is to get the landing rate from the pirep instead of the DB, as it could not be filed yet :)

Link to comment
Share on other sites

you could try adding a custom pirep field for landing rate

maybe it is possible to hand over that value to the datafield in DB

where do you but this function?

At the moment I am trying to add it to the core/modules/KACARS_Free/kACARS_Free.php module. Is there a better place to add it to?

Link to comment
Share on other sites

Ok I guess it is better to add it's own independent listner.

I am following these documentation and trying to compile an independend module:

This is what I have:

class Aircraft_Condition extends CodonModule

 {
 CodonEvent::addListener('Aircraft_Condition');
 }
   public function EventListener($eventinfo)
  {
   if($eventinfo[0] == 'pirep_filed'
   {
   $pirepinfo = $eventinfo[1];
   if($pirepinfo->landingrate > -200 && $pirepinfo->landingrate <-500);
 return DB::get_row('SELECT cond FROM ' . TABLE_PREFIX . 'aircraft
    WHERE `id`=' . $AircraftID);
   $cond = $cond -20	
   }
 }

Not working though. I wish I knew more about coding :(

Link to comment
Share on other sites

Guest lorathon

Try this (NOT TESTED!)

class Aircraft_Condition extends CodonModule
 {
 CodonEvent::addListener('Aircraft_Condition');
 }
   public function EventListener($eventinfo)
  {
   if($eventinfo[0] == 'pirep_filed'
   {
   $pirepinfo = $eventinfo[1];

   //Retrieve the aircraft info based on the aircraft id stored in the pirep row
   $aircraft = OperationsData::getAircraftInfo($pirepinfo->aircraftid);


   //Figure out the $cond that needs to be placed into the 
   if($pirepinfo->landingrate > -200 && $pirepinfo->landingrate <-500)
       $cond = $aircraft->cond -20;



   //update the 'cond' column using the aircraft id for row identification
   $update = OperationsData::editAircraft(array('id'=>$pirepinfo->aircraftid, 'cond'=>$cond));


   }
 }

Link to comment
Share on other sites

I guess it is on the right track, but I get the following error:

Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION in /home/jdsarcco/public_html/uvsaaf/core/modules/Aircraft_Condition/Aircraft_Condition.php on line 21

Link to comment
Share on other sites

I guess it is on the right track, but I get the following error:

Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION in /home/jdsarcco/public_html/uvsaaf/core/modules/Aircraft_Condition/Aircraft_Condition.php on line 21

dont exactly know what the error is :(

but from what I see in the error warning it gets a String but wants a Function as return value

how does Aircraft_Condition.php look like?

Link to comment
Share on other sites

Hi Thomas,

Thanks for the response. I found the culprit. the if($eventinfo[0] == 'pirep_filed') was without the last bracket :)

ok, so no more error, but I have run a test or two, and it does not update the 'cond' value. Maybe I must have the codon module to listen for event before pirep is filed?

here is the code as it is now:

<?php
/**
* phpVMS - Virtual Airline Administration Software
* Copyright (c) 2008 Nabeel Shahzad
* For more information, visit www.phpvms.net
* Forums: http://www.phpvms.net/forum
* Documentation: http://www.phpvms.net/docs
*
* phpVMS is licenced under the following license:
*   Creative Commons Attribution Non-commercial Share Alike (by-nc-sa)
*   View license.txt in the root, or visit http://creativecommons.org/licenses/by-nc-sa/3.0/
*
*/
class Aircraft_Condition extends CodonModule
{
public function __index()
{
 CodonEvent::addListener('Aircraft_Condition');
}

public function EventListener($eventinfo)
  {
if($eventinfo[0] == 'pirep_filed')

  //Retrieve the aircraft info based on the aircraft id stored in the pirep row

  $aircraft = OperationsData::getAircraftInfo($pirepinfo->aircraftid);

  //Figure out the $cond that needs to be placed into the
  if($pirepinfo->landingrate > -200 && $pirepinfo->landingrate <-500)
$cond = $aircraft->cond -20;


  //update the 'cond' column using the aircraft id for row identification
  $update = OperationsData::editAircraft(array('id'=>$pirepinfo->aircraftid, 'cond'=>$cond));
  }

}

As soon as the basic condition work, i will add more conditions based on landing rates

Link to comment
Share on other sites

Guest lorathon

I have modified my pirep data file so can not check to see if the aircraftid was part of the original pirep query. If it is not you will need to change the aircraft call to get by registration.

$aircraft = OperationsData::getAircraftByReg($pirepinfo->registration);

You also let out the filing of the $pirepinfo array

$pirepinfo = $eventinfo[1];

public function EventListener($eventinfo) {

  if($eventinfo[0] == 'pirep_filed') {

		$pirepinfo = $eventinfo[1];

	   //Retrieve the aircraft info based on the aircraft id stored in the pirep row
	   $aircraft = OperationsData::getAircraftInfo($pirepinfo->aircraftid);
	   //or
	   $aircraft = OperationsData::getAircraftByReg($pirepinfo->registration);

	   //Figure out the $cond that needs to be placed into the
	   if($pirepinfo->landingrate > -200 && $pirepinfo->landingrate <-500)
			$cond = $aircraft->cond -20;

	   //update the 'cond' column using the aircraft id for row identification
	   $update = OperationsData::editAircraft(array('id'=>$aircraft->id, 'cond'=>$cond));
 }  
}

Link to comment
Share on other sites

if I add that to Aircraft_Condition.php in modules folder

I get that error:

Parse error: syntax error, unexpected ';', expecting T_FUNCTION in /home/flyeurop/public_html/core/modules/Aircraft_Condition/Aircraft_Condition.php on line 40

the error is now fixed missed the closing } ;)

or did I miss something?

guys if we get that Project to work it will enhance Nighthawks great mod by 1000% :)

Link to comment
Share on other sites

Guest lorathon

I just reread the documentation on the hook looks like the the eventinfo should be 2 not 1

$pirepinfo = $eventinfo[2];

@Txmmy - You are correct that the pirep table has the "ID" of the aircraft. But the PIREPData::findPireps query changes the aircraft name into the aircraft data.

Try this.....,

public function EventListener($eventinfo) {
	  if($eventinfo[0] == 'pirep_filed') {
				    $pirepinfo = $eventinfo[2];
			   //Retrieve the aircraft info based on the aircraft registration
			   $aircraft = OperationsData::getAircraftByReg($pirepinfo->registration);
			   //Figure out the $cond that needs to be placed into the
			   if($pirepinfo->landingrate > -200 && $pirepinfo->landingrate <-500)
						    $cond = $aircraft->cond -20;

			   //update the 'cond' column using the aircraft id for row identification
			   $update = OperationsData::editAircraft(array('id'=>$aircraft->id, 'cond'=>$cond));
	 } 
}

Link to comment
Share on other sites

Ok, I have this so far, without any error, but it does not overwrite the condition. what did i miss? Is there more to do than just add the module?

<?php
/**
* phpVMS - Virtual Airline Administration Software
* Copyright (c) 2008 Nabeel Shahzad
* For more information, visit www.phpvms.net
* Forums: http://www.phpvms.net/forum
* Documentation: http://www.phpvms.net/docs
*
* phpVMS is licenced under the following license:
*   Creative Commons Attribution Non-commercial Share Alike (by-nc-sa)
*   View license.txt in the root, or visit http://creativecommons.org/licenses/by-nc-sa/3.0/
*
*/
class Aircraft_Condition extends CodonModule
{
public function __index()
{
 CodonEvent::addListener('Aircraft_Condition');
}

public function EventListener($eventinfo)
  {
   if($eventinfo[0] == 'pirep_filed')
  $pirepinfo = $eventinfo[2];

  //Retrieve the aircraft info based on the aircraft id stored in the pirep row

  $aircraft = OperationsData::getAircraftByReg($pirepinfo->registration);

  //Figure out the $cond that needs to be placed into the
  if($pirepinfo->landingrate > -100 && $pirepinfo->landingrate <-500)
   $cond = $aircraft->cond -20;


  //update the 'cond' column using the aircraft id for row identification
  $update = OperationsData::editAircraft(array('id'=>$pirepinfo->aircraftid, 'cond'=>$cond));
  }

}

Link to comment
Share on other sites

maybe the reason why it doesnt set is in that code from OperationsData.class

public static function editAircraft($data) {

    $data['icao'] = DB::escape(strtoupper($data['icao']));
    $data['name'] = DB::escape(strtoupper($data['name']));
    $data['registration'] = DB::escape(strtoupper($data['registration']));

    $data['range'] = ($data['range'] == '') ? 0 : $data['range'];
    $data['weight'] = ($data['weight'] == '') ? 0 : $data['weight'];
    $data['cruise'] = ($data['cruise'] == '') ? 0 : $data['cruise'];

    $data['range'] = str_replace(',', '', $data['range']);
    $data['weight'] = str_replace(',', '', $data['weight']);
    $data['cruise'] = str_replace(',', '', $data['cruise']);
    $data['maxpax'] = str_replace(',', '', $data['maxpax']);
    $data['maxcargo'] = str_replace(',', '', $data['maxcargo']);
    $data['price'] = ($data['price'] == '') ? 0 : $data['price'];
       $data['bought'] = ($data['bought'] == '') ? 0 : $data['bought'];
       $data['cond'] = ($data['cond'] == '') ? 0 : $data['cond'];
       $data['rep'] = ($data['rep'] == '') ? 0 : $data['rep'];


    if (empty($data['minrank'])) {
	    $data['minrank'] = 0;
    }

    if ($data['enabled'] === true || $data['enabled'] == '1') $data['enabled'] = 1;
    else  $data['enabled'] = 0;

    if ($data['minrank'] > 0) {
	    $data['ranklevel'] = RanksData::getRankLevel($data['minrank']);
    } else {
	    $data['ranklevel'] = 0;
    }

    $sql = "UPDATE " . TABLE_PREFIX . "aircraft SET ";
    $sql .= DB::build_update($data);
    $sql .= " WHERE `id`={$data['id']}";

    /*$sql = "UPDATE " . TABLE_PREFIX."aircraft
    SET `icao`='{$data['icao']}', `name`='{$data['name']}', `fullname`='{$data['fullname']}',
    `registration`='{$data['registration']}', `downloadlink`='{$data['downloadlink']}',
    `imagelink`='{$data['imagelink']}', `range`='{$data['range']}', `weight`='{$data['weight']}',
    `cruise`='{$data['cruise']}', `maxpax`='{$data['maxpax']}', `maxcargo`='{$data['maxcargo']}',
    `minrank`={$data['minrank']}, `ranklevel`={$rank_level}, `enabled`={$data['enabled']}, `bought`={$data['bought']}, `cond`={$data['cond']},`rep`={$data['rep']}
    WHERE `id`={$data['id']}";*/

    $res = DB::query($sql);

    if (DB::errno() != 0) return false;

    CodonCache::delete('all_aircraft');
    CodonCache::delete('all_aircraft_enabled');
    CodonCache::delete('all_aircraft_search');
    CodonCache::delete('all_aircraft_search_enabled');

    return true;
   }

best regards

Thomas

Link to comment
Share on other sites

Guest lorathon

Thomas has pointed out one thing. The editAircraft function should work but there is an issue. If you just send the 'cond' the script will set the minrank to 0 since it is not in the array. So you either have to send the minrank or make your own function to update the 'cond' only.

Also you have left out the brackets for the 'if' statement. The way you have it written the function will fire on ever hook. To check I would put a standard 'cond' of 100. That way you can really see if it is accessing the aircraft data. Or even better just grab the landing rate and shove it into the 'cond' column. That way you know that the landingrate is being found and also the aircraft update is working.

Also to check

1. Is there a 'cond' column in the aircraft table?

2. What is the type of the 'cond' column?

You may to write a function that you can access via the browser rather than through pirep sent. That way you can test the script and get it running prior to sticking the hook in play. This is what I would do. You should be able to figure it out very quickly doing it this way.

I have created a custom function to update the aircraft. It will only update the cond.

<?php
/**
* phpVMS - Virtual Airline Administration Software
* Copyright (c) 2008 Nabeel Shahzad
* For more information, visit www.phpvms.net
* Forums: http://www.phpvms.net/forum
* Documentation: http://www.phpvms.net/docs
*
* phpVMS is licenced under the following license:
*   Creative Commons Attribution Non-commercial Share Alike (by-nc-sa)
*   View license.txt in the root, or visit http://creativecommons.org/licenses/by-nc-sa/3.0/
*
*/
class Aircraft_Condition extends CodonModule
{
public function __index()
{
 CodonEvent::addListener('Aircraft_Condition');
}
public function EventListener($eventinfo)
  {
if($eventinfo[0] == 'pirep_filed') {
  $pirepinfo = $eventinfo[2];

  //Retrieve the aircraft info based on the aircraft id stored in the pirep row
  $aircraft = OperationsData::getAircraftByReg($pirepinfo->registration);

  //Figure out the $cond that needs to be placed into the
  if($pirepinfo->landingrate > -100 && $pirepinfo->landingrate <-500)
$cond = $aircraft->cond -20;

// Use landingrate as a test.
$cond = $pirepinfo->landingrate;
// Or use a hardcoded variable
$cond = 100;

  //update the 'cond' column using the aircraft id for row identification
  $update = $this->updateAircraft($aircraft->id, $cond);
}
  }
  private function updateAircraft($id, $cond) {
  $sql = 'UPDATE '.TABLE_PREFIX."aircraft
 SET `cond` = '$cond'
 WHERE `id` = '$id'";

 $res = DB::query($sql);

 if(DB::errno() != 0)
  return false;

			return true;
}
}

Link to comment
Share on other sites

Also to check

1. Is there a 'cond' column in the aircraft table?

2. What is the type of the 'cond' column?

'cond' column is there when Nighthawks addon is installed

'cond' column is varchar(15) as I have now looked up in DB which I think is another Problem

since it looks like we compare apples with stones ;)

cond- a value wont work since a varchar works more like a extended version of string type?

Link to comment
Share on other sites

Guest lorathon

Personally I would change the type to 'float'. That will give you more latitude with the column. If you want me to write a custom function that can be used from your browser let me know.

Link to comment
Share on other sites

Guest lorathon

The hook will only fire when a pirep is filed. If you write a function that you can fire from the browser you can get real time info. You can then run it over and over as you modify until you get it right.

Link to comment
Share on other sites

Just going over everything, and wanted to make sure, is this statement correct (I know the figures are insane, but just for testing purposes)

//Figure out the $cond that needs to be placed into the
  if($pirepinfo->landingrate > -1 && $pirepinfo->landingrate <-2000)
    $cond = $aircraft->cond -20;

Shouldn't it be:

//Figure out the $cond that needs to be placed into the
  if($pirepinfo->landingrate > -1)&& ($pirepinfo->landingrate <-2000)
    $cond = $aircraft->cond -20;

Link to comment
Share on other sites

Just going over everything, and wanted to make sure, is this statement correct (I know the figures are insane, but just for testing purposes)

//Figure out the $cond that needs to be placed into the
  if($pirepinfo->landingrate > -1 && $pirepinfo->landingrate <-2000)
	$cond = $aircraft->cond -20;

Shouldn't it be:

//Figure out the $cond that needs to be placed into the
  if($pirepinfo->landingrate > -1)&& ($pirepinfo->landingrate <-2000)
	$cond = $aircraft->cond -20;

//Figure out the $cond that needs to be placed into the
  if(($pirepinfo->landingrate > -1)&& ($pirepinfo->landingrate <-2000))
		$cond = $aircraft->cond -20;

but not completly sure ;)

and if you look at this example from activity module

if(!$activities) {
		$activities = array();
	}

could it be that we left out some {

}

so that the if never takes effect?

best regards

Thomas

Edited by Txmmy83
Link to comment
Share on other sites

I have tried a different approach:

I figured if you can have a command like this:

if (DB::errno() != 0) return false;
	CodonCache::delete('all_aircraft');

you could maybe use it the other way around? Like

	OperationsData::update('cond');

So here is what I have UNTESTED I have set the condition to write to a value of 50 just for testing purposes. I also decided to go with Aircraft Reg rather than ID. Is that wise?

<?php
/**
* phpVMS - Virtual Airline Administration Software
* Copyright (c) 2008 Nabeel Shahzad
* For more information, visit www.phpvms.net
* Forums: http://www.phpvms.net/forum
* Documentation: http://www.phpvms.net/docs
*
* phpVMS is licenced under the following license:
*   Creative Commons Attribution Non-commercial Share Alike (by-nc-sa)
*   View license.txt in the root, or visit http://creativecommons.org/licenses/by-nc-sa/3.0/
*
*/
class Aircraft_Condition extends CodonModule
{
public function __index()
{
 CodonEvent::addListener('Aircraft_Condition');
}
public function EventListener($eventinfo)
  {
  if($eventinfo[0] == 'pirep_filed') {
  $pirepinfo = $eventinfo[2];


}
 }

public static function editAircraft($data) {

 //Retrieve the aircraft info based on the aircraft id stored in the pirep row
 $data['registration'] = OperationsData::getAircraftByReg($pirepinfo->registration)
 if ($pirepinfo->landingrate > -1 && $pirepinfo->landingrate <-2000) {
	$data('cond') = 50;
	}

 $res = DB::query($sql);

 OperationsData::update('cond');

  if (DB::errno() != 0) return false;		CodonCache::delete('all_aircraft');
	CodonCache::delete('all_aircraft_enabled');
	CodonCache::delete('all_aircraft_search');
	CodonCache::delete('all_aircraft_search_enabled');
	return true;
}



}}

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...