Skip to content

Commit

Permalink
more minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
heartgg committed Mar 22, 2023
1 parent 6ed0678 commit 8e9344d
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "sk.edge",
"displayName": "sk.edge",
"version": "0.0.1",
"description": "the all-in-one registration tool by students, for students",
"description": "your registration assistant by students, for students",
"author": "Nebula Labs",
"packageManager": "[email protected]",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const Landing = () => {
<Card>
<div className="h-auto">
<h1>Welcome to sk.edge 👋</h1>
<h6 className="my-2">the all-in-one registration tool by students, for students</h6>
<h6 className="my-2">your registration assistant by students, for students</h6>
<img src={skedgeLogo} alt="" className="w-[100px] h-[100px] float-right" />
<p className="mb-2">Log into <b>Schedule Planner</b> and click <b>Options</b> on a course to get started!</p>
<p className="mb-2">Got feedback? Let us know <button className="text-purple-dark" onClick={navigateToSurvey}>here</button>!</p>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ProfileHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const ProfileHeader = ({ name, profilePicUrl, rmpId, profiles } : { name:
<button onClick={returnToSections} className="justify-center items-center flex">
<TiArrowBack size={40} color="white" className="p-2 hover:bg-blue-dark-hover rounded-lg transition duration-250 ease-in-out" />
</button>
<h2 className="col-span-3 text-center text-white mx-auto my-auto">{name}</h2>
<h2 className="col-span-3 text-center text-white mx-auto my-auto">{name.split(' ').at(0) + " " + name.split(' ').at(-1)}</h2>
<button className="justify-center items-center flex" onClick={navigativeToRmp}>
<FaExternalLinkAlt size={40} color="white" className="p-3 hover:bg-blue-dark-hover rounded-lg transition duration-250 ease-in-out" />
</button>
Expand Down
8 changes: 4 additions & 4 deletions src/data/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function buildProfessorProfiles (payload: ShowCourseTabPayload) {
if (professor?._id === undefined) return null
return fetchNebulaSections({ courseReference: nebulaCourse._id, professorReference: professor._id })
}))
const rmps = await requestProfessorsFromRmp({ professorNames: nebulaProfessors.map(prof => prof?.first_name + " " + prof?.last_name), schoolId: SCHOOL_ID })
const rmps = await requestProfessorsFromRmp({ professorNames: professors.map(prof => prof.split(' ')[0] + " " + prof.split(' ').at(-1)), schoolId: SCHOOL_ID })
let professorProfiles: ProfessorProfileInterface[] = []
for (let i = 0; i < professors.length; i++) {
const sectionsWithGrades = []
Expand All @@ -50,9 +50,9 @@ export async function buildProfessorProfiles (payload: ShowCourseTabPayload) {
name: professors[i],
profilePicUrl: nebulaProfessors[i]?.image_uri,
rmpId: rmps[i]?.legacyId,
rmpScore: rmps[i]?.avgRating,
diffScore: rmps[i]?.avgDifficulty,
wtaScore: rmps[i]?.wouldTakeAgainPercent,
rmpScore: rmps[i]?.avgRating ? (rmps[i]?.avgRating === 0 ? undefined : rmps[i]?.avgRating) : undefined,
diffScore: rmps[i]?.avgDifficulty ? (rmps[i].avgDifficulty === 0 ? undefined : rmps[i]?.avgDifficulty) : undefined,
wtaScore: rmps[i]?.wouldTakeAgainPercent ? (rmps[i]?.wouldTakeAgainPercent === -1 ? undefined : rmps[i]?.wouldTakeAgainPercent) : undefined,
rmpTags: rmps[i]?.teacherRatingTags.sort((a, b) => a.tagCount - b.tagCount).map(tag => tag.tagName),
gradeDistributions: sectionsWithGrades.length > 0 ? sectionsWithGrades.map(section => ({ name: [nebulaCourse.subject_prefix, nebulaCourse.course_number, section.section_number, section.academic_session.name].join(' '), series: [{name: "Students", data: section.grade_distribution}] })) : [{name: "No Data", series: [{name: "Students", data: []}]}],
ratingsDistribution: rmps[i] ? Object.values(rmps[i].ratingsDistribution).reverse().slice(1) : []
Expand Down
10 changes: 4 additions & 6 deletions src/data/fetchFromRmp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ function getProfessorUrls(professorNames: string[], schoolId: string): string[]

function getProfessorIds(texts: string[], professorNames: string[]): string[] {
const professorIds = []
const lowerCaseProfessorNames = professorNames.map(name => name.toLowerCase())
texts.forEach(text => {
let matched = false;
const regex = /"legacyId":(\d+).*?"firstName":"(.*?)","lastName":"(.*?)"/g;
for (const match of text.matchAll(regex)) {
if (professorNames.includes(match[2].split(' ')[0] + " " + match[3])) {
console.log(match[2].split(' ')[0].toLowerCase() + " " + match[3].toLowerCase())
if (lowerCaseProfessorNames.includes(match[2].split(' ')[0].toLowerCase() + " " + match[3].toLowerCase())) {
professorIds.push(match[1]);
matched = true;
}
Expand Down Expand Up @@ -55,6 +57,7 @@ function fetchWithGraphQl(graphQlUrlProps: any[], resolve) {
ratings[i] = ratings[i]["data"]["node"];
}
}
console.log(ratings)
resolve(ratings)
})
}
Expand All @@ -65,8 +68,6 @@ export interface RmpRequest {
}
export function requestProfessorsFromRmp(request: RmpRequest): Promise<RMPInterface[]> {
return new Promise((resolve, reject) => {
console.log("Running request professors...")
const startTime = Date.now();

// make a list of urls for promises
const professorUrls = getProfessorUrls(request.professorNames, request.schoolId)
Expand All @@ -84,11 +85,8 @@ export function requestProfessorsFromRmp(request: RmpRequest): Promise<RMPInterf
fetchWithGraphQl(graphQlUrlProps, resolve)
}
).catch(error => {
console.log(error)
reject(error);
});

console.log(Date.now() - startTime);
})
}

Expand Down
1 change: 0 additions & 1 deletion src/routes/CoursePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export const CoursePage = () => { // TODO: CHANGE INTERFACE
setLoading(true)
getCourseData().then(payload => {
buildProfessorProfiles(payload).then(profiles => {
console.log(profiles)
setProfiles(profiles)
}).finally(() => setLoading(false))
})
Expand Down
7 changes: 6 additions & 1 deletion src/routes/ProfessorProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import type { ProfessorProfileInterface } from "~data/builder"
export const ProfessorProfile = () => {
const { state } : { state: { professorData: ProfessorProfileInterface, profiles: ProfessorProfileInterface[] } } = useLocation();
const { professorData, profiles } = state;

const compareArrays = (a, b) => {
return JSON.stringify(a) === JSON.stringify(b);
};

return (
<div className="w-[400px] p-4">
<ProfileHeader name={professorData.name} profilePicUrl={professorData.profilePicUrl} rmpId={professorData.rmpId} profiles={profiles} />
Expand All @@ -22,7 +27,7 @@ export const ProfessorProfile = () => {
<RmpTag key={index} text={item.toUpperCase()} />
)}
</div>
{ professorData.ratingsDistribution.length > 0 &&
{ professorData.ratingsDistribution.length > 0 && !compareArrays(professorData.ratingsDistribution, Array(5).fill(0)) &&
<RmpRatings ratingsDistributionData={professorData.ratingsDistribution}/>
}
<ProfileGrades gradeDistributionData={professorData.gradeDistributions} />
Expand Down

0 comments on commit 8e9344d

Please sign in to comment.