Public
Edited
Feb 6, 2023
1 fork
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data = parseRows(activities, columnConfig)
.filter((row) => row.type === "Run")
.filter((row) => row.date > new Date("2022-08-01"))
Insert cell
columnConfig = [
{
id: "id",
columnName: "Activity ID",
type: "string"
},
{
id: "date",
columnName: "Activity Date",
type: "date"
},
{ id: "type", columnName: "Activity Type", type: "string" },
{
id: "duration",
columnName: "Elapsed Time",
type: "decimal"
},
{ id: "distance", columnName: "Distance", type: "decimal" },
{ id: "avgSpeed", columnName: "Average Speed", type: "decimal" },
{ id: "avgHeartRate", columnName: "Average Heart Rate", type: "decimal" }
]
Insert cell
function parseRows(list, columnConfig) {
return list.map((row) =>
columnConfig.reduce((acc, col) => {
return { ...acc, [col.id]: parseCell(row[col.columnName], col.type) };
}, {})
);
}
Insert cell
function parseCell(value, type) {
switch (type) {
case "date":
return new Date(value);
case "integer":
return Number.parseInt(value, 10);
case "decimal":
case "float":
return Number.parseFloat(value);
case "string":
default:
return value;
}
}
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