GPXIN-13: If Speed is unavailable, calculate Time Moving based on lat lon changes



Issue Information

Issue Type: New Feature
 
Priority: Minor
Status: Closed

Reported By:
Ben Tasker
Assigned To:
Ben Tasker
Project: PHP GPXIngest (GPXIN)
Resolution: Done (2015-08-13 17:59:01)
Affects Version: 1.02,
Target version: 1.02,

Created: 2015-01-13 09:53:12
Time Spent Working


Description
If trackpoints do not include speed values, calculate the time moving stats (implemented in GPXIN-7) based on whether the lat/lon values have changed between trackpoints.


Issue Links

Toggle State Changes

Activity


btasker changed priority from 'Major' to 'Minor'
If distance calculations are enabled (GPXIN-13) then the speed should be calculated once the time between trackpoints has been calculated

Repo: PHP-GPX-Ingest
Commit: 05af1e87f7e1c32735e0715f571be8e068544b29
Author: Ben Tasker <github@<Domain Hidden>>

Date: Mon Aug 10 13:50:56 2015 +0100
Commit Message: Class will calculate speed and timemoving from calculateddistance if enabled. Minor issues. See GPXIN-13



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




Webhook User-Agent

GitHub-Hookshot/29237e4


View Commit

Commit 05af1e8 implements the basic functionality and the output appears correct
<?php
require 'GPXIngest.class.php';

$gpx = new GPXIngest();
$gpx->enableExperimental('calcDistance');
$gpx->loadFile('test.gpx');
$gpx->ingest();
echo $json = $gpx->getJSON();

However, the class is generating PHP warnings (repeatedly)
PHP Warning:  array_count_values(): Can only count STRING and INTEGER values! in /tmp/gpx/GPXIngest.class.php on line 701
PHP Warning:  array_count_values(): Can only count STRING and INTEGER values! in /tmp/gpx/GPXIngest.class.php on line 776
PHP Warning:  array_count_values(): Can only count STRING and INTEGER values! in /tmp/gpx/GPXIngest.class.php on line 475


All relate to trying to extract the modal speed
475: 		$modesearch = array_count_values($this->journeyspeeds);
701: 		$modesearch = array_count_values($this->sspeed);
776: 		$modesearch = array_count_values($this->fspeed);

I'd guess we're occasionally setting a boolean as speedint which is then pushed into fspeed and sspeed on line 427
$this->fspeed[] = $ptspeed;
$this->sspeed[] = $ptspeed;

Should be reasonably easy to sort out, but well worth double-checking where else ptspeed is used.
Dropped a debug statement in
echo "Speedstring: $speed_string (".gettype($speed_string)."), ".
"speedint: $ptspeed (".gettype($ptspeed)."),".
"dist: $dist, entryperiod: {$this->entryperiod}\n";

Looks like we're occasionally getting a double
Speedstring: 0 MPH (string), speedint: 0 (integer),dist: 0, entryperiod: 0
Speedstring: 1 MPH (string), speedint: 1 (double),dist: 12.54, entryperiod: 11
Speedstring: 1 MPH (string), speedint: 1 (double),dist: 35.688, entryperiod: 17
Speedstring: 2 MPH (string), speedint: 2 (double),dist: 165.323, entryperiod: 57
Speedstring: 2 MPH (string), speedint: 2 (double),dist: 58.918, entryperiod: 17
Speedstring: 2 MPH (string), speedint: 2 (double),dist: 51.325, entryperiod: 20
Speedstring: 1 MPH (string), speedint: 1 (double),dist: 14.79, entryperiod: 16
Speedstring: 2 MPH (string), speedint: 2 (double),dist: 29.621, entryperiod: 13
Speedstring: 1 MPH (string), speedint: 1 (double),dist: 14.438, entryperiod: 12
PHP Warning:  array_count_values(): Can only count STRING and INTEGER values! in /tmp/gpx/GPXIngest.class.php on line 703
PHP Warning:  array_count_values(): Can only count STRING and INTEGER values! in /tmp/gpx/GPXIngest.class.php on line 703
PHP Warning:  array_count_values(): Can only count STRING and INTEGER values! in /tmp/gpx/GPXIngest.class.php on line 703
PHP Warning:  array_count_values(): Can only count STRING and INTEGER values! in /tmp/gpx/GPXIngest.class.php on line 703
PHP Warning:  array_count_values(): Can only count STRING and INTEGER values! in /tmp/gpx/GPXIngest.class.php on line 703
PHP Warning:  array_count_values(): Can only count STRING and INTEGER values! in /tmp/gpx/GPXIngest.class.php on line 703
PHP Warning:  array_count_values(): Can only count STRING and INTEGER values! in /tmp/gpx/GPXIngest.class.php on line 703
PHP Warning:  array_count_values(): Can only count STRING and INTEGER values! in /tmp/gpx/GPXIngest.class.php on line 703

So commit f6106ed castes ptspeed to an integer
It's probably wise (for debugging purposes) to add some sort of metadata to note that the speed was auto-calculated.

Repo: PHP-GPX-Ingest
Commit: f6106edfdd4ea47bc3811f52e22f2bca4c7a16af
Author: Ben Tasker <github@<Domain Hidden>>

Date: Mon Aug 10 14:08:18 2015 +0100
Commit Message: Ensured calculated ptspeed is an integer. See GPXIN-13



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




Webhook User-Agent

GitHub-Hookshot/29237e4


View Commit

Created a new array within the metadata object - AutoCalc - if the speed has been calculated from the distance calculations it will set speed to true. Used an array so that if we end up calculating other items in future we don't flood the metadata object with near identical properties.

Repo: PHP-GPX-Ingest
Commit: 8ee01e694a5b4cecd4b60173a225f338dd6d5e54
Author: Ben Tasker <github@<Domain Hidden>>

Date: Mon Aug 10 14:14:29 2015 +0100
Commit Message: Updated metadata to reflect whether speed has been auto-calculated. See GPXIN-13



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




Webhook User-Agent

GitHub-Hookshot/29237e4


View Commit

btasker changed status from 'Open' to 'Resolved'
btasker added 'Done' to resolution
btasker changed status from 'Resolved' to 'Closed'
Have marked as Complete - currently this will only happen if Distance calculations are explicitly enabled - the longer term plan though is to remove the need for explicit enabling of that functionality.