function count_by(groups, weight, filter_col_name = "INSTNM", filter_vals = my_schools.map(k => schools.indexOf(k))) {
const start = Date.now()
const mask = new Uint8Array(table.length)
let i = 0;
const schools_ix = new Set(filter_vals)
const filter_col = table.getColumn(filter_col_name)
const hits = []
for (let batch of filter_col.chunks) {
for (const ix of batch.indices) {
if (schools_ix.has(ix)) {
mask[i] = 1
hits.push(i)
}
i++
}
}
const cols = groups.map(group => {
const col = table.getColumn(group);
if (col.indices) return col.indices
return col
})
function *yielder() {
let value = table.getColumn(weight);
for (let ix of hits) {
const obj = {};
const row = [
value.get(ix),
...cols.map((col, col_index) => {
const val = col.get(ix)
return val
})
]
yield row
}
}
console.log("_________")
const rolled = d3.rollup(
yielder(),
entries => d3.sum(entries.map(entry => entry[0])),
...cols.map((col, i) => row => row[i+1])
)
console.log(`counting off the base data took ${Date.now() - start} ms`)
const renamings = new Map()
for (let group of groups) {
const dict = table.getColumn(group).dictionary
if (dict) renamings.set(group, dict.toArray())
}
const flattened = flatten_map(rolled, groups, renamings, weight)
return flattened
}