Skip to content

Commit 674aa65

Browse files
ryan-williamsclaude
andcommitted
www: two CIC-fast-follow fixes
- `RegionNotFound.suggestCounties`: skip `cc=99` (Port Authority) — it's a bridges/tunnels jurisdiction, not a real NJ county, so it shouldn't appear as a "did you mean" match. Discovered by CIC after `/c/notacounty` suggested it. - `FatalitiesPerYearPlot`: sum `trailing_365` client-side over the active `t=` subset. Previously the header always showed the all-type total, misleading when the plot bars were filtered (e.g. `t=e` filtered bars but header still said "575 deaths" — the all-type count). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 24f6dfc commit 674aa65

2 files changed

Lines changed: 27 additions & 11 deletions

File tree

www/src/components/RegionNotFound.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ function suggestCounties(
1313
{ limit = 3, threshold = 0.4 }: { limit?: number, threshold?: number } = {},
1414
): CountySuggestion[] {
1515
const target = slug.toLowerCase()
16-
const scored: CountySuggestion[] = Object.entries(cc2mc2mn).map(([cc, county]) => {
16+
// Exclude `cc=99` (Port Authority — bridges/tunnels jurisdiction, not
17+
// a real NJ county) so we don't offer it as a "did you mean" match.
18+
const scored: CountySuggestion[] = Object.entries(cc2mc2mn)
19+
.filter(([cc]) => Number(cc) !== 99)
20+
.map(([cc, county]) => {
1721
const candSlug = normalize(county.cn)
1822
// Inline Levenshtein call would create a cycle; just proxy through
1923
// `suggestMunis` semantics — but we want county names, so replicate

www/src/njsp/FatalitiesPerYearPlot.tsx

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,16 @@ type TypeCounts = {
7878
passenger: number
7979
}
8080

81-
// Projection row also carries trailing-365d total — same shape as TypeCounts
82-
// but with one extra field. Separate type so `keyof TypeCounts` (used by
83-
// `typesMap` for per-victim-type indexing) doesn't pick up `trailing_365`.
84-
type ProjectionRow = TypeCounts & { trailing_365: number }
81+
// Projection row carries trailing-365d totals split by victim type so the
82+
// header can filter to the active `t=` subset client-side. Separate type
83+
// so `keyof TypeCounts` (used by `typesMap` for per-victim-type indexing)
84+
// doesn't pick up the `trailing_365_*` extras.
85+
type ProjectionRow = TypeCounts & {
86+
trailing_365_driver: number
87+
trailing_365_pedestrian: number
88+
trailing_365_cyclist: number
89+
trailing_365_passenger: number
90+
}
8591

8692
const curYear = new Date().getFullYear()
8793
const prvYear = curYear - 1
@@ -102,10 +108,10 @@ const typeCountsQuery = (county: string | null, cc: number | null, mc: number |
102108
CAST(sum(pedestrian) as INT) as pedestrian,
103109
CAST(sum(cyclist) as INT) as cyclist,
104110
CAST(sum(passenger) as INT) as passenger,
105-
CAST(sum(trailing_365_driver
106-
+ trailing_365_pedestrian
107-
+ trailing_365_cyclist
108-
+ trailing_365_passenger) as INT) as trailing_365
111+
CAST(sum(trailing_365_driver) as INT) as trailing_365_driver,
112+
CAST(sum(trailing_365_pedestrian) as INT) as trailing_365_pedestrian,
113+
CAST(sum(trailing_365_cyclist) as INT) as trailing_365_cyclist,
114+
CAST(sum(trailing_365_passenger) as INT) as trailing_365_passenger
109115
FROM read_csv_auto('projected')
110116
${where}
111117
`
@@ -288,7 +294,7 @@ export function FatalitiesPerYearPlot({ id = "per-year", initialCounty = null, c
288294

289295
// Projected current-year totals (statewide / county / municipality).
290296
const projectionsQueryStr = useMemo(() => typeCountsQuery(county, propCc ?? null, propMc ?? null), [county, propCc, propMc])
291-
const [projections] = useQuery<ProjectionRow>({ db: projectionsDb, query: projectionsQueryStr, init: [{ driver: 0, pedestrian: 0, cyclist: 0, passenger: 0, trailing_365: 0 }] })
297+
const [projections] = useQuery<ProjectionRow>({ db: projectionsDb, query: projectionsQueryStr, init: [{ driver: 0, pedestrian: 0, cyclist: 0, passenger: 0, trailing_365_driver: 0, trailing_365_pedestrian: 0, trailing_365_cyclist: 0, trailing_365_passenger: 0 }] })
292298
const monthlyQueryStr = useMemo(() => monthlyQueryFn(county, propCc ?? null, propMc ?? null), [county, propCc, propMc])
293299
const monthlyRowsAll = useQuery<MonthlyRow>({ db: monthlyDb, query: monthlyQueryStr, init: [] })
294300

@@ -853,13 +859,19 @@ export function FatalitiesPerYearPlot({ id = "per-year", initialCounty = null, c
853859
const total2021 = yearTotals[2021]?.actual ?? 0
854860
const total2022 = yearTotals[2022]?.actual ?? 0
855861
const countyLabel = regionLabel ?? (county ? `${county} County` : "NJ")
862+
// Sum trailing-365d only over the active `t=` subset so the header
863+
// headline tracks the same filter the plot bars reflect.
864+
const trailing365 = selectedTypeKeys.reduce(
865+
(sum, t) => sum + (projections[`trailing_365_${t}` as keyof ProjectionRow] as number),
866+
0,
867+
)
856868

857869
return (
858870
<div ref={containerRef}>
859871
<h2 id={id}>
860872
<a href={`#${id}`}>Car Crash Deaths</a>
861873
</h2>
862-
<div className={css.subtitle}>{activeType ? `${TYPE_SINGULAR[activeType]} ` : ''}Fatalities{effectivePerCapita ? ' per 100k population' : ''}, {yearRange ? `${yearRange[0]}${yearRange[1]}` : '2001–present'}{regionLabel ? ` · ${regionLabel}` : initialCounty ? ` · ${initialCounty} County` : ''}{projections.trailing_365 > 0 ? ` · Last 365 days: ${projections.trailing_365.toLocaleString()} deaths` : ''}</div>
874+
<div className={css.subtitle}>{activeType ? `${TYPE_SINGULAR[activeType]} ` : ''}Fatalities{effectivePerCapita ? ' per 100k population' : ''}, {yearRange ? `${yearRange[0]}${yearRange[1]}` : '2001–present'}{regionLabel ? ` · ${regionLabel}` : initialCounty ? ` · ${initialCounty} County` : ''}{trailing365 > 0 ? ` · Last 365 days: ${trailing365.toLocaleString()} deaths` : ''}</div>
863875
<PlotWrapper
864876
key={`${timeGranularity}-${activeType ?? 'all'}-${highlightProjected}-${showPop ? 'pop' : 'nopop'}`}
865877
id={id}

0 commit comments

Comments
 (0)