Skip to content

Commit

Permalink
Add census tract location type (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvendetti committed Jul 2, 2021
1 parent d5f2aed commit 63fc308
Show file tree
Hide file tree
Showing 4 changed files with 74,174 additions and 2 deletions.
45 changes: 45 additions & 0 deletions js/stateToCensusTracts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const axios = require('axios');
const fs = require("fs");

const DC_REST_URL = "https://api.datacommons.org/";

async function generateStateToCensusTracts() {
let stateToCensusTracts = {};

try {
let response = await axios.post(DC_REST_URL + "node/places-in", {
dcids: "country/USA",
placeType: "State"
});
let payload = JSON.parse(response.data.payload);
const stateIds = payload.map(x => x.place);

let stateAbbrev = "";
let censusTractIds = [];
for (const stateId of stateIds) {
response = await axios.post(DC_REST_URL + "node/property-values", {
dcids: [stateId],
property: "fips52AlphaCode",
});
payload = JSON.parse(response.data.payload);
stateAbbrev = payload[stateId]["out"][0]["value"];

response = await axios.post(DC_REST_URL + "node/places-in", {
dcids: stateId,
placeType: "CensusTract",
});
payload = JSON.parse(response.data.payload);
censusTractIds = payload.map(x => x.place.substring(6));

stateToCensusTracts[stateAbbrev] = censusTractIds;
}

fs.writeFile("output/stateToCensusTracts.json", JSON.stringify(stateToCensusTracts, null, 2), (err) => {
if (err) throw err;
console.log("State to census tracts file generation complete");
});
} catch(err) {
console.error(err);
}
}
generateStateToCensusTracts();
8 changes: 8 additions & 0 deletions phs-gdc-dashboard/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const INDEX_VARIABLE_STATE_NAME = 'state';
export const INDEX_VARIABLE_COUNTY_NAME = 'county';
export const INDEX_VARIABLE_CITY_NAME = 'city';
export const INDEX_VARIABLE_ZIPCODE_NAME = 'zipCode';
export const INDEX_VARIABLE_CENSUSTRACT_NAME = 'censusTract';

export const INDEX_VARIABLES = {
[INDEX_VARIABLE_STATE_NAME]: {
Expand Down Expand Up @@ -35,6 +36,13 @@ export const INDEX_VARIABLES = {
"dcid": "CensusZipCodeTabulationArea",
"dcidValuePrefix": "zip/",
"enabled": true
},
[INDEX_VARIABLE_CENSUSTRACT_NAME]: {
"uiLabel": "census tract",
"uiValuesExample": "06085512402",
"dcid": "CensusTract",
"dcidValuePrefix": "geoId/",
"enabled": true
}
}

Expand Down
Loading

0 comments on commit 63fc308

Please sign in to comment.