Published
Edited
Feb 25, 2019
Fork of Calendar
1 fork
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
color = d3.scaleSequential(d3.interpolateYlOrRd).domain([d3.min(data, d => d.value), d3.max(data, d => d.value)])
Insert cell
data = dailyCounts
Insert cell
Insert cell
Insert cell
Insert cell
dataTable = loadData(dataUrl).then(buffer => arrow.Table.from(new Uint8Array(buffer)))
Insert cell
dailyData = groupByDay(dataTable, crimeType)
Insert cell
dailyCounts = Object.keys(dailyData)
.map(day => {
return {date: new Date(new Date(day).getTime() + timezoneOffset), value: dailyData[day].length};
})
Insert cell
timezoneOffset = (new Date().getTimezoneOffset() + 60) * 60 * 1000 // note: +60 for daylight saving time
Insert cell
function groupByDay(dataTable, crimeType) {
let groupData, date, location, arrested, info, results = {};
const dataFilter = arrow.predicate.custom(i => {
const date = toDate(dataTable.getColumn('Date').get(i));
const primaryType = dataTable.getColumn('PrimaryType').get(i);
return ((crimeType === '' || primaryType === crimeType) &&
date.getMonth() <= 8); // through August
}, b => 1);
dataTable.filter(dataFilter)
.scan((index) => {
const day = toDate(date(index)).toISOString().substring(0, 10); // ISO date string
if (!results[day]) {
results[day] = [];
}
const dataRecord = {};
dataRecord['date'] = toDate(date(index));
dataRecord['location'] = location(index);
dataRecord['arrested'] = arrested(index);
dataRecord['info'] = info(index);
results[day].push(dataRecord);
}, (batch) => {
date = arrow.predicate.col('Date').bind(batch);
location = arrow.predicate.col('LocationDescription').bind(batch);
arrested = arrow.predicate.col('Arrest').bind(batch);
info = arrow.predicate.col('Description').bind(batch);
});
return results;
}
Insert cell
import {loadData, toDate} from '@randomfractals/apache-arrow'
Insert cell
arrow = require('apache-arrow@0.3.1')
Insert cell
import {select} from "@jashkenas/inputs"
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