Public
Edited
Feb 12, 2024
Insert cell
Insert cell
// Define a function to round the timestamp to the nearest 5 minutes
const roundToFiveMinutes = timestamp => {
const date = new Date(timestamp);
const roundedMinutes = Math.floor(date.getMinutes() / 5) * 5;
date.setMinutes(roundedMinutes);
date.setSeconds(0);
return date.toISOString();
};

// Group the data into 5-minute bins
data.forEach(entry => {
const roundedTimestamp = roundToFiveMinutes(entry.timestamp);
const key = `${entry.tracking_source}-${roundedTimestamp}`;

if (!groupedData.has(key)) {
groupedData.set(key, {
tracking_source: entry.tracking_source,
timestamp: roundedTimestamp,
count: 0
});
}

groupedData.get(key).count++;
});

// Convert the map values to an array
const result = Array.from(groupedData.values());
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