Skip to content

Fix scheduledDistanceAlongTrip when scheduleDeviation is zero - #1283

Open
Ahmedhossamdev wants to merge 1 commit into
mainfrom
fix/trip-status-scheduled-distance-on-time
Open

Fix scheduledDistanceAlongTrip when scheduleDeviation is zero#1283
Ahmedhossamdev wants to merge 1 commit into
mainfrom
fix/trip-status-scheduled-distance-on-time

Conversation

@Ahmedhossamdev

@Ahmedhossamdev Ahmedhossamdev commented Aug 2, 2026

Copy link
Copy Markdown
Member

Fixes: #1282

Summary

This PR fixes the computation of scheduledDistanceAlongTrip for on-time vehicles.

Previously, the value was only calculated when scheduleDeviation != 0, causing vehicles with no schedule deviation to incorrectly report:

"scheduledDistanceAlongTrip": 0

instead of a value equal to distanceAlongTrip.

This behavior differs from the Java reference implementation, which reports:

scheduledDistanceAlongTrip == distanceAlongTrip

whenever scheduleDeviation == 0.

Changes

  • Remove the scheduleDeviation != 0 guard when computing scheduledDistanceAlongTrip.
  • Ensure on-time vehicles report scheduledDistanceAlongTrip equal to distanceAlongTrip.
  • Add a test covering the zero schedule deviation case.

Result

scheduledDistanceAlongTrip now matches the Java implementation and the API specification for both delayed/early and on-time vehicles.

Summary by CodeRabbit

  • Bug Fixes
    • Improved trip status accuracy for vehicles with valid GPS and route data.
    • Scheduled distance now reflects actual distance when a vehicle is on time, even when stop-time or schedule-deviation data is unavailable.

@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 1a63b442-9142-4ba1-854b-9f4c300bc788

📥 Commits

Reviewing files that changed from the base of the PR and between 3b73fd9 and 9df1662.

📒 Files selected for processing (2)
  • internal/restapi/trips_helper.go
  • internal/restapi/trips_helper_test.go

📝 Walkthrough

Walkthrough

BuildTripStatus now calculates ScheduledDistanceAlongTrip without requiring schedule deviation or stop times. The test verifies that an on-time vehicle reports scheduled distance equal to actual distance.

Changes

Trip status distance calculation

Layer / File(s) Summary
Scheduled distance calculation and validation
internal/restapi/trips_helper.go, internal/restapi/trips_helper_test.go
BuildTripStatus always calculates scheduled distance when GPS and route shape data are valid. The test verifies zero schedule deviation and equality between actual and scheduled distance.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: burma-shave

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the fix for scheduledDistanceAlongTrip when scheduleDeviation is zero.
Linked Issues check ✅ Passed The changes remove the zero-deviation limitation, return actual distance for on-time vehicles, and add the required test.
Out of Scope Changes check ✅ Passed The changes are limited to the trip-status calculation and its targeted test, with no unrelated code changes.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud

sonarqubecloud Bot commented Aug 2, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown

Performance Smoke Test Results

Status: PASSED

Metric Value
p(95) latency 1.9 ms
Error rate 0.00%
Total requests 332
Req/sec 11.0

Smoke test config: 5 VUs x 30s. Thresholds: p(95) < 300ms, error rate < 1%.

Full results uploaded as workflow artifact: k6-smoke-summary.

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.

trip-status: fix scheduledDistanceAlongTrip when scheduleDeviation is 0

1 participant