Skip to content

Commit

Permalink
Fix incorrect RMP matching
Browse files Browse the repository at this point in the history
  • Loading branch information
cabalex committed Feb 26, 2025
1 parent c516bac commit b4ae8e1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
13 changes: 13 additions & 0 deletions .server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import DB, { type Class, ClassStatus } from "./db/DB";
import axios from "axios";
import https from "https";
import { ZstdInit } from '@oneidentity/zstd-js';
import searchRMP from "./ratemyprofessor/search";



Expand Down Expand Up @@ -112,6 +113,18 @@ async function main() {
}
}

/*
// force rmp update
if (db.classes[dbClassIndex].instructor.name && db.classes[dbClassIndex].instructor.name !== "Staff") {
let rateMyProfessor = await backoffRetryer(searchRMP.bind(null, db.classes[dbClassIndex].instructor.name, db.classes[dbClassIndex].code) as any);
db.classes[dbClassIndex].instructor = {
...rateMyProfessor as any,
name: db.classes[dbClassIndex].instructor.name
}
}
*/

/*if (i % 50 === 0) {
console.log("checking export...");
tempDB.classes = db.classes;
Expand Down
27 changes: 17 additions & 10 deletions .server/ratemyprofessor/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@ import { POST } from "../search/retryableSearch";

const SCHOOL_ID = "U2Nob29sLTEwNzg=";

// Tromba, A.J.Bauerle,F.Lin,L. -> ["Tromba", "A"]
// Escobar Vega, L. -> ["Escobar Vega", "L"]

export default async function searchRMP(instructorName: string, classCode: string): Promise<Instructor|null> {
// UCSC class search doesn't include spaces
function getPisaName(instructorName: string) {
let splitName = instructorName.split(",");
let query = splitName[0];
let lastName = splitName[0];
let firstInitial = splitName[1] ? splitName[1].split(".")[0] : "";
return [lastName, firstInitial];
}

export default async function searchRMP(instructorName: string, classCode: string, searchWithInitial=false): Promise<Instructor|null> {
// UCSC class search doesn't include spaces
let [lastName, firstInitial] = getPisaName(instructorName);
let className = classCode.split(" - ")[0].replace(" ", "");

if (query.includes(" ")) {
query = (query.split(" ").pop() || "") + (splitName[1] ? ", " + splitName[1].replace(/\./g, "") : "");
}
// This seems to give best results in the RMP search (don't use commas)
let query = lastName + " " + firstInitial;

let resp = await POST("https://www.ratemyprofessors.com/graphql",
{
Expand Down Expand Up @@ -253,9 +260,9 @@ export default async function searchRMP(instructorName: string, classCode: strin

let similarityScore = instructors.map((b) =>
// Check if last name matches
(b.lastName.endsWith(query) ? 1 : -10) +
(b.lastName.endsWith(lastName) ? 1 : -10) +
// Check if first initial matches
(b.firstName.startsWith(splitName[1][0]) ? 1 : -1) +
(b.firstName.startsWith(firstInitial) ? 1 : -1) +
// Check if this instructor has taught courses like this
(b.courseCodes.map(x => x.courseName.replace(/([0-9 ]+.+)|(AND.+)/gm, "")).includes(className.replace(/([0-9 ]+.+)|(AND.+)/gm, "")) ? 1 : -1) +
// Check if this instructor has taught this course
Expand All @@ -267,8 +274,8 @@ export default async function searchRMP(instructorName: string, classCode: strin

let instructor = instructors[index];

// sanity check; ensure the last name is the same
if (!instructor.lastName.endsWith(query)) {
// sanity check; ensure what we know is true
if (!instructor.lastName.endsWith(lastName) || !instructor.firstName.startsWith(firstInitial)) {
return null;
}

Expand Down
Binary file modified public/db/2252.yaucsccs.zstd
Binary file not shown.
3 changes: 3 additions & 0 deletions src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ header.mobileHeader {
gap: 10px;
align-items: center;
}
svg {
flex-shrink: 0;
}

@media screen and (min-width: 1000px) {
.mobileHeader {
Expand Down

0 comments on commit b4ae8e1

Please sign in to comment.