Skip to content

Implement order tracking intelligence providers#237

Draft
roncodes wants to merge 17 commits into
mainfrom
feature/order-tracking-intelligence
Draft

Implement order tracking intelligence providers#237
roncodes wants to merge 17 commits into
mainfrom
feature/order-tracking-intelligence

Conversation

@roncodes
Copy link
Copy Markdown
Member

Summary

This refactors FleetOps order tracking into a provider-neutral Order Tracking Intelligence layer instead of the old monolithic OrderTracker OSRM helper.

Root Cause / Current Limitation

OrderTracker was doing too much in one class: stop selection, OSRM calls, progress math, formatting, caching, and fallback behavior. It also only supported OSRM directly, which meant no clean way to use traffic-aware providers or third-party last-mile intelligence providers.

Architecture

  • Replaced OrderTracker internals with a thin compatibility facade over TrackingIntelligenceService.
  • Added a new server/src/Tracking domain with:
    • TrackingContextBuilder
    • TrackingIntelligenceService
    • TrackingProviderManager
    • TrackingProviderRegistry
    • canonical context/options/capabilities/result/stop DTOs
  • Added built-in providers:
    • google_routes
    • osrm
    • calculated
  • Added company-level tracking settings and internal endpoints:
    • GET /settings/tracking-settings
    • POST /settings/tracking-settings
  • Updated OSRM to honor fleetops.osrm.host.

Third-Party Provider Contract

Providers implement TrackingProviderInterface:

public function key(): string;
public function capabilities(): TrackingProviderCapabilities;
public function canTrack(TrackingContext $context): bool;
public function track(TrackingContext $context, TrackingOptions $options): TrackingProviderResult;

Third-party packages can register providers through TrackingProviderRegistry, allowing Mapbox, TomTom, HERE, GraphHopper, Fleet Engine, or proprietary providers without modifying FleetOps core.

Tracker Data Shape

tracker_data is now a canonical nested object with:

  • provider
  • fallback_provider
  • confidence
  • warnings
  • driver
  • progress
  • active_stop
  • next_stop
  • route
  • eta
  • insights
  • capabilities

Ember consumers were updated to read the new nested shape.

Verification

  • php -l on touched backend files
  • php-cs-fixer fix --dry-run --config=.php-cs-fixer.php on touched PHP files
  • git diff --check
  • prettier --check on touched frontend files
  • eslint --no-cache on touched JS files
  • ember-template-lint on touched HBS files

Blocked in local environment:

  • ./server_vendor/bin/pest server/tests/TrackingIntelligenceTest.php fails because the local Pest package is missing server_vendor/pestphp/pest/vendor/autoload.php.
  • ./server_vendor/bin/phpunit --filter tracking delegates back to Pest and fails with Pest's "Please run ./vendor/bin/pest instead" guard.
  • phpstan initially hit sandbox EPERM on its local socket; after escalation it ran but reported many repo/PHPStan-bootstrap issues around Laravel helper discovery, Eloquent magic properties, and generic array annotations.

Notes

Google Fleet Engine is intentionally not implemented here. This PR leaves it as a future enterprise/stateful provider adapter because Fleet Engine has a broader vehicle/task lifecycle than a routing provider.

@roncodes
Copy link
Copy Markdown
Member Author

Follow-up implemented in a1d4680: added Routing & Tracking organization settings, admin Tracking Defaults, provider metadata in tracking-settings responses, boot-time currentUser tracking settings load, richer order Tracking Intelligence display, compact confidence/fallback/stale indicators, and separate summary/provider route cache semantics. Verification: PHP lint/style checks passed; Prettier, ESLint, and ember-template-lint passed for touched frontend files. Pest remains blocked locally because server_vendor/pestphp/pest/vendor/autoload.php is missing and Symfony Console classes are unavailable in the local vendor install.

@roncodes
Copy link
Copy Markdown
Member Author

Tracking display follow-up implemented in 4092d3a: replaced the debug-style tracker panel with an operator summary, removed duplicated stops/route legs from Tracking, formatted ETA/date/distance values, collapsed provider details into a quiet route-quality line, surfaced only one operator-relevant warning, and reduced card/overlay badge clutter to a single compact exception indicator. Verification: Prettier, ESLint, ember-template-lint, and git diff --check passed. Focused Ember test build succeeded, but browser execution failed before loading tests with a global vendor/test harness error: Class extends value undefined / assets/tests.js not loaded.

@roncodes
Copy link
Copy Markdown
Member Author

Tracking panel density follow-up implemented in fcf8c1d: removed the four-column metric layout, reduced metric text size, gave destination its own compact row, wrapped route-quality metadata, replaced the large warning block with a compact warning strip, and tightened label section padding/image sizes. Verification: Prettier, ember-template-lint, and git diff --check passed for the touched template.

@roncodes
Copy link
Copy Markdown
Member Author

Tracking layout correction implemented in 5730556: removed field-info-container from the tracking metric blocks, switched to explicit stacked label/value cards, kept destination stacked and full-width, and restored the warning strip with concrete yellow background classes for dark/light mode instead of opacity utilities. Verification: Prettier, ember-template-lint, and git diff --check passed for the touched template.

