Published
Edited
Sep 15, 2021
1 fork
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// summarise shower time and water usage
water_usage = aq.from(data)
.params({water_ml_per_second: water_ml_per_second})
.groupby('shower')
.rollup({
length_seconds: d => op.max(d.time)
})
.derive({water_used_ml: d => water_ml_per_second * d.length_seconds})
.objects()
Insert cell
// stats on water use
results = aq.from(water_usage)
.rollup({
avg_water_per_shower_ml: d => op.mean(d.water_used_ml),
sd_water_per_shower_ml: d => op.stdev(d.water_used_ml),
total_water_used_ml: d => op.sum(d.water_used_ml)
})
.objects()[0]
Insert cell
// convert mL to gallons
function mlToGallon(ml) {
return ml / 3785.41
}
Insert cell
// reminded of repeat from https://observablehq.com/@observablehq/observable-for-jupyter-users
function emojifyShower(column) {
return '💧'.repeat(Math.round(mlToGallon(results[column])))
}
Insert cell
display_avg_water = mlToGallon(results['avg_water_per_shower_ml']).toFixed(2)
Insert cell
display_sd_water = mlToGallon(results['sd_water_per_shower_ml']).toFixed(2)
Insert cell
display_total_water = mlToGallon(results['total_water_used_ml']).toFixed(2)
Insert cell
Insert cell
Insert cell
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