Class: Strava::Models::Stream
- Inherits:
-
Response
- Object
- Hashie::Trash
- Strava::Model
- Response
- Strava::Models::Stream
- Defined in:
- lib/strava/models/stream.rb
Overview
Represents a single stream of time-series data from the Strava API.
A Stream contains both metadata about the data collection and the actual data array. Common stream types include: time, distance, latlng, altitude, velocity_smooth, heartrate, cadence, watts, temp, moving, and grade_smooth.
Instance Method Summary collapse
-
#data ⇒ Array
Array of data points.
-
#original_size ⇒ Integer
Total number of data points in the original stream before any resampling.
-
#resolution ⇒ String
Resolution of the stream data ("low", "medium", or "high").
-
#series_type ⇒ String
Type of series - how data points are indexed ("time" or "distance").
-
#total_elevation_gain ⇒ Float?
Returns the total elevation gain, calculated as the sum of all positive elevation increases between consecutive data points.
-
#total_elevation_gain_s ⇒ String?
Returns formatted total elevation gain in meters.
-
#total_elevation_loss ⇒ Float?
Returns the total elevation loss, calculated as the sum of all negative elevation decreases between consecutive data points.
-
#total_elevation_loss_s ⇒ String?
Returns formatted total elevation loss in meters.
Instance Method Details
#data ⇒ Array
Returns Array of data points. The type of data depends on the stream:
- time: Array of integers (seconds from start)
- distance: Array of floats (meters from start)
- latlng: Array of [latitude, longitude] coordinate pairs
- altitude: Array of floats (meters)
- velocity_smooth: Array of floats (meters per second)
- heartrate: Array of integers (beats per minute)
- cadence: Array of integers (RPM for cycling, steps/min for running)
- watts: Array of integers (power in watts)
- temp: Array of integers (temperature in celsius)
- moving: Array of booleans (true if moving, false if stopped)
- grade_smooth: Array of floats (grade as percentage).
56 |
# File 'lib/strava/models/stream.rb', line 56 property 'data' |
#original_size ⇒ Integer
Returns Total number of data points in the original stream before any resampling.
36 |
# File 'lib/strava/models/stream.rb', line 36 property 'original_size' |
#resolution ⇒ String
Returns Resolution of the stream data ("low", "medium", or "high").
39 |
# File 'lib/strava/models/stream.rb', line 39 property 'resolution' |
#series_type ⇒ String
Returns Type of series - how data points are indexed ("time" or "distance").
42 |
# File 'lib/strava/models/stream.rb', line 42 property 'series_type' |
#total_elevation_gain ⇒ Float?
Returns the total elevation gain, calculated as the sum of all positive elevation increases between consecutive data points.
This is only meaningful when the stream represents altitude data.
70 71 72 73 74 |
# File 'lib/strava/models/stream.rb', line 70 def total_elevation_gain return if data.nil? data.each_cons(2).sum { |a, b| b > a ? b - a : 0 } end |
#total_elevation_gain_s ⇒ String?
Returns formatted total elevation gain in meters.
99 100 101 102 103 104 |
# File 'lib/strava/models/stream.rb', line 99 def total_elevation_gain_s gain = total_elevation_gain return if gain.nil? format('%gm', format('%.1f', gain)) end |
#total_elevation_loss ⇒ Float?
Returns the total elevation loss, calculated as the sum of all negative elevation decreases between consecutive data points.
This is only meaningful when the stream represents altitude data.
88 89 90 91 92 |
# File 'lib/strava/models/stream.rb', line 88 def total_elevation_loss return if data.nil? data.each_cons(2).sum { |a, b| a > b ? a - b : 0 } end |
#total_elevation_loss_s ⇒ String?
Returns formatted total elevation loss in meters.
111 112 113 114 115 116 |
# File 'lib/strava/models/stream.rb', line 111 def total_elevation_loss_s loss = total_elevation_loss return if loss.nil? format('%gm', format('%.1f', loss)) end |