########################################################################################## GPXIN-28: E_WARNING raised if Speed not present (but calculated) ########################################################################################## Issue Type: Bug ----------------------------------------------------------------------------------------- Issue Information ==================== Priority: Major Status: Closed Resolution: Fixed (2017-07-04 12:13:25) Project: PHP GPXIngest (GPXIN) Reported By: btasker Assigned To: btasker Affected Versions: - 1.02 Targeted for fix in version: - 1.02 Time Estimate: 33 minutes Time Logged: 12 minutes ----------------------------------------------------------------------------------------- Issue 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 -- BEGIN SNIPPET -- 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 -- END SNIPPET -- The relevant lines are -- BEGIN SNIPPET -- $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); -- END SNIPPET -- ----------------------------------------------------------------------------------------- Issue Relations ================ - Github #10 (https://github.com/bentasker/PHP-GPX-Ingest/issues/10) - GPXIngest Line 947 (https://github.com/bentasker/PHP-GPX-Ingest/blob/5414ad85e032348864f6c13fbe5867a935f57516/GPXIngest.class.php#L947) ----------------------------------------------------------------------------------------- Activity ========== ----------------------------------------------------------------------------------------- 2016-02-21 19:54:32 btasker ----------------------------------------------------------------------------------------- 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. ----------------------------------------------------------------------------------------- 2016-02-21 19:54:46 ----------------------------------------------------------------------------------------- btasker changed status from 'Open' to 'In Progress' ----------------------------------------------------------------------------------------- 2016-02-21 20:03:40 btasker ----------------------------------------------------------------------------------------- We calculate accel stats here - https://github.com/bentasker/PHP-GPX-Ingest/blob/5414ad85e032348864f6c13fbe5867a935f57516/GPXIngest.class.php#L490 -- BEGIN SNIPPET -- list($acc,$decc) = $this->calculateAcceleration($ptspeed,$time,$unit); -- END SNIPPET -- But _ptspeed_ is supposed to be set during the calculations -- BEGIN SNIPPET -- // 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; } -- END SNIPPET -- Dropping some debug into _calculateAcceleration_ we do seem to be passing it calculated values -- BEGIN SNIPPET -- Called with 14, 1247348337, mph Called with 15, 1247348352, mph -- END SNIPPET -- And we do seem to be getting Acceleration stats -- BEGIN SNIPPET -- [maxacceleration] => 0.0298 [maxdeceleration] => 0.2235 [minacceleration] => 0.0298 [mindeceleration] => 0.2235 [avgacceleration] => 0.03 [avgdeceleration] => 0.22 -- END SNIPPET -- 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 ----------------------------------------------------------------------------------------- 2016-02-21 20:03:46 ----------------------------------------------------------------------------------------- btasker changed status from 'In Progress' to 'Open' ----------------------------------------------------------------------------------------- 2016-02-21 20:06:07 ----------------------------------------------------------------------------------------- btasker changed timespent from '0 minutes' to '9 minutes' ----------------------------------------------------------------------------------------- 2016-02-21 20:11:51 ----------------------------------------------------------------------------------------- btasker changed timespent from '9 minutes' to '12 minutes' ----------------------------------------------------------------------------------------- 2016-02-21 20:12:32 git ----------------------------------------------------------------------------------------- -- BEGIN QUOTE -- Repo: PHP-GPX-Ingest Commit: 48883817548b6fc6707a7097436b700fd4229d88 Author: B Tasker