Skip to content

punctualityRate

  • Legs, dwell, cut-offs and punctuality, shared by road, rail, sea and air.
punctualityRate(pairs: PlannedActual[], tolerance: PunctualityTolerance): OnTimeRate | null

The share of planned/actual pairs that were on time under one tolerance.

  • A rate is a count under a stated tolerance: the same arrivals give a different rate under a 60-minute tolerance than under a 120-minute one, so the tolerance travels with the number.
  • Each pair is classified by classifyPunctuality’s rule under the same tolerance: late and early are read once, before any pair, so the whole list is judged under one tolerance. Only "onTime" counts: with an early tolerance, an early arrival is not on time; without one, it is.
  • rate is onTime / total as a plain number (0.75), not rounded.
  • Every pair must be valid: one invalid pair returns null, never a rate over the rest.
  • An empty list returns null: no arrivals have no rate.
  • Anything beyond a rate — percentiles, causes — is the consumer’s.
ParameterTypeDescription
pairsPlannedActual[]the planned and actual time of each arrival
tolerancePunctualityTolerancelate (required) and early (optional) tolerances, as classifyPunctuality takes them

the on-time count, the total and the rate (null for an empty list), or null on invalid input

One planned/actual pair for punctualityRate.

import type { PlannedActual } from "@northguild/gmt";
MemberTypeDescription
plannedstringThe planned time, as an ISO 8601 instant or zoned datetime string.
actualstringThe actual time, as an ISO 8601 instant or zoned datetime string.

What punctualityRate returns: the on-time count, the total, and their ratio.

import type { OnTimeRate } from "@northguild/gmt";
MemberTypeDescription
onTimenumberThe number of pairs classifyPunctuality calls "onTime".
totalnumberEvery pair counted.
ratenumberThe on-time share, onTime / total, from 0 to 1.
import { punctualityRate } from "@northguild/gmt/transport/calculate";
punctualityRate([{ planned: "2024-06-15T10:00:00Z", actual: "2024-06-15T10:05:00Z" }, { planned: "2024-06-15T10:00:00Z", actual: "2024-06-15T10:14:00Z" }, { planned: "2024-06-15T10:00:00Z", actual: "2024-06-15T10:16:00Z" }, { planned: "2024-06-15T10:00:00Z", actual: "2024-06-15T09:57:00Z" }], { late: "PT15M" }) // { onTime: 3, total: 4, rate: 0.75 }
pairs
output 

transport/calculate/punctualityRate.ts