Skip to content

Add gradient-aware pacing to ride calculator#10

Merged
simonech merged 2 commits intomasterfrom
copilot/add-gradient-aware-pacing
Feb 19, 2026
Merged

Add gradient-aware pacing to ride calculator#10
simonech merged 2 commits intomasterfrom
copilot/add-gradient-aware-pacing

Conversation

Copy link
Contributor

Copilot AI commented Feb 19, 2026

Power output should vary by gradient rather than staying flat across all terrain. Adds gradient-based power multipliers to the ride calculator and surfaces per-segment and average power in the CLI.

Changes

RideCalculator – gradient pacing multiplier

  • Added GetGradientPacingMultiplier(double gradient) static method mapping gradient bands to power factors:
Gradient Multiplier
< −5% 85%
−5% to −1% 90%
−1% to 1% 100%
1% to 3% 102%
3% to 6% 107%
> 6% 110%
  • Calculate now derives adjustedPower = powerWatts * multiplier per segment before computing speed/duration; the adjusted value is stored in RideSegment.PowerWatts

Program.cs – CLI output

  • Summary: adds duration-weighted Avg Power line
  • Segments: adds Power column per segment
Avg Power: 206.3 W

0m - 100m | Gradient: 3.6% | Power: 214 W | Speed: 18.1 km/h | Time: 20 s
100m - 200m | Gradient: -0.4% | Power: 200 W | Speed: 35.5 km/h | Time: 10 s
200m - 300m | Gradient: 1.7% | Power: 204 W | Speed: 24.4 km/h | Time: 15 s
300m - 329m | Gradient: -3.0% | Power: 180 W | Speed: 48.5 km/h | Time: 2 s
Original prompt

This section details on the original issue you should resolve

<issue_title>Add gradient aware pacing</issue_title>
<issue_description>Now that we have setup the basics, let's add gradient aware pacing.

Basically just change the power based on gradient.
If road is flat use 100% of the power, if climbing goes higher if downhill less power.

Downhill less than -5% 85%
-5% to -1% 90%
-1% to 1% 100%
1 to 3 102%
3 to 6 107%
More than 6 110%

In the CLI pls also print power per segment and avg power on the top</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: simonech <61557+simonech@users.noreply.github.com>
Copilot AI changed the title [WIP] Add gradient aware pacing for power adjustments Add gradient-aware pacing to ride calculator Feb 19, 2026
Copilot AI requested a review from simonech February 19, 2026 17:01
@simonech simonech marked this pull request as ready for review February 19, 2026 17:21
Copilot AI review requested due to automatic review settings February 19, 2026 17:21
@simonech simonech merged commit f23120a into master Feb 19, 2026
5 checks passed
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds gradient-aware pacing so the ride simulation varies rider power output by terrain slope, and updates the CLI to report per-segment and duration-weighted average power.

Changes:

  • Introduces a gradient-band → power multiplier mapping in RideCalculator.
  • Applies adjusted power per route segment when computing velocity/time, and stores it on RideSegment.
  • Extends CLI output to include Avg Power and per-segment Power.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
VirtualSpeed/VirtualSpeed/Services/RideCalculator.cs Adds gradient pacing multiplier and applies adjusted power per segment.
VirtualSpeed/VirtualSpeed/Program.cs Computes and prints duration-weighted average power and per-segment power.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

return 1.00;
if (gradientPct < 3.0)
return 1.02;
if (gradientPct < 6.0)
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gradient banding has an off-by-one at the 6% boundary: gradientPct < 6.0 returns 1.07, but exactly 6.0% will fall through to 1.10. The requirement states 3%–6% => 107% and only >6% => 110%, so 6.0% should still map to 1.07 (adjust the comparison/ordering accordingly).

Suggested change
if (gradientPct < 6.0)
if (gradientPct <= 6.0)

Copilot uses AI. Check for mistakes.
_parameters = parameters;
}

public static double GetGradientPacingMultiplier(double gradient)
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetGradientPacingMultiplier is public but is only used internally in this class. If it isn't intended as part of the public API surface, consider making it private/internal to avoid committing to a public contract unnecessarily.

Suggested change
public static double GetGradientPacingMultiplier(double gradient)
private static double GetGradientPacingMultiplier(double gradient)

Copilot uses AI. Check for mistakes.
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 gradient aware pacing

3 participants