Public
Edited
Nov 16, 2023
Insert cell
Insert cell
parsetime = d3.timeParse("%b %d, %Y")
Insert cell
parsetimeb = d3.timeParse('%m/%d/%Y')
Insert cell
formattime = d3.timeFormat("%B %Y")
Insert cell
views = FileAttachment("VC GRAPHS - Audio Episode Views.csv")
.csv()
.then((data) => {
const parseCommas = (d) => Number(d.replace(/,/g, ""));
return data.map((row) => ({
...row,
rawDate: parsetime(row["Video publish time"]),
date: formattime(parsetime(row["Video publish time"])),
Views: parseCommas(row.Views)
}));
})
Insert cell
rolledViews = d3
.rollups(
views,
(v) => {
return {
min: d3.min(v, (d) => d.Views),
mean: d3.mean(v, (d) => d.Views),
median: d3.median(v, (d) => d.Views),
max: d3.max(v, (d) => d.Views),
rawDate: v[0].rawDate
};
},
(d) => d.date
).map((d) => ({ date: d[0], ...d[1] })).sort((a,b) => d3.ascending(a.rawDate, b.rawDate))
Insert cell
videoWatchTimes = FileAttachment("VC GRAPHS - Video Episode Watch time.csv")
.csv()
.then((data) => {
const parseCommas = (d) => Number(d.replace(/,/g, ""));
return data.map((row) => ({
...row,
rawDate: parsetimeb(row["Date"]),
date: formattime(parsetimeb(row["Date"])),
"Watch time (minutes)": parseCommas(row["Watch time (minutes)"])
}));
})

Insert cell
rolledVideoWatchTimes = d3
.rollups(
videoWatchTimes,
(v) => {
return {
min: d3.min(v, (d) => d["Watch time (minutes)"]),
mean: d3.mean(v, (d) => d["Watch time (minutes)"]),
median: d3.median(v, (d) => d["Watch time (minutes)"]),
max: d3.max(v, (d) => d["Watch time (minutes)"]),
rawDate: v[0].rawDate
};
},
(d) => d.date
)
.map((d) => ({ date: d[0], ...d[1] }))
.sort((a, b) => d3.ascending(a.rawDate, b.rawDate))
Insert cell
audioWatchTimes = FileAttachment("VC GRAPHS - Audio Episode Watch Time .csv").csv()
.then((data) => {
const parseCommas = (d) => Number(d.replace(/,/g, ""));
return data.map((row) => ({
...row,
rawDate: parsetime(row["Video publish time"]),
date: formattime(parsetime(row["Video publish time"])),
"Watch time (minutes)": parseCommas(row["Watch time (minutes)"])
}));
})
Insert cell
rolledAudioWatchTimes = d3
.rollups(
audioWatchTimes,
(v) => {
return {
min: d3.min(v, (d) => d["Watch time (minutes)"]),
mean: d3.mean(v, (d) => d["Watch time (minutes)"]),
median: d3.median(v, (d) => d["Watch time (minutes)"]),
max: d3.max(v, (d) => d["Watch time (minutes)"]),
rawDate: v[0].rawDate
};
},
(d) => d.date
)
.map((d) => ({ date: d[0], ...d[1] }))
.sort((a, b) => d3.ascending(a.rawDate, b.rawDate))
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more