Last active
May 26, 2025 15:57
-
-
Save gamesguru/68f2d950b82d0076a354c6b7458e0dce to your computer and use it in GitHub Desktop.
Script to load all professors and calculate a department's weighted average for ratings and difficulties.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** SCORES (RESULTS) | |
Average rating at Oakland University: 3.12 | |
Average difficulty at Oakland University: 3.56 | |
Based on 123 professors and 4636 ratings in the Mathematics department. | |
https://www.ratemyprofessors.com/search/professors/716?q=*&did=38 | |
Average rating at Oakland Community College: 3.44 | |
Average difficulty at Oakland Community College: 3.35 | |
Based on 14 professors and 132 ratings in the Mathematics department. | |
https://www.ratemyprofessors.com/search/professors/11931?q=*&did=38 | |
Average rating at Macomb Community College (all campuses): 3.46 | |
Average difficulty at Macomb Community College (all campuses): 3.14 | |
Based on 160 professors and 4507 ratings in the Mathematics department. | |
https://www.ratemyprofessors.com/search/professors/1360?q=*&did=38 | |
Average rating at University of Michigan: 3.74 | |
Average difficulty at University of Michigan: 3.42 | |
Based on 474 professors and 4433 ratings in the Mathematics department. | |
https://www.ratemyprofessors.com/search/professors/1258?q=*&did=38 | |
Average rating at Massachusetts Institute of Technology: 4.16 | |
Average difficulty at Massachusetts Institute of Technology: 2.95 | |
Based on 31 professors and 414 ratings in the Mathematics department. | |
https://www.ratemyprofessors.com/search/professors/580?q=*&did=38 | |
*/ | |
// ------------------------------------------------- | |
// Functions | |
function sleep(ms) { | |
return new Promise((resolve) => setTimeout(resolve, ms)); | |
} | |
// Scroll to bottom | |
window.scrollTo(0, document.body.scrollHeight); | |
await sleep(900); | |
let b = Array.from(document.getElementsByTagName("button")).pop(); | |
// Keep clicking "Show More" til we load all the professors | |
for (let i = 0; i < 1000; i++) { | |
if (Array.from(document.getElementsByTagName("button")).pop().innerText != "Show More") { | |
console.info("Done scrolling."); | |
break; | |
} | |
b.click(); | |
await sleep(900); | |
window.scrollTo(0, document.body.scrollHeight); | |
} | |
// Aggregate rating elements | |
let ratings = document.querySelectorAll("[class^=CardNumRating__CardNumRatingNumber]"); | |
let lvlDiffs = document.querySelectorAll("[class^=CardFeedback__CardFeedbackNumber]"); | |
let counts = document.querySelectorAll("[class^=CardNumRating__CardNumRatingCount]"); | |
let l = ratings.length; | |
let m = lvlDiffs.length; | |
let n = counts.length; | |
if (l != n || m != 2 * n) { | |
console.error("Different number of ratingValue and ratingCount elements!"); | |
throw new Error(); | |
} | |
// Count the totals | |
let rateTotal = 0.0; | |
let lvlDiffTotal = 0.0; | |
let countTotal = 0; | |
for (let i = 0; i < n; i++) { | |
let _r = parseFloat(ratings[i].innerText); | |
let _d = parseFloat(lvlDiffs[2 * i + 1].innerText); | |
let _c = parseInt(counts[i].innerText.split(" ")[0]); | |
rateTotal += _r * _c; | |
lvlDiffTotal += _d * _c; | |
countTotal += _c; | |
} | |
// Print weighted averages | |
let rateWeight = rateTotal / countTotal; | |
let lvlDiffWeight = lvlDiffTotal / countTotal; | |
let deptName = document.querySelector("[class^='SearchResultsHeaderText']").children[0].children[0] | |
.innerText; | |
let schoolName = document.querySelector("[class^='SearchResultsHeaderText']").children[0] | |
.children[1].innerText; | |
console.info(`Average rating ${schoolName}: ${rateWeight.toFixed(2)} | |
Average difficulty ${schoolName}: ${lvlDiffWeight.toFixed(2)} | |
Based on ${n} professors and ${countTotal} ratings ${deptName}. | |
${window.location.href}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment