Repository navigation
Commit 2c539cc
committed
fix(eta,carriers): disambiguate colliding US state codes; correct two metric denominators
#1665 — LOCATION_TOKENS maps bare two-letter tokens, and three of them are also
US state codes: CA (Canada), DE (Germany) and IN (India). So 'Los Angeles, CA'
matched the city table (US) and the country table (CA) and resolveZone rejected it
as a conflicting location, while 'Indianapolis, IN' — a city with no entry —
silently resolved to the Asia zone and quoted a 12-day transit. The whole-token
guarantee the country table relies on does not help: US state codes *are*
legitimate whole tokens.
Adds a US state table and reads a trailing bare state code as a state under two
deliberate restrictions. It applies only when the city table matched nothing, so
a known city keeps deciding its own zone — that is what preserves 'Toronto, CA'
as Canada while 'Los Angeles, CA' becomes US — and only when a token precedes
it, so a bare 'DE' still resolves to Germany as the existing spec requires. The
city path also suppresses the trailing state code from the country table, since
that duplicate report is precisely what made 'Los Angeles, CA' a conflict, but
only for the immediate 'City, ST' shape so 'Lagos, NG vs CA' still reports its
real conflict.
The unavoidable trade-off, documented in the code: a city absent from CITY_TOKENS
followed by a colliding code is now read as a state, so 'Frankfurt, DE' resolves
to Delaware. Nothing in that string distinguishes the two. Typing the country
name resolves it, because the country table matches the explicit name first.
#1666 — two denominators were wrong. onTimeRate divided by every delivered or
completed shipment while the numerator required both an actual and an estimated
delivery date; estimatedDeliveryDate is optional at creation, so a shipment with
no estimate was always counted as not on time. The denominator now requires an
estimate. cancellationRate counted every cancelled shipment against the carrier
regardless of who cancelled it, penalising them for the shipper's decisions; it
now counts only cancellations where the status history records the carrier as the
actor via changedById. Both counts are returned alongside the rates so a caller
can see how few deliveries a rate rests on.
Verified by running the real logic rather than by inspection: all four acceptance
cases fixed, and the three existing getMyMetrics tests still pass against their
positional mock.1 parent 1076a4b commit 2c539cc
2 files changed
Lines changed: 131 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
39 | 44 | | |
40 | 45 | | |
41 | 46 | | |
42 | 47 | | |
43 | 48 | | |
44 | 49 | | |
45 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
46 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
47 | 69 | | |
48 | 70 | | |
49 | 71 | | |
50 | 72 | | |
51 | 73 | | |
52 | 74 | | |
53 | 75 | | |
| 76 | + | |
54 | 77 | | |
55 | 78 | | |
56 | 79 | | |
| |||
75 | 98 | | |
76 | 99 | | |
77 | 100 | | |
78 | | - | |
| 101 | + | |
79 | 102 | | |
80 | 103 | | |
81 | 104 | | |
82 | 105 | | |
83 | 106 | | |
84 | | - | |
| 107 | + | |
85 | 108 | | |
86 | 109 | | |
87 | 110 | | |
88 | 111 | | |
89 | | - | |
| 112 | + | |
| 113 | + | |
90 | 114 | | |
91 | 115 | | |
92 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
93 | 123 | | |
94 | 124 | | |
95 | 125 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
215 | 248 | | |
216 | 249 | | |
217 | 250 | | |
| |||
232 | 265 | | |
233 | 266 | | |
234 | 267 | | |
235 | | - | |
| 268 | + | |
236 | 269 | | |
237 | 270 | | |
238 | 271 | | |
| |||
248 | 281 | | |
249 | 282 | | |
250 | 283 | | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
255 | 289 | | |
256 | 290 | | |
257 | 291 | | |
258 | 292 | | |
259 | 293 | | |
260 | 294 | | |
261 | 295 | | |
262 | | - | |
263 | | - | |
| 296 | + | |
| 297 | + | |
264 | 298 | | |
265 | 299 | | |
266 | 300 | | |
267 | 301 | | |
268 | 302 | | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
269 | 306 | | |
270 | 307 | | |
271 | 308 | | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
272 | 360 | | |
273 | 361 | | |
| 362 | + | |
| 363 | + | |
274 | 364 | | |
275 | 365 | | |
276 | 366 | | |
| |||
0 commit comments