Skip to content

Commit 72670d3

Browse files
committed
wip: puma map new york cbsa
1 parent 78fa9e7 commit 72670d3

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed
Binary file not shown.

docs/new-york-area.md

+28-27
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,40 @@ const selectedYear = Generators.input(yearInput);
1515
yearInput.querySelector("input[type=number]").remove();
1616
```
1717

18+
19+
```js
20+
// Fetch the mapping of PUMA codes to their names
21+
const pumaNameMapping = await db.query(`
22+
SELECT DISTINCT puma, puma_name, state_code FROM data
23+
`).then(data => new Map(data.map(d => [d.puma, d.puma_name, d.state_code])));
24+
```
25+
1826
```js
19-
const uniquePUMAs = await db.query(`
20-
SELECT DISTINCT puma FROM data
21-
WHERE year = 2020
22-
`).then(data => data.map(d => d.puma));
27+
const selectedPUMAName = pumaNameMapping.get(selectedPUMA);
2328
```
2429

2530
```js
26-
const uniquePUMAs = await db.query("SELECT DISTINCT puma FROM data WHERE year = 2020").then(data => data.map(d => d.puma));
27-
const selectedPUMA = Inputs.select(uniquePUMAs, {label: "Select PUMA", value: uniquePUMAs[0]});
31+
const uniquePUMAs = await db.query(`SELECT DISTINCT puma FROM data WHERE year = ${selectedYear}`).then(data => data.map(d => d.puma));
32+
const PUMAInput = Inputs.select(uniquePUMAs, {label: "Select PUMA", value: uniquePUMAs[0]});
33+
const selectedPUMA = Generators.input(PUMAInput);
2834
```
2935

3036
```js
31-
const orderSectors = Generators.observe(change => {
32-
const mostRecentYear = uniqueYears[uniqueYears.length - 1];
33-
const query = `
34-
SELECT sector, SUM(income * count) / SUM(count) AS mean_income
35-
FROM data
36-
WHERE year = ${mostRecentYear} AND puma = '${selectedPUMA}'
37-
GROUP BY sector
38-
ORDER BY mean_income DESC
39-
`;
40-
db.query(query).then(data => change(data.map(d => d.sector)));
41-
});
37+
const mostRecentYear = uniqueYears[uniqueYears.length - 1];
38+
const orderSectors = await db.query(`
39+
SELECT sector, SUM(income * count) / SUM(count) AS mean_income
40+
FROM data
41+
WHERE year = ${mostRecentYear}
42+
GROUP BY sector
43+
ORDER BY mean_income DESC
44+
`).then(data => data.map(d => d.sector));
4245
```
4346

4447
```js
45-
const income = Generators.observe((change) => {
46-
const query = `
47-
SELECT income, count, sector FROM data
48-
WHERE year = ${selectedYear} AND puma = '${selectedPUMA}'
49-
`;
50-
db.query(query).then(change);
51-
});
48+
const income = db.query(`
49+
SELECT income, count, sector FROM data
50+
WHERE year = ${selectedYear} AND puma = ${selectedPUMA}
51+
`);
5252
```
5353

5454
```js
@@ -83,13 +83,14 @@ function incomeChart(income, width) {
8383
```
8484

8585
<div class="card">
86-
<h2>The sectors in which people earn the most money have shifted over the past two decades</h2>
87-
<h3>How much income per year x million people reported earning in the 2000–2022 American Community Surveys run by the United States' Census Bureau, categorized by their sector of employment, specifically for PUMAs overlapping with the New York-Newark CBSA in 2020.</h3>
86+
<h2>The sectors in which people earn the most money shift across time and space</h2>
87+
<h3>How much income per year x million people reported earning in the 2010–2022 American Community Surveys run by the United States' Census Bureau, categorized by their sector of employment, specifically for areas overlapping with the New York-Newark-Jersey City core-based statistical area in 2020.</h3>
8888
<h3><code style="font-size: 90%;"><a href="https://github.com/jaanli/exploring_american_community_survey_data/blob/main/american_community_survey/models/public_use_microdata_sample/figures/income-histogram-with-sector-historical-inflation-adjusted-industry-mapped.sql">Code for data transform</a></code></h3>
8989
<div style="display: flex; align-items: center;">
9090
<h1 style="margin-top: 0.5rem;">${selectedYear}</h1>
9191
${yearInput}
92-
${selectedPUMA}
92+
<h1 style="margin-top: 0.5rem;">${pumaNameMapping.get(selectedPUMA)}</h1>
93+
${PUMAInput}
9394
</div>
9495
${resize((width) => incomeChart(income, width))}
9596
</div>

0 commit comments

Comments
 (0)