Public
Edited
Paused
1 fork
Importers
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
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
pop_by_shelter = Plot.plot(
(() => {
const n = 3; // number of facet columns
const keys = Array.from(d3.union(housing_counts.map((d) => d.location)));
const index = new Map(keys.map((key, i) => [key, i]));
const fx = (key) => index.get(key) % n;
const fy = (key) => Math.floor(index.get(key) / n);
return {
fx: { axis: null },
fy: { axis: null },
marks: [
Plot.line(housing_counts, {
x: "date",
y: "count",
fx: (d) => fx(d.location),
fy: (d) => fy(d.location)
}),
Plot.text(keys, { fx, fy, frameAnchor: "top-left", dx: 6, dy: 6 }),
Plot.frame()
]
};
})()
)
Insert cell
housing_counts
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
housing_counts = expanded_housing_counts.filter(
(d) =>
![
"SHELTER",
"SHELTER TOTAL",
"STAGING AREA TOTAL",
"Minors Currently in Shelters",
"Minors Currently in Staging Area"
].includes(d.location)
)
Insert cell
expanded_housing_counts = {
const transposedData = [];
let housing_type = "staging";
raw_housing_census.forEach(function (d) {
for (var key in d) {
var obj = {};
if (key !== "STAGING AREA") {
if (d["STAGING AREA"] === "SHELTER") {
housing_type = "shelter";
}
obj.identifier = key.substring(0, 10);
obj.date = new Date(key.substring(0, 10));
obj.count = d[key];
obj.location = d["STAGING AREA"];
obj.type = housing_type;
transposedData.push(obj);
}
}
});
return transposedData
.filter((d) => d.count)
.sort((a, b) => a.date.getTime() - b.date.getTime());
}
Insert cell
raw_housing_census = await d3.csv(
"https://raw.githubusercontent.com/fgregg/asylum-dashboard-data/main/data/housing_census.csv",
d3.autoType
)
Insert cell
movement_to_date = {
const transposedData = [];
raw_movement_to_date.forEach(function (d) {
for (var key in d) {
var obj = {};
if (key !== "") {
obj.identifier = key;
obj.date = new Date(key);
obj.count = d[key];
obj.type = d["* = potential data entry error"];
transposedData.push(obj);
}
}
});
return transposedData;
}
Insert cell
raw_movement_to_date = await d3.csv(
"https://raw.githubusercontent.com/fgregg/asylum-dashboard-data/main/data/movement_to_date.csv",
d3.autoType
)
Insert cell
Insert cell
grand_exit_rate = d3.mean(exit_rates.map((d) => d.rate))
Insert cell
last_date = shelter_entrances[shelter_entrances.length - 1].end
Insert cell
shelter_entrances
Insert cell
age_pyramid = shelter_entrances.map((d) => ({
days_in_system: (last_date.getTime() - d.end.getTime()) / (1000 * 3600 * 24),
count:
d.count *
Math.exp(
(-grand_exit_rate * (last_date.getTime() - d.end.getTime())) /
(1000 * 3600 * 24)
)
}))
Insert cell
Plot.plot({
y: { label: "people per days in system" },
color: { legend: true },
marks: [
Plot.line(age_pyramid, {
curve: "step-before",
x: "days_in_system",
y: "count"
})
]
})
Insert cell
d3.sum(age_pyramid.filter((d) => d.days_in_system > 60).map((d) => d.count)) /
d3.sum(age_pyramid.map((d) => d.count))
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