@roncodes
Copy link
Copy Markdown
Member Author

Tracking/route ETA split follow-up pushed in 3efc1d7.

Summary:

  • Refactored order tracking into a compact operator summary with driver signal, route quality, warning, waypoint progress, ETA cards, destination, and route summary.
  • Moved stop-level ETA/arrival metadata into the Route panel and RouteList, including total route distance and estimated completion at the top of the route panel.
  • Added cumulative per-leg ETA values to tracker_data.route.legs and fixed invalid driver coordinates such as 0,0 so they are treated as missing driver location and no longer inflate route distance/ETA.

Verification:

  • npx prettier --write on touched frontend files
  • npx eslint --no-cache on touched JS/tests
  • npx ember-template-lint on touched HBS templates
  • ./server_vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php on touched PHP files
  • php -l on touched PHP files
  • git diff --check / git diff --cached --check

Focused test notes:

  • ./server_vendor/bin/pest server/tests/TrackingIntelligenceTest.php is blocked locally because server_vendor/pestphp/pest/vendor/autoload.php is missing and Symfony Console classes are unavailable.
  • npx ember test --filter="tracking-stop-progress|order/details/tracking|route-list" builds successfully, then fails before running selected tests with the existing global vendor/test loader error: Class extends value undefined and tests.js not loaded.

@roncodes
Copy link
Copy Markdown
Member Author

Tracking UI overhaul follow-up pushed in 2022aab.

What changed in this pass:

  • Route panel summary is now a lightweight text row: All Stops on the left, distance/duration on the right.
  • RouteList ETA moved back inline beside status badges, with Current Stop badge and a pulsing active waypoint marker.
  • Tracking panel now follows the mockup structure more closely: compact confidence/driver pills, paired Smart adjusted ETA vs Reported ETA, segmented confidence meter, NOW HEADING TO destination block, compact distance summary, and collapsible diagnostics/warnings.
  • Tracking stop progress no longer prints large waypoint addresses; markers show address details through Attach::Tooltip + InfoBlock/DisplayPlace.
  • Added Ping driver app CTA for stale/missing GPS states, backed by a new POST /orders/{id}/ping-driver endpoint that reuses the existing OrderPing push notification.
  • Added custom CSS in addon/styles/fleetops-engine.css for the tracking intelligence surfaces and pulse effects.

Verification:

  • npx prettier --write on touched files
  • npx ember-template-lint on touched HBS templates
  • npx eslint --no-cache on touched JS/tests
  • npx stylelint addon/styles/fleetops-engine.css
  • ./server_vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php on touched PHP files
  • php -l on touched PHP files
  • git diff --check / git diff --cached --check
  • npx ember build --environment=test completed successfully; existing intl/postcss warnings remain unrelated.

@roncodes
Copy link
Copy Markdown
Member Author

Follow-up tracking UI polish pushed in 83f43fb.

What changed:

  • ETA confidence now renders with a percentage when available, with sensible confidence fallbacks.
  • Reported ETA always renders from reported/active/route duration data and is struck through when confidence/location/fallback state makes it untrusted, with a smaller reason below.
  • Tracking progress strip moved back to the top and given enough vertical height to avoid the internal vertical scrollbar.
  • Warning CTA now matches the warning styling, including the Ping driver app action.
  • Diagnostics trigger now reads like the mockup with a warning count and chevron state.
  • Added reported total and between-stops distance progress bars in the tracking summary when route data is present.
  • Route stop ETA badge uses warning styling and current stop uses the indigo/magic treatment.
  • Updated timestamp moved to the footer with a Recalculate action.
  • Labels block now uses the same compact tracking block surface styling.

Verification:

  • npx prettier --write addon/components/order/details/tracking.js addon/components/order/details/tracking.hbs addon/components/route-list.hbs addon/styles/fleetops-engine.css
  • npx ember-template-lint addon/components/order/details/tracking.hbs addon/components/route-list.hbs addon/components/tracking-stop-progress.hbs
  • npx eslint --no-cache addon/components/order/details/tracking.js addon/components/route-list.js addon/components/tracking-stop-progress.js
  • npx stylelint addon/styles/fleetops-engine.css
  • git diff --check
  • npx ember build --environment=test

Build completed successfully; existing intl/PostCSS warnings are still present in the repo output.

@roncodes
Copy link
Copy Markdown
Member Author

Follow-up pushed in 9356fb6.

Corrections in this pass:

  • Removed per-waypoint distance badges from Route; only ETA/current/completed/status badges remain.
  • Route current stop now uses the Fleetbase component with status=magic.
  • Reduced tracking stop progress scroller min-height to 2rem.
  • Made reported total progress fall back to completed stop percentage and render a small visible fill when route distance exists but progress is 0.
  • Added a FleetOps format-duration helper override so long durations render as days + hours instead of huge hour counts, e.g. 286h becomes 11d 22h.
  • Removed the misleading Smart adjusted ETA 'Due now' branch; zero/empty ETA now shows Pending GPS fix or Pending start depending on driver signal.
  • Refactored purchase-rate cost breakdown to match Ledger invoice line-item styling with a compact table and total footer.

