REPOSITORY CODING · MEDIUM
Keep threshold-equal trajectory segments
A segment lasting exactly maxGap belongs in the report. Reject only longer gaps while preserving positive duration requirements.
Geospatial trajectory analyticsMobility segment laboratory
Work through a real codebase.
Choose an environment, investigate the existing implementation and use the tests to check your change. Sign in to open a workspace; execution and Ono usage follow your plan’s allowances.
Task requirements and environments
PySpark · 55 minute session
- Build movement segments with real Spark windows and aggregations from up to 40 GPS observations. Coordinates are integer microdegrees in valid latitude/longitude bounds. Times and observation sequences are bounded nonnegative integers. Validate equal-ID/equal-observed conflicting deliveries.
- Filter observations by inclusive asOf and through before selecting the latest delivery per ID. For multiple IDs at one user/timestamp, retain the lexicographically smallest ID. Form consecutive segments independently per user in timestamp order.
- Keep segments with positive elapsed time <= maxGap and great-circle distance <= maxSpeed*elapsed. Haversine uses radians and Earth radius 6371000 meters, with its intermediate probability clamped into [0,1]. Round each retained segment distance to nearest integer meter, halves upward, before aggregating. Zero-speed stationary segments are valid.
- Assign elapsed seconds and rounded meters to the starting-point grid cell. Grid widths are one of 1,2,5,10,15,30,45,90,180 degrees; bins start at -90/-180, longitude +180 wraps to -180 and the north pole belongs to the final latitude bin. Return sorted segments, per-user cells and totals including users with no retained segment.
- Per-user duration, distance and segment counts must conserve their accepted segment/cell sums. The native Spark session is bounded, shared across fixtures and never contacts a mapping service.