Skip to content

Commit

Permalink
Added survey placeholder.
Browse files Browse the repository at this point in the history
  • Loading branch information
emeryberger committed May 30, 2022
1 parent c7b015e commit b75869f
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 61 deletions.
55 changes: 37 additions & 18 deletions csrankings.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ class CSRankings {
...this.theoryAreas.map(key => ({ [this.areaDict[key]]: "theory" })),
...this.interdisciplinaryAreas.map(key => ({ [this.areaDict[key]]: "interdisciplinary" })),
];
for (let item of subareaList) {
for (let key in item) {
for (const item of subareaList) {
for (const key in item) {
this.subareas[key] = item[key];
}
}
Expand Down Expand Up @@ -275,7 +275,20 @@ class CSRankings {
CSRankings.geoCheck();
this.rank();
// We've finished loading; remove the overlay.
document.getElementById("overlay").style.display = "none";
document.getElementById("overlay-loading").style.display = "none";
// Randomly display a survey.
const surveyFrequency = 1000; // One out of this many users gets the survey (on average).
// Check to see if survey has already been displayed (via a cookie).
if (!document.cookie.split('; ').find(row => row.startsWith('surveyDisplayed'))) {
// Not shown yet.
const displaySurvey = (Math.floor(Math.random() * surveyFrequency) == 0);
if (false && displaySurvey) { // currently disabled; remove 'false' to enable.
// Set a cookie indicating the survey has been displayed; set cookie to expire in one year.
document.cookie = "surveyDisplayed=true;max-age=60*60*24*365";
// Now reveal the survey.
document.getElementById("overlay-survey").style.display = "block";
}
}
}))();
}
// We have scrolled: increase the number we rank.
Expand Down Expand Up @@ -354,7 +367,7 @@ class CSRankings {
static stddev(n) {
const avg = CSRankings.average(n);
const squareDiffs = n.map(function (value) {
let diff = value - avg;
const diff = value - avg;
return (diff * diff);
});
const sigma = Math.sqrt(CSRankings.sum(squareDiffs) / (n.length - 1));
Expand Down Expand Up @@ -387,7 +400,7 @@ class CSRankings {
// if (key in CSRankings.nextTier) {
// continue;
// }
let value = this.authorAreas[name][key];
const value = this.authorAreas[name][key];
if (key in CSRankings.parentMap) {
key = this.areaDict[key];
}
Expand Down Expand Up @@ -471,7 +484,8 @@ class CSRankings {
// if (key in CSRankings.nextTier) {
// continue;
// }
let value = this.authorAreas[uname][key];
// Round it to the nearest 0.1.
const value = Math.round(this.authorAreas[uname][key] * 10) / 10;
// Use adjusted count if this is for a department.
/*
DISABLED so department charts are invariant.
Expand All @@ -483,8 +497,6 @@ class CSRankings {
}
}
*/
// Round it to the nearest 0.1.
value = Math.round(value * 10) / 10;
if (value > 0) {
if (key in CSRankings.parentMap) {
key = CSRankings.parentMap[key];
Expand Down Expand Up @@ -879,7 +891,7 @@ class CSRankings {
/* Build the dictionary of departments (and count) to be ranked. */
buildDepartments(startyear, endyear, weights, regions, deptCounts, deptNames, facultycount, facultyAdjustedCount) {
/* contains an author name if that author has been processed. */
let visited = {};
const visited = {};
for (const r in this.authors) {
if (!this.authors.hasOwnProperty(r)) {
continue;
Expand Down Expand Up @@ -1440,14 +1452,21 @@ class CSRankings {
// Now check everything listed in the query string.
let q = query.split('&');
// If there is an 'all' in the query string, set everything to true.
let foundAll = q.some((elem) => {
const foundAll = q.some((elem) => {
return (elem == "all");
});
let foundNone = q.some((elem) => {
// For testing: if 'survey' is in the query string, reveal the survey overlay.
const foundSurvey = q.some((elem) => {
return (elem == "survey");
});
if (foundSurvey) {
document.getElementById("overlay-survey").style.display = "block";
}
const foundNone = q.some((elem) => {
return (elem == "none");
});
// Check for regions and strip them out.
let foundRegion = q.some((elem) => {
const foundRegion = q.some((elem) => {
return CSRankings.regions.indexOf(elem) >= 0;
});
if (foundRegion) {
Expand All @@ -1463,15 +1482,15 @@ class CSRankings {
});
}
// Check for pie chart
let foundPie = q.some((elem) => {
const foundPie = q.some((elem) => {
return (elem == "pie");
});
if (foundPie) {
$("#charttype").val("pie");
}
if (foundAll) {
// Set everything.
for (let item in CSRankings.topTierAreas) {
for (const item in CSRankings.topTierAreas) {
// if (!(item in CSRankings.nextTier)) {
let str = `input[name=${item}]`;
$(str).prop('checked', true);
Expand Down Expand Up @@ -1499,7 +1518,7 @@ class CSRankings {
// First, clear everything that isn't subsetted.
CSRankings.clearNonSubsetted();
// Then, activate the areas in the query.
for (let item of q) {
for (const item of q) {
if ((item != "none") && (item != "")) {
const str = `input[name=${item}]`;
$(str).prop('checked', true);
Expand All @@ -1516,7 +1535,7 @@ class CSRankings {
}
}
static clearNonSubsetted() {
for (let item of CSRankings.areas) {
for (const item of CSRankings.areas) {
if (item in CSRankings.childMap) {
const kids = CSRankings.childMap[item];
if (!CSRankings.subsetting(kids)) {
Expand Down Expand Up @@ -1559,8 +1578,8 @@ class CSRankings {
numCheckedBelow++;
}
});
let subsettedAbove = ((numCheckedAbove > 0) && (numCheckedAbove < aboveFold.length));
let subsettedBelow = ((numCheckedBelow > 0) && (belowFold.length != 0));
const subsettedAbove = ((numCheckedAbove > 0) && (numCheckedAbove < aboveFold.length));
const subsettedBelow = ((numCheckedBelow > 0) && (belowFold.length != 0));
return subsettedAbove || subsettedBelow;
}
addListeners() {
Expand Down
Loading

0 comments on commit b75869f

Please sign in to comment.