From 19496bf6b36ac3d540eb26414d1fb0892f694465 Mon Sep 17 00:00:00 2001 From: Shaydu Date: Thu, 29 Jun 2017 20:46:26 -0700 Subject: [PATCH 1/7] Update Route.php --- src/phpGPX/Models/Route.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/phpGPX/Models/Route.php b/src/phpGPX/Models/Route.php index f8bccd2..dad6164 100644 --- a/src/phpGPX/Models/Route.php +++ b/src/phpGPX/Models/Route.php @@ -111,6 +111,18 @@ function recalculateStats() $this->stats->distance += $this->points[$p]->difference; $this->points[$p] = $this->stats->distance; } + + if($this->stats->cumulativeElevation == null) + { + $lastElevation = $firstPoint->elevation; + $this->stats->cumulativeElevation = 0; + } + else + { + $elevationDelta = $this->points[$p]->elevation - $lastElevation; + $this->stats->cumulativeElevation = ($elevationDelta > 0) ? $elevationDelta : 0; + $lastElevation = $this->points[$p]->elevation; + } if ($this->stats->minAltitude == null) { @@ -142,4 +154,4 @@ function recalculateStats() } } } -} \ No newline at end of file +} From c7a95cb0e3defe6c01233ed50c569c882ed4aa72 Mon Sep 17 00:00:00 2001 From: Shaydu Date: Thu, 29 Jun 2017 20:49:00 -0700 Subject: [PATCH 2/7] Update Stats.php --- src/phpGPX/Models/Stats.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/phpGPX/Models/Stats.php b/src/phpGPX/Models/Stats.php index 708ee3b..e8ed67e 100644 --- a/src/phpGPX/Models/Stats.php +++ b/src/phpGPX/Models/Stats.php @@ -46,6 +46,12 @@ class Stats implements Summarizable * @var int */ public $maxAltitude = null; + + /** + * Total elevation gain in meters (m) + * @var int + */ + public $cumulativeElevationGain = null; /** * Started time @@ -96,4 +102,4 @@ function toArray() 'duration' => (double) $this->duration ]; } -} \ No newline at end of file +} From 90403ccca6a87c7d3bf09e1915daa3a0797646d7 Mon Sep 17 00:00:00 2001 From: Shaydu Date: Thu, 29 Jun 2017 20:51:45 -0700 Subject: [PATCH 3/7] Change cumulativeElevation Stat property name --- src/phpGPX/Models/Route.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/phpGPX/Models/Route.php b/src/phpGPX/Models/Route.php index dad6164..918fa4f 100644 --- a/src/phpGPX/Models/Route.php +++ b/src/phpGPX/Models/Route.php @@ -112,15 +112,15 @@ function recalculateStats() $this->points[$p] = $this->stats->distance; } - if($this->stats->cumulativeElevation == null) + if($this->stats->cumulativeElevationGain == null) { $lastElevation = $firstPoint->elevation; - $this->stats->cumulativeElevation = 0; + $this->stats->cumulativeElevationGain = 0; } else { $elevationDelta = $this->points[$p]->elevation - $lastElevation; - $this->stats->cumulativeElevation = ($elevationDelta > 0) ? $elevationDelta : 0; + $this->stats->cumulativeElevationGain = ($elevationDelta > 0) ? $elevationDelta : 0; $lastElevation = $this->points[$p]->elevation; } From 20d5e26587bc8e200fb5d977b078c9ec0c741933 Mon Sep 17 00:00:00 2001 From: Shaydu Date: Thu, 29 Jun 2017 20:54:42 -0700 Subject: [PATCH 4/7] Add cumulativeElevationGain property --- src/phpGPX/Models/Stats.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/phpGPX/Models/Stats.php b/src/phpGPX/Models/Stats.php index 708ee3b..daac348 100644 --- a/src/phpGPX/Models/Stats.php +++ b/src/phpGPX/Models/Stats.php @@ -46,6 +46,12 @@ class Stats implements Summarizable * @var int */ public $maxAltitude = null; + + /** + * Cumulative elevation gain in meters (m) + * @var int + */ + public $cumulativeElevationGain = null; /** * Started time @@ -75,6 +81,7 @@ public function reset() $this->averagePace = null; $this->minAltitude = null; $this->maxAltitude = null; + $this->cumulativeElevationGain = null; $this->startedAt = null; $this->finishedAt = null; } @@ -91,9 +98,10 @@ function toArray() 'avgPace' => (double) $this->averagePace, 'minAltitude' => (double) $this->minAltitude, 'maxAltitude' => (double) $this->maxAltitude, + 'cumulativeElevationGain' => (double) $this->cumulativeElevationGain, 'startedAt' => DateTimeHelper::formatDateTime($this->startedAt, phpGPX::$DATETIME_FORMAT, phpGPX::$DATETIME_TIMEZONE_OUTPUT), 'finishedAt' => DateTimeHelper::formatDateTime($this->finishedAt, phpGPX::$DATETIME_FORMAT, phpGPX::$DATETIME_TIMEZONE_OUTPUT), 'duration' => (double) $this->duration ]; } -} \ No newline at end of file +} From 07df57159e12f0e9aa9fa40eac871fa42c3f70be Mon Sep 17 00:00:00 2001 From: Shaydu Date: Thu, 29 Jun 2017 20:56:00 -0700 Subject: [PATCH 5/7] Update property description --- src/phpGPX/Models/Stats.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/phpGPX/Models/Stats.php b/src/phpGPX/Models/Stats.php index e8ed67e..fb00d3a 100644 --- a/src/phpGPX/Models/Stats.php +++ b/src/phpGPX/Models/Stats.php @@ -48,7 +48,7 @@ class Stats implements Summarizable public $maxAltitude = null; /** - * Total elevation gain in meters (m) + * Cumulative elevation gain in meters (m) * @var int */ public $cumulativeElevationGain = null; From 919ad34c7d4c41e53865d26f4397d50ae9be5d03 Mon Sep 17 00:00:00 2001 From: Shaydu Date: Thu, 29 Jun 2017 21:00:24 -0700 Subject: [PATCH 6/7] Update phpGPX-Models-Stats.md --- docs/phpGPX-Models-Stats.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/phpGPX-Models-Stats.md b/docs/phpGPX-Models-Stats.md index fc185b5..8973f30 100644 --- a/docs/phpGPX-Models-Stats.md +++ b/docs/phpGPX-Models-Stats.md @@ -69,6 +69,16 @@ Maximal altitude in meters (m) +* Visibility: **public** + +### $cumulativeElevationGain + + public integer $cumulativeElevationGain = null + +Cumulative positive elevation gain in meters (m) + + + * Visibility: **public** From ccbd265ec4abd252afd399519a774da16a41fa1b Mon Sep 17 00:00:00 2001 From: steve haydu Date: Thu, 29 Jun 2017 22:46:39 -0700 Subject: [PATCH 7/7] fix elevation gain calculation --- src/phpGPX/Models/Route.php | 8 ++++---- src/phpGPX/Models/Track.php | 13 ++++++++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/phpGPX/Models/Route.php b/src/phpGPX/Models/Route.php index 918fa4f..000c519 100644 --- a/src/phpGPX/Models/Route.php +++ b/src/phpGPX/Models/Route.php @@ -112,15 +112,15 @@ function recalculateStats() $this->points[$p] = $this->stats->distance; } - if($this->stats->cumulativeElevationGain == null) + if($this->stats->cumulativeElevationGain === null) { - $lastElevation = $firstPoint->elevation; + $lastElevation = $firstPoint->elevation; $this->stats->cumulativeElevationGain = 0; } - else + else { $elevationDelta = $this->points[$p]->elevation - $lastElevation; - $this->stats->cumulativeElevationGain = ($elevationDelta > 0) ? $elevationDelta : 0; + $this->stats->cumulativeElevationGain += ($elevationDelta > 0) ? $elevationDelta : 0; $lastElevation = $this->points[$p]->elevation; } diff --git a/src/phpGPX/Models/Track.php b/src/phpGPX/Models/Track.php index cd2c2be..33f1bcb 100644 --- a/src/phpGPX/Models/Track.php +++ b/src/phpGPX/Models/Track.php @@ -118,6 +118,17 @@ function recalculateStats() } $this->stats->distance += $this->segments[$s]->points[$p]->difference; $this->segments[$s]->points[$p]->distance = $this->stats->distance; + + if($this->stats->cumulativeElevationGain === null) + { + $lastElevation = $firstPoint->elevation; + $this->stats->cumulativeElevationGain = 0; + } + else + { + $elevationDelta = $this->segments[$s]->points[$p]->elevation - $lastElevation; + $this->stats->cumulativeElevationGain += ($elevationDelta > 0) ? $elevationDelta : 0; $lastElevation = $this->segments[$s]->points[$p]->elevation; + } } if ($this->stats->minAltitude == null) { @@ -148,4 +159,4 @@ function recalculateStats() } } } -} \ No newline at end of file +}