Skip to content

Add total_elevation_gain and total_elevation_loss to Stream - #105

Merged
dblock merged 1 commit into
masterfrom
dblock/54-total-elevation-loss
Aug 24, 2026
Merged

dblock merged 1 commit into
masterfrom
dblock/54-total-elevation-loss

Conversation

@dblock

@dblock dblock commented Aug 24, 2026

Copy link
Copy Markdown
Owner

Description

Closes #54.

Strava's API doesn't provide a native total_elevation_loss (descent) property on any model. As discussed in the issue, computing it requires either cross-referencing data from multiple endpoints (e.g. Activity for gain plus Stream for start/end elevation), or computing gain/loss directly from an altitude stream's data points.

This PR takes the self-contained approach: it adds total_elevation_gain and total_elevation_loss methods (plus formatted _s helpers) to Strava::Models::Stream, computed by summing the positive/negative deltas between consecutive altitude data points. This requires only a single altitude stream request and no cross-model composition.

streams = client.activity_streams(1946417534, keys: %w[altitude])

streams.altitude.total_elevation_gain # => 725.3
streams.altitude.total_elevation_loss # => 680.1
streams.altitude.total_elevation_gain_s # => "725.3m"
streams.altitude.total_elevation_loss_s # => "680.1m"

Changes

  • Adds total_elevation_gain, total_elevation_loss, total_elevation_gain_s and total_elevation_loss_s to Strava::Models::Stream.
  • Adds unit tests in spec/strava/models/stream_spec.rb.
  • Updates README with usage example.
  • Updates CHANGELOG.

@github-actions

github-actions Bot commented Aug 24, 2026

Copy link
Copy Markdown

Danger Report

No issues found.

View run

… from altitude data

Closes #54.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dblock
dblock force-pushed the dblock/54-total-elevation-loss branch from 8b30eae to 5c15183 Compare August 24, 2026 20:44
@dblock dblock mentioned this pull request Aug 24, 2026
@dblock
dblock merged commit c5cb2b4 into master Aug 24, 2026
17 checks passed
@dblock
dblock deleted the dblock/54-total-elevation-loss branch August 24, 2026 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for descent

1 participant