-
Notifications
You must be signed in to change notification settings - Fork 1
Plug back in the speed calculator #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| namespace VirtualSpeed.Model | ||
| { | ||
| public record RideSegment( | ||
| double DurationSeconds, | ||
| double SpeedKmh, | ||
| double PowerWatts, | ||
| RouteSegment RouteSegment | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,13 +8,31 @@ class Program | |||||||||||||||||
| { | ||||||||||||||||||
| static void Main(string[] args) | ||||||||||||||||||
| { | ||||||||||||||||||
| if (args.Length < 2 || args[0] != "--gpx") | ||||||||||||||||||
| string filePath = null; | ||||||||||||||||||
| double power = 0; | ||||||||||||||||||
| bool hasPower = false; | ||||||||||||||||||
|
|
||||||||||||||||||
| for (int i = 0; i < args.Length - 1; i++) | ||||||||||||||||||
| { | ||||||||||||||||||
| Console.WriteLine("Usage: app.exe --gpx <route.gpx>"); | ||||||||||||||||||
| return; | ||||||||||||||||||
| if (args[i] == "--gpx") | ||||||||||||||||||
| filePath = args[i + 1]; | ||||||||||||||||||
| else if (args[i] == "--power") | ||||||||||||||||||
| { | ||||||||||||||||||
| if (!double.TryParse(args[i + 1], System.Globalization.NumberStyles.Any, | ||||||||||||||||||
| System.Globalization.CultureInfo.InvariantCulture, out power)) | ||||||||||||||||||
| { | ||||||||||||||||||
| Console.WriteLine("Error: --power must be a valid number."); | ||||||||||||||||||
| return; | ||||||||||||||||||
| } | ||||||||||||||||||
|
||||||||||||||||||
| } | |
| } | |
| if (power <= 0) | |
| { | |
| Console.WriteLine("Error: --power must be a positive number (watts)."); | |
| return; | |
| } |
Copilot
AI
Feb 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The argument parsing loop will skip the last argument if it's a flag. The condition i < args.Length - 1 means if someone passes --gpx file.gpx --power (without a value), the --power flag won't be checked. Additionally, if --power is the last argument with a value, it will work, but if --gpx is the last argument, it won't be processed. Consider changing the loop to check i < args.Length and then verify that i + 1 < args.Length before accessing args[i + 1] to provide better error handling.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| using System.Collections.Generic; | ||
| using VirtualSpeed.Model; | ||
|
|
||
| namespace VirtualSpeed.Services | ||
| { | ||
| public class RideCalculator | ||
| { | ||
| private readonly Parameters _parameters; | ||
|
|
||
| public RideCalculator(Parameters parameters) | ||
| { | ||
| _parameters = parameters; | ||
| } | ||
|
|
||
| public IReadOnlyList<RideSegment> Calculate(IReadOnlyList<RouteSegment> routeSegments, double powerWatts) | ||
| { | ||
| var rideSegments = new List<RideSegment>(); | ||
| var calculator = new VirtualSpeedCalculator(_parameters); | ||
|
|
||
| foreach (var routeSegment in routeSegments) | ||
| { | ||
| double speedKmh = calculator.CalculateVelocity(powerWatts, routeSegment.AverageGradient); | ||
| double speedMs = calculator.ConvertKmhToMS(speedKmh); | ||
| double durationSeconds = speedMs > 0 ? routeSegment.LengthMeters / speedMs : 0; | ||
|
|
||
| rideSegments.Add(new RideSegment(durationSeconds, speedKmh, powerWatts, routeSegment)); | ||
| } | ||
|
|
||
| return rideSegments; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The workflow test checks for "Total Distance:" and "Avg Speed:" in the output, but doesn't verify "Total Time:" which is also a new output added in this PR. Consider adding a check for "Total Time:" to ensure all new outputs are being generated correctly.