Jump to content

statistics help [SOLVED]


airmermaid

Recommended Posts

Hello

In my statistics on main page I have tried to add a "totat passengers carried" field. To my surprise the number shown was unbelieveable.

According to it my airline has carried around 104000 passengers with only 27 flights. Which makes around 3800 persons per flight.

I took the data from .../core/common/StatsData.class.php (field is TotalPaxCarried). Am I looking at wrong place for that data?

I also would like to know if there's a way to add Total Cargo Carried because my airline has a cargo section too.

Cheers,

Arslan

Link to comment
Share on other sites

I just tested it and it returned a reasonable value for me (2945 pax for 38 flights). Can you post the actual code you're using?

As for the total cargo, I don't see any built-in methods for that. You'd have to write an SQL query to sum the 'load' field for all filed PIREPs.

  • Like 1
Link to comment
Share on other sites

I just tested it and it returned a reasonable value for me (2945 pax for 38 flights). Can you post the actual code you're using?

As for the total cargo, I don't see any built-in methods for that. You'd have to write an SQL query to sum the 'load' field for all filed PIREPs.

This is the part of Total Pax Carried (which I deleted)

<tt>Total Passengers Carried: </tt><?php echo StatsData::TotalPaxCarried(); ?><br />

For the cargo thingy I will pass as I don't know this coding stuff and don't want to mess with SQL :)

Link to comment
Share on other sites

Try passing the airline: StatsData::TotalPaxCarried('MER')

That's how I tested it, see if it makes a difference. According to the documentation, passing the airline is optional, so I assume by not passing anything it returns the total for all airlines (which should be the same value if you only have one airline), but either I'm wrong or there's a bug in the method.

Link to comment
Share on other sites

  • Moderators

Hey Michael,

Just to clear up, I don't think you need the 's in in the VA code.

It should be done like that..

<?php echo StatsData::TotalPaxCarried(MER); ?>

and it will return the data in order of an VA.

Link to comment
Share on other sites

Hey Michael,

Just to clear up, I don't think you need the 's in in the VA code.

It should be done like that..

<?php echo StatsData::TotalPaxCarried(MER); ?>

and it will return the data in order of an VA.

Told you, I was doing something weird.

Thanks guys.

But it still is the same

Total Pax Carried: 104643

:(

Link to comment
Share on other sites

Hey Michael,

Just to clear up, I don't think you need the 's in in the VA code.

It should be done like that..

<?php echo StatsData::TotalPaxCarried(MER); ?>

and it will return the data in order of an VA.

I just tested it again and it works either with or without the quotes. I also tested StatsData::TotalPaxCarried() without passing any arguments and it still returned the same value (2945), so I'm not sure what's wrong with the OP.

Link to comment
Share on other sites

Ahh finally :)

Then I have to remove that Total Pax thingy from my main page.

Cheers,

Well, if you're using separate airline codes for pax and cargo (which from reading your about page it looks so) you can just use <?php echo StatsData::TotalPaxCarried(MER); ?> for pax and <?php echo StatsData::TotalPaxCarried(somethingelse); ?> for cargo.

Link to comment
Share on other sites

Well, there is a way to do it using SQL:

$query="SELECT SUM(`load`) as totalpax FROM `phpvms_pireps` WHERE `flighttype`='P'";
$result=DB::get_results($query);
echo $result[0]->totalpax;

This sums up the load for passenger flights only. This assumes that you have your cargo routes set as cargo flights.

Link to comment
Share on other sites

I have the exact same problem as the original author. I just two day ago set up a few cargo flights and my passenger count went through the roof with only 2 flights done. I am pulling the stats exactly how he did originally.

And I thought it was odd so I went and looked at the schedules just to verify that they ARE infact selected as cargo flights and not charter or passenger. All the cargo flights are all selected as cargo.

I do have two separate airlines set up. Neither of which does cargo specific schedules. Cargo flights just end up where they end up at in either airline.

Link to comment
Share on other sites

Well, there is a way to do it using SQL:

$query="SELECT SUM(`load`) as totalpax FROM `phpvms_pireps` WHERE `flighttype`='P'";
$result=DB::get_results($query);
echo $result[0]->totalpax;

This sums up the load for passenger flights only. This assumes that you have your cargo routes set as cargo flights.

And where did you put this little sql query at? In the stats data class? And if so where did you insert it at?

