Skip to content

Commit 100d22b

Browse files
authored
Merge pull request #1142 from DataUSA/university-lookups-migration
University lookup migration
2 parents 75110cc + 876af3e commit 100d22b

File tree

2 files changed

+47
-11
lines changed

2 files changed

+47
-11
lines changed

api/crosswalks.js

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -408,22 +408,40 @@ module.exports = function(app) {
408408
* To handle the sentence: "The highest paying jobs for people who hold a degree in one of the
409409
* 5 most specialized majors at University."
410410
*/
411-
app.get("/api/university/highestWageLookup/:id", async(req, res) => {
411+
app.get("/api/university/highestWageLookup/:id/:hierarchy", async(req, res) => {
412+
413+
const ipedsPumsFilterTesseract = d => ![21, 29, 32, 33, 34, 35, 36, 37, 48, 53, 60].includes(d["CIP2 ID"]);
414+
412415
const {id} = req.params;
416+
const {hierarchy} = req.params;
417+
418+
const latestYearUrl = `${CANON_CONST_TESSERACT}tesseract/data.jsonrecords?cube=ipeds_completions&drilldowns=Year&include=${hierarchy}:${id}&locale=en&measures=Completions&time=Year.latest`
419+
const latestYear = await axios.get(latestYearUrl)
420+
.then(resp => resp.data.data[0]["Year"]);
421+
422+
const cipURL = `${CANON_CONST_TESSERACT}complexity/rca_historical.jsonrecords?cube=ipeds_completions&location=${hierarchy}&activity=CIP2&measure=Completions&time=Year&filter=${hierarchy}:${id}&cuts=Year:${latestYear}`
413423

414-
const cipURL = `${CANON_API}/api/data?University=${id}&measures=Completions,yuc%20RCA&year=latest&drilldowns=CIP2&order=yuc%20RCA&sort=desc`;
415424
const CIP2 = await axios.get(cipURL)
416-
.then(resp => resp.data.data.filter(ipedsPumsFilter).slice(0, 5).map(d => d["ID CIP2"]).join());
425+
.then(resp => resp.data.data
426+
.sort((a, b) => b["Completions RCA"] - a["Completions RCA"])
427+
.filter(ipedsPumsFilterTesseract)
428+
.slice(0, 5)
429+
.map(d => `${d["CIP2 ID"]}`.padStart(2, '0')).join());
430+
431+
const logicUrl = `${CANON_CONST_TESSERACT}tesseract/data.jsonrecords?cube=pums_5&drilldowns=Year,CIP2,Detailed+Occupation&include=Workforce+Status:true;Employment+Time+Status:1;CIP2:${CIP2}&locale=en&measures=Record+Count,Average+Wage&time=Year.latest&filters=Record+Count.gte.5&sort=Average+Wage.desc`
417432

418-
const logicUrl = `${CANON_API}/api/data?measures=Average%20Wage,Record%20Count&year=latest&drilldowns=CIP2,Detailed%20Occupation&order=Average%20Wage&sort=desc&Workforce%20Status=true&Employment%20Time%20Status=1&Record%20Count%3E=5&CIP2=${CIP2}`;
419433
const wageList = await axios.get(logicUrl)
420-
.then(resp => resp.data.data);
434+
.then(resp => resp.data.data)
435+
436+
wageList.sort((a, b) => b["Average Wage"] - a["Average Wage"]);
421437

422438
const dedupedWages = [];
423439
wageList.forEach(d => {
424440
if (dedupedWages.length < 5 && !dedupedWages.find(w => w["Detailed Occupation"] === d["Detailed Occupation"])) dedupedWages.push(d);
425441
});
426442

443+
444+
dedupedWages.sort((a, b) => b["Average Wage"] - a["Average Wage"]);
427445
res.json({data: dedupedWages.slice(0, 10)});
428446

429447
});
@@ -432,30 +450,47 @@ module.exports = function(app) {
432450
* To handle the sentence: "The most common industries for people who hold a degree in one
433451
* of the 5 most specialized majors at University."
434452
*/
435-
app.get("/api/university/commonIndustryLookup/:id", async(req, res) => {
453+
app.get("/api/university/commonIndustryLookup/:id/:hierarchy", async(req, res) => {
454+
455+
const ipedsPumsFilterTesseract = d => ![21, 29, 32, 33, 34, 35, 36, 37, 48, 53, 60].includes(d["CIP2 ID"]);
456+
436457
const {id} = req.params;
458+
const {hierarchy} = req.params;
459+
460+
const latestYearUrl = `${CANON_CONST_TESSERACT}tesseract/data.jsonrecords?cube=ipeds_completions&drilldowns=Year&include=${hierarchy}:${id}&locale=en&measures=Completions&time=Year.latest`
461+
const latestYear = await axios.get(latestYearUrl)
462+
.then(resp => resp.data.data[0]["Year"]);
463+
464+
const cipURL = `${CANON_CONST_TESSERACT}complexity/rca_historical.jsonrecords?cube=ipeds_completions&location=${hierarchy}&activity=CIP2&measure=Completions&time=Year&filter=${hierarchy}:${id}&cuts=Year:${latestYear}`
437465

438-
const cipURL = `${CANON_API}/api/data?University=${id}&measures=Completions,yuc%20RCA&year=latest&drilldowns=CIP2&order=yuc%20RCA&sort=desc`;
439466
const CIP2 = await axios.get(cipURL)
440-
.then(resp => resp.data.data.filter(ipedsPumsFilter).slice(0, 5).map(d => d["ID CIP2"]).join());
467+
.then(resp => resp.data.data
468+
.sort((a, b) => b["Completions RCA"] - a["Completions RCA"])
469+
.filter(ipedsPumsFilterTesseract)
470+
.slice(0, 5)
471+
.map(d => `${d["CIP2 ID"]}`.padStart(2, '0')).join());
472+
473+
const logicUrl = `${CANON_CONST_TESSERACT}tesseract/data.jsonrecords?cube=pums_5&drilldowns=Year,CIP2,Industry+Group&include=Workforce+Status:true;Employment+Time+Status:1;CIP2:${CIP2}&locale=en&measures=Record+Count,Total+Population&time=Year.latest&filters=Record+Count.gte.5&sort=Total+Population.desc`
441474

442-
const logicUrl = `${CANON_API}/api/data?measures=Total%20Population,Record%20Count&year=latest&drilldowns=CIP2,Industry%20Group&order=Total%20Population&Workforce%20Status=true&Employment%20Time%20Status=1&sort=desc&Record%20Count>=5&CIP2=${CIP2}`;
443-
const industryList = await axios.get(logicUrl)
475+
let industryList = await axios.get(logicUrl)
444476
.then(resp => resp.data.data);
445477

446478
const dedupedIndustries = [];
447479
// The industryList has duplicates. For example, if a Biology Major enters Biotech, and a separate
448480
// Science major enters Biotech, these are listed as separate data points. These must be folded
449481
// together under one "Biotech" to create an accurate picture of "industries entered by graduates with X degrees"
482+
industryList = industryList.filter(d => d["Industry Group ID"] !== "")
483+
450484
industryList.forEach(d => {
451-
const thisIndustry = dedupedIndustries.find(j => j["Industry Group"] === d["Industry Group"]);
485+
const thisIndustry = dedupedIndustries.find(j => j["Industry Group"] === d["Industry Group"]);
452486
if (thisIndustry) {
453487
thisIndustry["Total Population"] += d["Total Population"];
454488
}
455489
else {
456490
dedupedIndustries.push(d);
457491
}
458492
});
493+
459494
dedupedIndustries.sort((a, b) => b["Total Population"] - a["Total Population"]);
460495
res.json({data: dedupedIndustries.slice(0, 10)});
461496

api/customAttributes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ module.exports = function(app) {
126126
retObj.beaL0 = beaIds && beaIds.L0 ? beaIds.L0 : false;
127127
retObj.beaL1 = beaIds && beaIds.L1 ? beaIds.L1 : false;
128128
retObj.blsIds = blsInds[id] || false;
129+
retObj.blsIdsStr = blsInds[id] ? blsInds[id].flat().join(",") : false;
129130
retObj.pumsLatestYear = await axios.get(`${origin}/api/data?${hierarchy}=${id}&measures=Total%20Population&limit=1&order=Year&sort=desc`)
130131
.then(resp => resp.data.data[0]["ID Year"])
131132
.catch(() => 2020);

0 commit comments

Comments
 (0)