View Single Post
  #6 (permalink)  
Old 09-08-2004, 08:24 AM
accwai's Avatar
accwai accwai is offline
Enthusiast
 
Real Name: Andy Wai
Location: Toronto, Canada
Hybrids: 2004 Prius
Posts: 47
Default

Quote:
Originally posted by Jason+Sep 8th 2004 @ 9:18 AM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td>QUOTE (Jason @ Sep 8th 2004 @ 9:18 AM)</td></tr><tr><td id='QUOTE'>Andy,
Please stop trying to undermine the database. It is a computer. It doesn't have a mind of its own.
[/b]

??? I don't get it. What's that supposed to mean?

Quote:
Originally posted by Jason@Sep 8th 2004 @ 9:18 AM
Gallons are not stored in the database. You cannot calculate gallons and then use gallons to calculate something else. That is completely unscientific and inexact.

An individual tank's gallons will be less accurate than the overall car because there is less data. That's simply all there is to it.
And why is that? The last time I checked, mpg is total miles travelled divided by total gallon of gas used over those miles. Total gallon of gas used is the sum of all tanks. What's so unscientific and inexact about that?

<!--QuoteBegin-Jason
@Sep 8th 2004 @ 9:18 AM
Here is the actual code in the databsae. It's PHP, a serverside language. Enjoy.

Weighting total mileage (loops):

Quote:
while ( $weight = mysql_fetch_array($weightresult) ) {

$mileagenumerator = $mileagenumerator + $weight['mileage']*$weight['distance'];

$denominator = $denominator + $weight['distance'];

$mileage = $mileagenumerator/$denominator;
}
Calculating total gallons:
Quote:
echo number_format(1/$car1['avgmileage']*$car2['sumdistance'],1);
Calculating tank gallons:
Quote:
echo round(1/$data['mileage']*$data['distance'],1);
[/quote]
Well, I'm a EJB type person, but this stuff is close enough to Perl that I'll take a crack at it.

So lets take a concrete example. You have a car that did two tanks. 50mpg for 100 miles on the first tank, and 20mpg for 50 miles on the second tank. From first principle, total distance = 100+50 = 150 miles. Gas use for first tank is 100/50 = 2 gal. Second tank is 50/20 = 2.5 gal. Total gas use is 4.5 gal and overall mpg = 150/4.5 = 33.3mpg.

Now according to your PHP script above, weighted average mpg for the two tank run is (50*100+20*50)/(100+50) = 6000/150 = 40mpg. Now if we go back to first principle, this 40mpg number must come from some distance divided by some gas use. Assume we agree that the total distance is 150 miles, so according to your weighting, we must have used up only 3.75 gallons of gas? So where does the other .75 gallons go??

Andy

P.S. The more the individual tank deviated from the overall average, the bigger the difference is between the two methods. That's why you see a lot more on EMAXX and JHX and much less on sparky etc.
Reply With Quote