import type { EnrichedResult, Stint, PitStop } from '../types'
import { compareFinishPosition } from '../utils'
import {
TyreStintTimeline,
type StintTimelineRow,
} from './charts/TyreStintTimeline'
interface Props {
results: EnrichedResult[]
stints: Stint[]
pit_stops: PitStop[]
hasStints: boolean
}
export function StrategyView({ results, stints, pit_stops: _pitStops, hasStints }: Props) {
if (!hasStints) {
return (
Stints not available. This session does not have ingested
tyre compound and stint ranges in /api/v1/race-hub. Strategy
charts require per-driver stints: compound, lap_start, lap_end.
{results.length > 0 && (
<>
Laps Completed
from results — hint at pit count
| P |
Driver |
Laps |
{results.map((r) => (
|
{r.position}
|
{r.name_acronym || r.driver_number}
|
0 ? 'var(--text)' : 'var(--text-3)' }}>
{r.number_of_laps > 0 ? r.number_of_laps : '—'}
|
))}
>
)}
)
}
const sortedDrivers = [...results].sort((a, b) => {
const cmp = compareFinishPosition(a.position, b.position)
return cmp !== 0 ? cmp : a.driver_number - b.driver_number
})
const totalLaps = Math.max(
...stints.map((s) => s.lap_end),
...results.map((r) => r.number_of_laps),
1,
)
const timelineRows: StintTimelineRow[] = sortedDrivers.map((driver) => ({
label: driver.name_acronym || String(driver.driver_number),
color: driver.team_colour ? `#${driver.team_colour}` : '#888',
stints: stints
.filter((s) => s.driver_number === driver.driver_number)
.map((s) => ({
compound: s.compound,
lapStart: s.lap_start,
lapEnd: s.lap_end,
isNew: s.tyre_age_at_start === 0,
})),
}))
return (
)
}