Here is what I am looking at as we speak.

public static function TotalPaxCarried($airline_code = '') {
       $key = 'total_pax_carried';
       if ($airline_code != '') {
           $key .= '_' . $airline_code;
       }

       $total = CodonCache::read($key);

       if ($total === false) {
           $params = array('table' => TABLE_PREFIX . 'pireps', 'fields' =>
               'SUM(`load`) as `total`', 'where' => array('accepted' => PIREP_ACCEPTED,
               'flighttype' => 'P'), );

           if (!empty($airline_code)) {
               $params['where']['code'] = $airline_code;
               $params['group'] = 'code';
           }

           $sql = DB::build_select($params);
           $results = DB::get_results($sql);
           if (!$results) {
               $total = 0;
           } else {
               $total = $results[0]->total;
           }

           CodonCache::write($key, $total, '15minute');
       }

       return $total;
   }

Link to comment
Share on other sites

Hi,

In my site I have put it inside frontpage_main.tpl under sidebar entry where you also have Newest Pilots and such.

This is the full code I am currently using.

<h3 align="center">Statistics</h3>

<table bgcolor="#d6d6d6" frame="border" align="center" bordercolor="#010854">

<tr align="left"><th>

<div>

<tt>Total Pilots: </tt><?php echo StatsData::PilotCount(); ?><br />

<tt>Total Pax Flights: </tt>

<?php

$query="SELECT COUNT(*) as totalfltp FROM `phpvms_pireps` WHERE `flighttype`='P'";

$result=DB::get_results($query);

echo $result[0]->totalfltp; ?><br />

<tt>Total Cargo Flights: </tt>

<?php

$query="SELECT COUNT(*) as totalfltp FROM `phpvms_pireps` WHERE `flighttype`='C'";

$result=DB::get_results($query);

echo $result[0]->totalfltp; ?><br />

<tt>Total Hours Flown: </tt><?php echo StatsData::TotalHours()?> <?php echo hours; ?><br />

<tt>Total Miles Flown: </tt><?php echo StatsData::TotalMilesFlown()?> <?php echo NM; ?><br />

<tt>Total a/c in Fleet: </tt><?php echo StatsData::TotalAircraftInFleet(); ?><br />

<tt>Total Flights Today: </tt><?php echo StatsData::totalflightstoday(); ?><br />

<tt> Total Pax Carried: </tt><?php

$query="SELECT SUM(`load`) as totalpax FROM `phpvms_pireps` WHERE `flighttype`='P'";

$result=DB::get_results($query);

echo $result[0]->totalpax; ?> <?php echo Persons; ?><br />

<tt>Total Cargo Carried: </tt><?php

$query="SELECT SUM(`load`) as totalfreight FROM `phpvms_pireps` WHERE `flighttype`='C'";

$result=DB::get_results($query);

echo $result[0]->totalfreight; ?> <?php echo Kgs; ?><br /></div>

</th></tr></table>

Hope it helps.

  • Like 1
Link to comment
Share on other sites

Well, I tried that and it echoed persons after the number which in my case stayed the same. I wonder if I should have deleted my cache and all that good stuff in the maint center to get the number to reflect accurately.

I think it is because the name of the database in your VA is not "phpvms_pireps" but something else. Try calling it with the exact name. In my VA it is "phpvms_CEOpireps"

Link to comment
Share on other sites

Well, I tried that and it echoed persons after the number which in my case stayed the same. I wonder if I should have deleted my cache and all that good stuff in the maint center to get the number to reflect accurately.

Can you post the exact code you're using? The cache shouldn't make a difference; the code I posted is a direct SQL query, which is not cached, unlike the API calls, which do utilize caching. My way is not necessarily better, in fact it's worse in several ways, but it is one way to get the results.

Link to comment
Share on other sites

Right, you also have to make sure the TABLE_PREFIX is correct:

$sql = "SELECT * FROM ".TABLE_PREFIX."tablename";

Since some people change table prefixes

Everything is default. I never change anything database related. It is how it was installed. ;) Why mess witha piece of work that is proven to begin with and one of if not the best working around? :D

And thanks for the help on this one guys. I appreciate it. This has been causing quite a buzz on my test site the last week or so. It was just kind of ironic you guys all started talking about it at about the same time I noticed the problem.

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