Published
Edited
Oct 1, 2022
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

{
const incidentsByMonth = d3.group(data, d => d.dateTime.getMonth() + 1); // Group data by month (into map of arrays)

// Iterate through map to get size of each month array (ie. number of incidents)
const incidentCounts = [];
const i = 0;
for (let i = 1; i < 13; i++) {
incidentCounts.push(String(incidentsByMonth.get(i).length) + ' in month ' + (i))
}

return incidentCounts // It looks as though their was a spike in incidents in May, June and July.
};

Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// Out of all unique causes, what were the three that occured the most?
{
const causes = [];
for (let obj of data) {
causes.push(obj.cause)
}

const counts = {};
for (const c of causes) {
counts[c] = counts[c] ? counts[c] + 1 : 1;
}
return counts

// Our top three causes (excluding unspecified) are:
// 1. Driver Inattention/Distraction
// 2. Following Too Closely
// 3. Failure to Yield Right-of-Way
}
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