GPXIN-28: E_WARNING raised if Speed not present (but calculated)



Issue Information

Issue Type: Bug
 
Priority: Major
Status: Closed

Reported By:
Ben Tasker
Assigned To:
Ben Tasker
Project: PHP GPXIngest (GPXIN)
Resolution: Fixed (2017-07-04 12:13:25)
Affects Version: 1.02,
Target version: 1.02,

Created: 2016-02-21 19:49:27
Time Spent Working
Estimated:
 
45 minutes
Remaining:
  
33 minutes
Logged:
  
12 minutes


Description
Reported on Github as #10

If speed isn't present in the source GPX file, and has instead been calculated (i.e. calcDistance has been enabled), a number of E_WARNINGS are raised as a result of trying to generate acceleration stats

Warning: max() [function.max]: Array must contain at least one element in \GPXIngest.php on line 947

Warning: max() [function.max]: Array must contain at least one element in \GPXIngest.php on line 948

Warning: min() [function.min]: Array must contain at least one element in \GPXIngest.php on line 949

Warning: min() [function.min]: Array must contain at least one element in \GPXIngest.php on line 950

Warning: Division by zero in \GPXIngest.php on line 952

Warning: Division by zero in \GPXIngest.php on line 953


The relevant lines are
$this->journey->journeys->$jkey->stats->maxacceleration = max($this->faccel);
$this->journey->journeys->$jkey->stats->maxdeceleration = max($this->fdecel);
$this->journey->journeys->$jkey->stats->minacceleration = min($this->faccel);
$this->journey->journeys->$jkey->stats->mindeceleration = min($this->fdecel);

$this->journey->journeys->$jkey->stats->avgacceleration = round(array_sum($this->faccel)/count($this->faccel),2);
$this->journey->journeys->$jkey->stats->avgdeceleration = round(array_sum($this->fdecel)/count($this->fdecel),2);


Issue Links

Github #10
GPXIngest Line 947
Toggle State Changes

Activity


I need to double check, but my guess is we're probably not generating the acceleration stats if speed isn't present in the source. GPXIN-13 implemented calculating time moving when calcDistance is used, but I don't think we've touched Accel/Deccel stats yet.

GPXIN-16 also saw these errors, the fix at the time was to suppress speed if it wasn't present in the GPX file, but the implementation of calcDistance (GPXIN-6) has essentially overridden that protection.
btasker changed status from 'Open' to 'In Progress'
We calculate accel stats here - https://github.com/bentasker/PHP-GPX-Ingest/blob/5414ad85e032348864f6c13fbe5867a935f57516/GPXIngest.class.php#L490
list($acc,$decc) = $this->calculateAcceleration($ptspeed,$time,$unit);

But ptspeed is supposed to be set during the calculations
						// Added for GPXIN-13
						if (!$trkpt->desc || empty($speed_string)){
						      // Calculate the speed based on distance travelled and time
						      // distance is in feet

						      // Avoid div by 0
						      if ($this->entryperiod == 0){
							    $speed_string = "0 MPH";
							    $ptspeed = 0;
						      }else{						    
							    $fps = $dist / $this->entryperiod; // Feet per second
							    $mph = round(($fps * 0.681818),0);
							    $speed_string = "$mph MPH";
							    $ptspeed = (int)$mph;
						      }
						      // Make sure the metadata shows we did this calculation
						      $this->journey->metadata->AutoCalc['speed'] = true;
						}


Dropping some debug into calculateAcceleration we do seem to be passing it calculated values
Called with 14, 1247348337, mph
Called with 15, 1247348352, mph

And we do seem to be getting Acceleration stats
[maxacceleration] => 0.0298
[maxdeceleration] => 0.2235
[minacceleration] => 0.0298
[mindeceleration] => 0.2235
[avgacceleration] => 0.03
[avgdeceleration] => 0.22


So it doesn't look like that's the root cause.

Will try and get a copy of the GPX file the user is using - wonder if they've got a track with only one trackpoint or something? Should really check whether those arrays are empty before running max/min on them though
btasker changed status from 'In Progress' to 'Open'
btasker changed timespent from '0 minutes' to '9 minutes'
btasker changed timespent from '9 minutes' to '12 minutes'

Repo: PHP-GPX-Ingest
Commit: 48883817548b6fc6707a7097436b700fd4229d88
Author: B Tasker <github@<Domain Hidden>>

Date: Sun Feb 21 20:10:52 2016 +0000
Commit Message: Prevented acceleration warnings when track contains single trackpoint. See GPXIN-28



Modified (-)(+)
-------
GPXIngest.class.php




Webhook User-Agent

GitHub-Hookshot/21f57ba


View Commit

The user has provided an example GPX:
<?xml version="1.0" encoding="UTF-8"?>
<gpx version="1.1" creator="GPS Track Editor" xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gte="http://www.gpstrackeditor.com/xmlschemas/General/1" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3" targetNamespace="http://www.topografix.com/GPX/1/1" elementFormDefault="qualified" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
<metadata>
	<name>GPS_2010-04-08_070150</name>
</metadata>
<trk>
	<name>ACTIVE LOG</name>
	<trkseg>
		<trkpt lat="32.069516" lon="34.786010">
			<ele>23.17</ele>
			<time>2010-04-08T07:01:50Z</time>
		</trkpt>
		<trkpt lat="32.069516" lon="34.786010">
			<ele>25.23</ele>
			<time>2010-04-08T07:01:51Z</time>
		</trkpt>
		<trkpt lat="32.069516" lon="34.786010">
			<ele>26.37</ele>
			<time>2010-04-08T07:01:55Z</time>
		</trkpt>
		<trkpt lat="32.069516" lon="34.786010">
			<ele>19.80</ele>
			<time>2010-04-08T07:01:59Z</time>
		</trkpt>
		<trkpt lat="32.069516" lon="34.786010">
			<ele>26.00</ele>
			<time>2010-04-08T07:02:00Z</time>
		</trkpt>
		<extensions>
			<gte:name>#6</gte:name>
			<gte:color>#00ffff</gte:color>
		</extensions>
	</trkseg>
</trk>
</gpx>


The speed (and by extension (ac|de)cel) calculations are based on lat/lon. But in that file they're static (though the user's elevation is changing) so we wouldn't record any values to push into those arrays.
Which by extension, means that if, over a number of trackpoints, a user doesn't change speed at all (however unlikely that might be) we won't be generating stats for that either, which would have an effect on the averages generated.

Whether or not that's a bad thing I can't decide. If we introduce calculation of 0 values then we're talking average acceleration over a track. Without, we're talking average rate of acceleration when accelerating which is a subtle but fairly important distinction. I can see a use-case for both, though I think the currently existing stats will have to continue to use the status quo, as the calculations are correct (if a little ambiguous) I don't want to break b/c over them
I think this is as fixed as it can ever be.

Having a file with absolutely no lat/lon present, but static, whilst only elevation changes across the whole file is such an edge case (unless you're interested in tracking journeys in lifts), that it doesn't seem worth putting too much effort into.

The commit above should have fixed the warnings in any case.
btasker changed status from 'Open' to 'Resolved'
btasker added 'Fixed' to resolution
btasker changed status from 'Resolved' to 'Closed'

Work log


Ben Tasker
Permalink
2016-02-21 20:06:07

Time Spent: 9 minutes
Log Entry: Initial investigation

Ben Tasker
Permalink
2016-02-21 20:11:51

Time Spent: 3 minutes
Log Entry: Fixing div by 0 and use of empty faccel/daccel arrays