Skip to content

Commit

Permalink
Merge pull request #973 from DataUSA/staging
Browse files Browse the repository at this point in the history
v3.1.10 - Uranium
  • Loading branch information
davelandry authored Jun 27, 2022
2 parents 134bca5 + 2cd95e8 commit 1ba6363
Show file tree
Hide file tree
Showing 34 changed files with 265 additions and 138 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ datausa
*.pyc

google_auth.json
googleAnalyticsKey.json

# pm2 config
*.config.js
33 changes: 24 additions & 9 deletions api/customAttributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,36 @@ module.exports = function(app) {

const retObj = {
breadcrumbs,
freightYear: 2018,
freightYear: 2020,
neverShow: false,
tesseract: process.env.CANON_CONST_TESSERACT,
url: urls[id]
};

if (dimension === "CIP") {
retObj.stem = id.length === 6 ? stems.includes(id) ? "Stem Major" : false : "Contains Stem Majors"
}

if (dimension === "Geography") {

const parentsElection = await axios.get(`${origin}/api/civic/senator/${id}`)
.then(resp => resp.data)
.catch(() => []);

retObj.parentsElection = parentsElection;

const state = breadcrumbs.find(d => d.hierarchy === "State");
const stateElection = parentsElection.map(d => d["ID State"]).reduce((acc,item)=>{
if(!acc.includes(item)){
acc.push(item);
}
return acc;
},[]);

retObj.stateId = state && ["Congressional District"].includes(hierarchy) ? state.id : id;
retObj.stateDataID = state && !["Nation", "State"].includes(hierarchy) ? state.id : id;
retObj.hierarchyElectionSub = ["Nation", "County"].includes(hierarchy) ? hierarchy : "State";
retObj.stateElectionId = ["Nation", "State", "County"].includes(hierarchy) ? id : stateElection.join(",");
retObj.electionCut = hierarchy === "Nation" ? `State` : hierarchy === "County" ? `County&State+County=${retObj.stateDataID}` : `County&State+County=${retObj.stateElectionId}`;
retObj.hierarchySub = hierarchy === "Nation" ? "State" : "County";
}

if (dimension === "PUMS Industry") {
else if (dimension === "PUMS Industry") {
if (blsMonthlyIndustries[id]) {
retObj.blsMonthlyID = blsMonthlyIndustries[id];
retObj.blsMonthlyDimension = "Industry";
Expand All @@ -61,8 +75,9 @@ module.exports = function(app) {
retObj.blsMonthlyDimension = "Supersector";
}
}

retObj.tesseract = process.env.CANON_CONST_TESSERACT;
else if (dimension === "CIP") {
retObj.stem = id.length === 6 ? stems.includes(id) ? "Stem Major" : false : "Contains Stem Majors"
}

return res.json(retObj);

Expand Down
39 changes: 34 additions & 5 deletions api/homeRoute.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
const axios = require("axios");
const {google} = require("googleapis");
const analytics = google.analytics("v3");

// configure an auth client
const jwtClient = new google.auth.GoogleAuth({
keyFilename: process.env.GA_KEYFILE,
scopes: "https://www.googleapis.com/auth/analytics.readonly"
});

const {CANON_API} = process.env;

Expand All @@ -8,6 +16,27 @@ module.exports = function(app) {

app.get("/api/home", async(req, res) => {

const mostVisited = await analytics.data.ga
.get({
"auth": jwtClient,
"dimensions": "ga:pagePath",
"ids": "ga:111999474",
"start-date": "30daysAgo",
"end-date": "yesterday",
"metrics": "ga:pageviews",
"sort": "-ga:pageviews"
})
.then(resp => resp.data.rows.filter(r => r[0].includes("/profile/")))
.then(rows => rows.reduce((obj, row) => {
const profile = row[0].split("/")[2];
if (profile !== "degree") {
if (!obj[profile]) obj[profile] = [];
if (obj[profile].length < 5) obj[profile].push(row[0].split("/")[3]);
}
return obj;
}, {}))
.catch(() => ({}));

const carousels = [];
const newProfiles = [
// "congressional-district-5-ga",
Expand Down Expand Up @@ -60,7 +89,7 @@ module.exports = function(app) {
]
});

const geoSlugs = [
const geoSlugs = mostVisited.geo && mostVisited.geo.length === 5 ? mostVisited.geo : [
"california",
"welch-wv",
"new-york-ny",
Expand Down Expand Up @@ -90,7 +119,7 @@ module.exports = function(app) {
tiles: geos
});

const indSlugs = [
const indSlugs = mostVisited.naics && mostVisited.naics.length === 5 ? mostVisited.naics : [
"oil-gas-extraction",
"finance-insurance",
"restaurants-food-services",
Expand Down Expand Up @@ -123,7 +152,7 @@ module.exports = function(app) {
tiles: industries
});

const occSlugs = [
const occSlugs = mostVisited.soc && mostVisited.soc.length === 5 ? mostVisited.soc : [
"customer-service-representatives",
"police-officers",
"service-occupations",
Expand Down Expand Up @@ -153,7 +182,7 @@ module.exports = function(app) {
tiles: occupations
});

const universitySlugs = [
const universitySlugs = mostVisited.university && mostVisited.university.length === 5 ? mostVisited.university : [
"harvard-university",
"university-of-washington-seattle-campus",
"university-of-california-los-angeles",
Expand Down Expand Up @@ -182,7 +211,7 @@ module.exports = function(app) {
tiles: universities
});

const cipSlugs = [
const cipSlugs = mostVisited.cip && mostVisited.cip.length === 5 ? mostVisited.cip : [
"computer-science-110701",
"engineering",
"natural-resources-conservation",
Expand Down
3 changes: 3 additions & 0 deletions app/d3plus.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ export default {
}
},
color: colors.colorScaleGood,
colorMin: colors.colorScaleGood[0],
colorMid: colors.colorScaleGood[2],
colorMax: colors.colorScaleGood[4],
legendConfig: {
shapeConfig: {
labelConfig: {
Expand Down
2 changes: 1 addition & 1 deletion app/pages/Home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Home extends Component {
super(props);
this.state = {
banner: new Date() < launch,
image: "autumn"
image: "snow"
};
}

Expand Down
2 changes: 1 addition & 1 deletion app/toCanon/topics/Column.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Column extends Component {
{ subtitles.map((content, i) => <div key={i} className="topic-subtitle" dangerouslySetInnerHTML={{__html: stripP(content.subtitle)}} />) }
{ selectors.map(selector => <div className="bp3-select bp3-fill" key={selector.name}>
<select onChange={d => this.onSelector.bind(this)(selector.name, d.target.value)} disabled={loading} defaultValue={selector.default}>
{ selector.options.map(({option}) => <option value={option} key={option}>{variables[option]}</option>) }
{ selector.options.map(({label, option}) => <option value={option} key={option}>{variables[label || option]}</option>) }
</select>
</div>) }
{ !hideText && descriptions.map((content, i) => <div key={i} className="topic-description" dangerouslySetInnerHTML={{__html: content.description}} />) }
Expand Down
4 changes: 2 additions & 2 deletions app/toCanon/topics/TextViz.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class TextViz extends Component {
{ selectors.map(selector => <div className="bp3-select bp3-fill" key={selector.name}>
{selector.title && selector.title !== "New Selector" ? <span className="topic-select-label">{selector.title}</span> : null}
<select onChange={d => this.onSelector.bind(this)(selector.name, d.target.value)} disabled={loading} defaultValue={selector.default}>
{ selector.options.map(({option}) => <option value={option} key={option}>{variables[option] !== undefined ? variables[option] : option}</option>) }
{ selector.options.map(({label, option}) => <option value={option} key={option}>{variables[label || option] !== undefined ? variables[label || option] : label || option}</option>) }
</select>
</div>) }
{ miniviz && <Viz topic={contents} config={miniviz} className="topic-miniviz" title={ title } slug={ `${slug}_miniviz` } /> }
Expand All @@ -69,7 +69,7 @@ class TextViz extends Component {
{ selectors.map(selector => <div className="bp3-select bp3-fill" key={selector.name}>
{selector.title && selector.title !== "New Selector" ? <span className="topic-select-label">{selector.title}</span> : null}
<select onChange={d => this.onSelector.bind(this)(selector.name, d.target.value)} disabled={loading} defaultValue={selector.default}>
{ selector.options.map(({option}) => <option value={option} key={option}>{variables[option] !== undefined ? variables[option] : option}</option>) }
{ selector.options.map(({label, option}) => <option value={option} key={option}>{variables[label || option] !== undefined ? variables[label || option] : label || option}</option>)}
</select>
</div>) }
<div className="topic-stats">
Expand Down
Loading

0 comments on commit 1ba6363

Please sign in to comment.