mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
The report priced every departure against its planned origin-to-destination corridor, so a train that worked several station-to-station moves showed one row and one distance. Ton/Km and Vehicle-Km were then computed against that single corridor and understated the work actually done. The row grain is now the leg: consecutive checkpoint events at different yards, read with lead() over each schedule. DISTINCT because a train that works the same pair twice in one departure is still one leg — without it the join fans the cargo out and doubles every SUM in the group. Both ends fall back to the schedule's own corridor, so a departure with no checkpoints logged keeps exactly the single row it had before. Only query() joins the legs. The KPIs stay corridor-level and would count the same cargo once per leg if they had that join.