Skip to content

Commit

Permalink
Merge pull request #133 from unkn-wn/revert-132-Scheduling-Assistant
Browse files Browse the repository at this point in the history
Revert "Scheduling Assistant"
  • Loading branch information
SohamJog authored Nov 27, 2024
2 parents 2742141 + 09bde5c commit 2578a1c
Show file tree
Hide file tree
Showing 17 changed files with 661 additions and 2,270 deletions.
488 changes: 223 additions & 265 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"chart.js": "^4.4.1",
"cors": "^2.8.5",
"net": "^1.0.2",
"next": "^14.2.18",
"next": "14.0.3",
"nextjs-cors": "^2.2.0",
"react": "^18",
"react-chartjs-2": "^5.2.0",
Expand Down
10 changes: 3 additions & 7 deletions server/harmonize.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,10 @@
class_data["sched"] = list(set(class_data["sched"]))
if "description" not in class_data:
class_data["description"] = instances[0]["description"]
class_data["credits"] = next(
(instance["credits"] for instance in instances if "<a href=" not in instance["description"]),
[0, 0]
)
class_data["credits"] = instances[0]["credits"]
for instance in instances:
if "<a href=" not in instance["description"]:
class_data["credits"][0] = min(instance["credits"][0], class_data["credits"][0])
class_data["credits"][1] = max(instance["credits"][1], class_data["credits"][1])
class_data["credits"][0] = min(instance["credits"][0], class_data["credits"][0])
class_data["credits"][1] = max(instance["credits"][1], class_data["credits"][1])
out[class_id] = class_data

course_data = []
Expand Down
41 changes: 11 additions & 30 deletions src/components/RMP.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,17 @@ async function getRMPRating(instructor) {

let rating = 0;

let baseUrl = window.location.href;
if (baseUrl.includes("localhost")) {
baseUrl = "http://localhost:3000";
} else {
baseUrl = "https://boilerclasses.com";
}

// for all Purdue University schools in West Lafayette, search prof
const schools = ["U2Nob29sLTc4Mw==", "U2Nob29sLTE3NTk5"]; // purdue IDs for West Lafayette
for (const school of schools) {
const paramsTeacher = new URLSearchParams({ name: instructor, id: school });
const responseProf = await fetch(baseUrl + "/api/ratings/searchTeacher?" + paramsTeacher);
const responseProf = await fetch("/api/ratings/searchTeacher?" + paramsTeacher);
const prof = await responseProf.json();
const profs = prof.prof.filter(Boolean);

if (profs.length > 0) {
const paramsGetTeacher = new URLSearchParams({ id: profs[0].id });
const responseRMP = await fetch(baseUrl + "/api/ratings/getTeacher?" + paramsGetTeacher);
const responseRMP = await fetch("/api/ratings/getTeacher?" + paramsGetTeacher);
const RMPrating = await responseRMP.json();
rating = RMPrating.RMPrating.avgRating;
break;
Expand Down Expand Up @@ -75,18 +68,11 @@ async function getAllRMPRatings(allProfs) {
}


// Add these new utility functions before loadRatingsForProfs
export function getRMPScore(rmpData, instructor) {
if (!rmpData || !instructor) return null;
return rmpData[instructor] || null;
}


// Asynchronously fetch RMP rating for all professors
let isLoadingRatings = false;

export async function loadRatingsForProfs(course, onUpdate = null) {
if (!course) return Promise.resolve({});
export async function loadRatingsForProfs(course) {
if (!course) return Promise.resolve({}); // Return an empty object if no course

const allProfs = [];
for (const semester in course.instructor) {
Expand All @@ -97,21 +83,16 @@ export async function loadRatingsForProfs(course, onUpdate = null) {
}
}

if (isLoadingRatings) return Promise.resolve({});
if (isLoadingRatings) {
return Promise.resolve({}); // Return an empty object if already loading
}

isLoadingRatings = true;

const ratings = {};
try {
// Process professors individually for streaming updates
const promises = allProfs.map(async (instructor) => {
const rating = await getRMPRating(instructor);
ratings[instructor] = rating;
// Call callback with accumulated ratings so far
if (onUpdate) onUpdate({...ratings});
});

await Promise.all(promises);
return ratings;
const ratings = await getAllRMPRatings(allProfs);
const newRMP = { ...ratings };
return newRMP;
} catch (error) {
console.error("Error loading ratings:", error);
return Promise.resolve({});
Expand Down
Loading

0 comments on commit 2578a1c

Please sign in to comment.