Published
Edited
Apr 16, 2022
Insert cell
Insert cell
Insert cell
Insert cell
clean(tempTable, ["time0", "mean_speed"])
Insert cell
Insert cell
tempTable = {
let twoDims = flights
.groupby({
time0: (d) => op.round(d.time),
distance0: (d) => op.round(d.distance / 100) * 100
})
.rollup({
mean_speed: (d) => op.round(op.mean(d.distance / d.time)),
count: (d) => op.count()
})
.orderby("time0", "distance0")
.reify();

//return twoDims;
let oneDim = flights
.groupby({
time0: (d) => op.round(d.time)
})
.rollup({
mean_speed: (d) => op.round(op.mean(d.distance / d.time))
})
.orderby("time0")
.reify();

return append(oneDim, twoDims);
}
Insert cell
tempTable.view({ limit: 13, offset: 400 })
Insert cell
Insert cell
// 准备缓存时,需要同时 groupby filter 的维度
// 查询缓存,需要先筛选出缓存数据,聚合的时候,count => sum
query0 = tempTable
.filter((d) => d.time0 !== undefined && d.distance0 !== undefined)
.filter((d) => d.distance0 === 400)
.groupby("time0")
.rollup({ count: (d) => op.sum(d.count) })
.view(13)
Insert cell
// filter distance = 400,groupBy time,count
expectResult0 = flights
.filter((d) => op.round(d.distance / 100) * 100 === 400)
.groupby({ time0: (d) => op.round(d.time) })
.rollup({ count: (d) => op.count() })
.orderby("time0")
.view(13)
Insert cell
Insert cell
// 查询缓存,需要先筛选出缓存数据,获取聚合的时候,只能 select
query1 = tempTable
.filter((d) => d.time0 !== undefined && d.distance0 !== undefined)
.filter((d) => d.distance0 === 400 || d.distance0 === 500) // 这里出问题了!
.select("time0", "mean_speed")
.view(13)
Insert cell
expectResult1 = flights
.filter(
(d) =>
op.round(d.distance / 100) * 100 === 400 ||
op.round(d.distance / 100) * 100 === 500
)
.groupby({
time0: (d) => op.round(d.time)
})
.rollup({
mean_speed: (d) => op.round(op.mean(d.distance / d.time))
})
.orderby("time0")
.view(13)
Insert cell
Insert cell
flights = aq.loadArrow(
"https://vega.github.io/vega-datasets/data/flights-200k.arrow"
) // 测试数据
Insert cell
flights.view(5)
Insert cell
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