Public
Edited
Mar 21, 2023
Insert cell
Insert cell
Insert cell
viewof radioSort = Inputs.radio(["crashRetirementPercent", "pointsFinishPercent", "pointsPerCrashRetirement"],
{label: "Descending Sort by:", value: "crashRetirementPercent"})
Insert cell
haas_summary.view()
Insert cell
haas_summary = aq.from(query)
.params({
radioSort: radioSort
})
.groupby("surname")
.rollup({
avg_points: d => op.mean(d.points),
total_points: d => op.sum(d.points),
crash_retirements: d => op.sum(op.includes(["Accident", "Collision", "Collision damage", "Withdrew"], d.status)),
points_finishes: d => op.sum(d.points > 0),
races: d => op.count()
})
.derive({
crashRetirementPercent: d => d.crash_retirements / d.races,
pointsFinishPercent: d => d.points_finishes / d.races,
pointsPerCrashRetirement: d => d.total_points / d.crash_retirements
})
.filter(d => d.races > 20) // get rid of pietro Fitipaldi
.orderby(aq.desc(radioSort))
.select(aq.not("total_points"))
Insert cell
Insert cell
viewof yearSummarySelect = Inputs.select(query.map(d => d3.format("d")(d.year)),
{label: "Select one", unique: true, value: "2022"})
Insert cell
haas_summary_year.view()
Insert cell
haas_summary_year = aq.from(query)
.params({yearSummarySelect: yearSummarySelect})
.filter(d => d.year == yearSummarySelect)
.groupby("surname")
.rollup({
total_points: d => op.sum(d.points),
crash_retirements: d => op.sum(op.includes(["Accident", "Collision", "Collision damage", "Withdrew"], d.status)),
points_finishes: d => op.sum(d.points > 0),
races: d => op.count()
})
.derive({
crashRetirementPercent: d => d.crash_retirements / d.races,
pointsFinishPercent: d => d.points_finishes / d.races,
pointsPerCrashRetirement: d => d.total_points / d.crash_retirements
})
//.filter(d => d.races > 20) // get rid of pietro Fitipaldi
.orderby(aq.desc("pointsPerCrashRetirement"))
//.select(aq.not("total_points"))
Insert cell
Insert cell
Plot.plot({
x:{
tickFormat: "p"
},
y:{
tickFormat: "p"
},
marks:[
Plot.text(haas_summary, {x: "crashRetirementPercent", y: "pointsFinishPercent", text: "surname"}),
Plot.ruleX([0]),
Plot.ruleY([0])
]
})
Insert cell
pointsFinishCountsYear = aq.from(query)
.filter(d => !op.includes(
["Fittipaldi", "Gutiérrez", "Mazepin"], d.surname)
) // already know these guys never scored
.groupby("year", "surname")
.rollup({
points_finishes: d => op.sum(d.points > 0),
points_scored: d => op.sum(d.points)
})
Insert cell
viewof pointsVar = Inputs.radio(new Map([["# of points finishes", "points_finishes"],
["Total points scored", "points_scored"]]),
{label: "Plot variable:", value: "points_finishes"})
Insert cell
Plot.plot({
x:{
tickFormat: "d"
},
color: {
legend: true
},
marks: [
Plot.barY(pointsFinishCountsYear, {x: "year", y: pointsVar, fill: "surname",
title:(d) =>
`${d.surname} \n ${d.year} \n ${d.points_finishes} points finishes \n ${d.points_scored} points scored`
})
]
})
Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
x:{
tickFormat: "d"
},
y:{
tickFormat: "p"
},
marks:[
Plot.line(hulk_summary, {x: "year", y: "crashRetirementPercent"}),
Plot.dot(hulk_summary, {x: "year", y: "crashRetirementPercent",
title: (d) =>
`${d.year} \n Races: ${d.races} \n ${d.total_points} points scored`
}
)
]
})
Insert cell
Insert cell
hulk_summary = aq.from(hulk)
.groupby("year")
.rollup({
avg_points: d => op.mean(d.points),
total_points: d => op.sum(d.points),
crash_retirements: d => op.sum(op.includes(["Accident", "Collision", "Collision damage"], d.status)),
points_finishes: d => op.sum(d.points > 0),
races: d => op.count()})
.derive({
crashRetirementPercent: d => d.crash_retirements / d.races,
pointsFinishPercent: d => d.points_finishes / d.races,
pointsPerCrashRetirement: d => d.total_points / d.crash_retirements
})
Insert cell
Insert cell
Insert cell
import {Plot} from "@mkfreeman/plot-tooltip"
Insert cell
import {op, aq} from "@uwdata/arquero"
Insert cell
Insert cell
database = FileAttachment("f1_db.sqlite").sqlite()
Insert cell
database
SELECT res.grid, drivers.driverRef, drivers.surname, res.laps, res.position, res.points, ra.year, ra.name, st.status
FROM results AS res
LEFT JOIN races AS ra
on res.raceId=ra.raceID
LEFT JOIN drivers
on res.driverId=drivers.driverId
LEFT JOIN status AS st
on res.statusId=st.statusId
LEFT JOIN constructors AS co
on res.constructorId=co.constructorId
WHERE st.status NOT IN ("Did not qualify", "Did not prequalify") AND
co.constructorRef = 'haas';
Insert cell
database
SELECT res.grid, drivers.driverRef, drivers.surname, res.laps, res.position, res.points, ra.year, ra.name, st.status
FROM results AS res
LEFT JOIN races AS ra
on res.raceId=ra.raceID
LEFT JOIN drivers
on res.driverId=drivers.driverId
LEFT JOIN status AS st
on res.statusId=st.statusId
LEFT JOIN constructors AS co
on res.constructorId=co.constructorId
WHERE st.status NOT IN ("Did not qualify", "Did not prequalify") AND
drivers.driverRef = 'hulkenberg' AND YEAR >= 2016;
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more