punctualityRate
Signature
Section titled “Signature”punctualityRate(pairs: PlannedActual[], tolerance: PunctualityTolerance): OnTimeRate | nullThe 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:lateandearlyare read once, before any pair, so the whole list is judged under one tolerance. Only"onTime"counts: with anearlytolerance, an early arrival is not on time; without one, it is. rateisonTime / totalas 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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
pairs | PlannedActual[] | the planned and actual time of each arrival |
tolerance | PunctualityTolerance | late (required) and early (optional) tolerances, as classifyPunctuality takes them |
Returns
Section titled “Returns”the on-time count, the total and the rate (null for an empty list), or null on invalid input
PlannedActual
Section titled “PlannedActual”One planned/actual pair for punctualityRate.
import type { PlannedActual } from "@northguild/gmt";| Member | Type | Description |
|---|---|---|
planned | string | The planned time, as an ISO 8601 instant or zoned datetime string. |
actual | string | The actual time, as an ISO 8601 instant or zoned datetime string. |
OnTimeRate
Section titled “OnTimeRate”What punctualityRate returns: the on-time count, the total, and their ratio.
import type { OnTimeRate } from "@northguild/gmt";| Member | Type | Description |
|---|---|---|
onTime | number | The number of pairs classifyPunctuality calls "onTime". |
total | number | Every pair counted. |
rate | number | The on-time share, onTime / total, from 0 to 1. |
Related types
Section titled “Related types”Examples
Section titled “Examples”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 }