Verification:

  • npx prettier --write addon/components/order/details/tracking.js addon/components/order/details/tracking.hbs addon/components/route-list.hbs addon/components/order/details/purchase-rate.hbs addon/styles/fleetops-engine.css addon/helpers/format-duration.js app/helpers/format-duration.js
  • npx ember-template-lint addon/components/order/details/tracking.hbs addon/components/route-list.hbs addon/components/order/details/purchase-rate.hbs addon/components/tracking-stop-progress.hbs
  • npx eslint --no-cache addon/components/order/details/tracking.js addon/components/route-list.js addon/components/tracking-stop-progress.js addon/components/order/details/purchase-rate.js addon/helpers/format-duration.js app/helpers/format-duration.js
  • npx stylelint addon/styles/fleetops-engine.css
  • git diff --check
  • npx ember build --environment=test

@roncodes
Copy link
Copy Markdown
Member Author

Small route summary fix pushed in c4c6234.

The ALL STOPS count now uses the same buildRoutePointsFromPayload path as RouteList, so the summary count matches the actual rendered pickup/waypoint/dropoff list instead of manually reading payload.waypoints.length from a shape that can report 0.

Verification:

  • npx prettier --write addon/components/order/details/route.js
  • npx eslint --no-cache addon/components/order/details/route.js
  • git diff --check

Note: I left the existing local unstaged edit in addon/components/route-list.hbs untouched.

@roncodes
Copy link
Copy Markdown
Member Author

Small progress strip fix pushed in 3022969.

For pickup/dropoff-only orders, the tracking progress rail no longer centers the first and last dots inside half-width segments. The first stop anchors to the left edge and the final stop anchors to the right edge, so the rail uses the full available width.

Verification:

  • npx prettier --write addon/components/tracking-stop-progress.hbs
  • npx ember-template-lint addon/components/tracking-stop-progress.hbs
  • git diff --check

Note: existing local unstaged addon/components/route-list.hbs change was left untouched.

@roncodes
Copy link
Copy Markdown
Member Author

Tracking settings follow-up pushed in 2aa82eb.

Changes:

  • Tracking provider options now expose label/value while preserving key/name aliases for compatibility.
  • OSRM now renders as OSRM instead of Osrm from both frontend defaults and backend provider metadata.
  • Organization Routing & Tracking settings now use a multi-select for fallback providers.
  • Admin Tracking Defaults also use the same fallback provider multi-select.
  • Save payload still sends provider and fallbacks as provider keys, so backend settings remain stable.

Verification:

  • npx prettier --write addon/controllers/settings/routing.js addon/templates/settings/routing.hbs addon/components/admin/routing-settings.js addon/components/admin/routing-settings.hbs
  • npx ember-template-lint addon/templates/settings/routing.hbs addon/components/admin/routing-settings.hbs
  • npx eslint --no-cache addon/controllers/settings/routing.js addon/components/admin/routing-settings.js
  • php -l server/src/Http/Controllers/Internal/v1/SettingController.php
  • git diff --check
  • npx ember build --environment=test

Note: existing local unstaged addon/components/order/details/purchase-rate.hbs edit was left untouched.

@roncodes
Copy link
Copy Markdown
Member Author

Tracking settings advanced toggle pushed in 4cd16fe.

Changes:

  • Organization Routing & Tracking settings now keep Tracking Provider and Fallback Providers visible by default.
  • Traffic-Aware ETA, Summary Cache TTL, Route Cache TTL, Stale Location Threshold, and Fallback Speed are hidden behind an Advanced Settings toggle.
  • Admin Tracking Defaults now use the same Advanced Settings toggle behavior.
  • Saved settings payload is unchanged; this is UI disclosure only.

Verification:

  • npx prettier --write addon/controllers/settings/routing.js addon/templates/settings/routing.hbs addon/components/admin/routing-settings.js addon/components/admin/routing-settings.hbs
  • npx ember-template-lint addon/templates/settings/routing.hbs addon/components/admin/routing-settings.hbs
  • npx eslint --no-cache addon/controllers/settings/routing.js addon/components/admin/routing-settings.js
  • git diff --check
  • npx ember build --environment=test

Note: existing local unstaged addon/components/order/details/purchase-rate.hbs edit was left untouched.

@roncodes
Copy link
Copy Markdown
Member Author

Small polish for the tracking advanced toggle pushed in b3ac3ce.

Changes:

  • Fallback provider multi-select trigger uses the compact form-input-sm styling in both organization and admin settings.
  • Advanced Settings panel gets top spacing when expanded.
  • Toggle label remains stable as Advanced Settings while the chevron communicates expanded/collapsed state.

Verification:

  • npx prettier --write addon/templates/settings/routing.hbs addon/components/admin/routing-settings.hbs
  • npx ember-template-lint addon/templates/settings/routing.hbs addon/components/admin/routing-settings.hbs
  • git diff --check

Note: existing local unstaged addon/components/order/details/purchase-rate.hbs edit remains untouched.

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.

1 participant