Published
Edited
Apr 29, 2021
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
d3 = require("d3-array", "d3-dsv@2", "d3-time", "d3-time-format")
Insert cell
matches = d3.csvParse(await FileAttachment("matches.csv").text(), d3.autoType)
Insert cell
timeWasted = d3.sum(matches, d => d.gameDuration)
Insert cell
function minutes(duration){
return parseInt(duration/60)
}
Insert cell
function hours(duration){
return parseInt(duration/(60*60))
}
Insert cell
function days(duration){
return parseInt(duration/(24*60*60))
}
Insert cell
firstGame = d3.min(matches, d => d.gameCreation)
Insert cell
lastGame = d3.max(matches, d => d.gameCreation)
Insert cell
function formatDate(d) {
var format = d3.timeFormat("%d/%m/%Y");
return format(d);
}
Insert cell
daysList = [...new Set(d3.map(matches, d => {
var format = d3.timeFormat("%Y-%m-%d");
return format(d.gameCreation)
}))]
Insert cell
totalDurationByDay = d3.rollup(matches,
v => d3.sum(v, d => d.gameDuration),
d => {
var format = d3.timeFormat("%Y-%m-%d");
return format(d.gameCreation)
})
Insert cell
meanDuration = parseInt(d3.mean(d3.map(totalDurationByDay, d => d[1])) / 60)
Insert cell
interval = d3.utcDay.every(1) // sample frequency
Insert cell
stop = interval() // exclusive
Insert cell
start = interval.offset(stop, -d3.timeDay.count(firstGame, lastGame))
Insert cell
import { TimeAxis, TimeChart, wave } from "@observablehq/timechart"
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