Skip to content

Commit

Permalink
courses ct integration
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanggum committed Jun 27, 2024
1 parent 6adaec6 commit 42a043b
Show file tree
Hide file tree
Showing 17 changed files with 108 additions and 190 deletions.
36 changes: 9 additions & 27 deletions backend/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@
import json

class Course:
def __init__(self, codes: List[str], title: str, credit: int, areas: List[str], skills: List[str]):
def __init__(self, codes: List[str], title: str, credit: int, areas: List[str], skills: List[str], seasons: List[str]):
self.codes = codes
self.title = title
self.credit = credit
self.areas = areas
self.skills = skills
self.seasons = seasons

def to_dict(self):
return {
"codes": self.codes,
"title": self.title,
"credit": self.credit,
"areas": self.areas,
"skills": self.skills
"skills": self.skills,
"seasons": self.seasons
}

class StudentCourse:
Expand All @@ -38,12 +40,12 @@ def to_dict(self):

# Functions

def process_dacourses(data):
def distill_dacourses(data):
dacourses = {}
for table in data["coursestable"]:
for raw in table["courses"]:
season, year = raw["term"].split()
season_map = { "Fall": "01", "Spring": "02" }
season_map = { "Spring": "01", "Fall": "03" }
raw["timekey"] = f"{year}{season_map.get(season)}"
dacourses[raw["id"]] = raw
dacourses = list(dacourses.values())
Expand All @@ -65,7 +67,7 @@ def process_dacourses(data):


def coursify(dacourses):
"""DegreeAuditCourse[] (w/ Same Term) -> StudentCourse[]"""
"""DegreeAuditCourse[] -> StudentCourse[]"""

cookies = { 'session': 'enter_session_here', 'session.sig': 'enter_session_sig_here' }
timekey = dacourses[0]["timekey"]
Expand All @@ -84,16 +86,14 @@ def coursify(dacourses):
if not offering:
print("NA Offering")
continue

print("FOUND!")

codes = [l["course_code"] for l in offering["course"]["listings"]]
title = offering["course"]["title"]
credit = int(dacourse["credit"].strip("()"))
areas = offering["course"]["areas"]
skills = offering["course"]["skills"]

course = Course(codes, title, credit, areas, skills)
seasons = ["Fall", "Spring"]
course = Course(codes, title, credit, areas, skills, seasons)

# StudentCourse Portion
status = dacourse["status"]
Expand All @@ -108,21 +108,3 @@ def coursify(dacourses):

return student_courses


# mock = {'coursestable': [{'req': '', 'courses': [{'id': 'CPSC 327', 'name': 'Object-Oriented Programming', 'status': 'A', 'credit': '1', 'term': 'Fall 2023', 'designation': 'Qr'}, {'id': 'ART 136', 'name': 'B&W', 'status': 'A', 'credit': '1', 'term': 'Fall 2023', 'designation': 'Qr'}]},
# {'req': '', 'courses': [{'id': 'ENGL 376', 'name': 'Theories of the Western Novel', 'status': 'A-', 'credit': '1', 'term': 'Fall 2023', 'designation': 'Hu'}, {'id': 'HIST 277J', 'name': 'Memory', 'status': 'A', 'credit': '1', 'term': 'Fall 2023', 'designation': 'Qr'}]}]}

# def save(data: dict, filename: str):
# """"""
# with open(filename, 'w') as file:
# json.dump(data, file, indent=4)

# if __name__ == "__main__":
# cookies = { 'session': 'enter_session_here', 'session.sig': 'enter_session_sig_here' }
# timekey = "202302"
# url = f"https://api.coursetable.com/api/static/catalogs/public/{timekey}"

# response = requests.get(url, cookies)
# if response:
# print(timekey)
# save(response.json(), 'public_catalog_data.json')
7 changes: 3 additions & 4 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,14 @@ def sync_data():
return make_response(jsonify({"Error": "Invalid Data"}), 400)

# Process
courses = extract_dacourses(data)
yearTree = yearTreeify(courses)
courses = distill_dacourses(data)
year_tree = year_treeify(courses)

# Store
user = User(loc_netid, data["name"].split(" ")[1], data["degree"], data["major"], uq_student_courses, yearTree, data["coursestable"])
user = User(loc_netid, data["name"].split(" ")[1], data["degree"], data["major"], courses, year_tree, data["coursestable"])
db.collection("Users").document(loc_netid).set(user.__dict__)

# Transfer
# print(data, flush=True)
return make_response(jsonify(data), 200)


Expand Down
2 changes: 1 addition & 1 deletion backend/year.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def term_courses(term_str, courses):
return [course for course in courses if course["season"] == season and course["year"] == year]


def yearTreeify(courses):
def year_treeify(courses):
""""""
terms = list(set(f"{course["season"]} {course["year"]}" for course in courses))

Expand Down
16 changes: 8 additions & 8 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ import Majors from './pages/Majors';

function App() {

const [auth, setAuth] = useState(true);
const [auth, setAuth] = useState(false);

// const checkAuthStatus = async () => {
// const isLoggedIn = await checkLogin();
// setAuth(isLoggedIn);
// };
const checkAuthStatus = async () => {
const isLoggedIn = await checkLogin();
setAuth(isLoggedIn);
};

// useEffect(() => {
// checkAuthStatus();
// }, []);
useEffect(() => {
checkAuthStatus();
}, []);

return (
<div>
Expand Down
71 changes: 25 additions & 46 deletions frontend/src/commons/components/courses/CourseBoxSmall.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import React, { useContext } from "react";

import React from "react";
import styles from "./CourseBoxSmall.module.css";

import "react-tooltip/dist/react-tooltip.css";
import { Tooltip } from "react-tooltip";
import {
Season,
StudentCourse,
Course,
Distribution,
} from "../../types/TypeCourse";
import { Course, StudentCourse } from "../../types/TypeCourse";

import img_fall from "./../../images/fall.png";
import img_spring from "./../../images/spring.png";
Expand All @@ -17,14 +13,14 @@ import DistributionCircle from "./DistributionsCircle";

import { useModal } from "../../../hooks/modalContext";

function CourseSeasonText(season: string ) {
return (
"Course Offered In " + season.charAt(0) + season.slice(1).toLowerCase()
);
}
// function CourseSeasonText(season: string ) {
// return (
// "Course Offered In " + season.charAt(0) + season.slice(1).toLowerCase()
// );
// }

function CourseSeasonIcon(props: { seasons: Array<Season> }) {
const seasonImageMap = {
function CourseSeasonIcon(props: { seasons: Array<string> }) {
const seasonImageMap: { [key: string]: string } = {
"Fall": img_fall,
"Spring": img_spring,
};
Expand All @@ -34,23 +30,11 @@ function CourseSeasonIcon(props: { seasons: Array<Season> }) {
{props.seasons.map((szn, index) => (
<div key={index} style={{ marginLeft: index > 0 ? "-7.5px" : 0 }}>
{seasonImageMap[szn] && (
<div>
<div
data-tooltip-id="season-tooltip"
data-tooltip-content={CourseSeasonText(szn)}
data-tooltip-place="top"
>
<img
style={{ width: "15px", height: "15px" }}
src={seasonImageMap[szn]}
alt={szn}
/>
</div>
<Tooltip
id="season-tooltip"
style={{ backgroundColor: "#444444", borderRadius: "3px" }}
/>
</div>
<img
style={{ width: "15px", height: "15px" }}
src={seasonImageMap[szn]}
alt={szn}
/>
)}
</div>
))}
Expand Down Expand Up @@ -102,29 +86,24 @@ function CourseBoxSmall(props: {studentCourse?: StudentCourse; course?: Course;}
}
}

if (props.course && props.studentCourse == null) {
if(props.course && props.studentCourse == null){
let allDist = [...props.course.areas, ...props.course.skills];
return (
<div className={styles.CourseBox} onClick={openModal}>
{/* <CourseSeasonIcon seasons={props.course.seasons} /> */}
{props.course.code}
{props.course.distribution.length > 0 ? (
<DistCircDiv dist={props.course.distribution} />
) : (
""
)}
<CourseSeasonIcon seasons={props.course.seasons} />
{props.course.codes}
{allDist.length > 0 ? (<DistCircDiv dist={allDist}/>) : ("")}
</div>
);
} else if (props.course == null && props.studentCourse) {
}else if(props.course == null && props.studentCourse){
let allDist = [...props.studentCourse.course.areas, ...props.studentCourse.course.skills];
return (
<div className={`${styles.CourseBox} ${styles.CourseBoxStudent}`} onClick={openModal}>
<CheckMark studentCourse={props.studentCourse} />
{/* <CourseSeasonIcon seasons={[props.studentCourse.season]} /> */}
{props.studentCourse.course.code}
{props.studentCourse.course.distribution.length > 0 ? (
<DistCircDiv dist={props.studentCourse.course.distribution} />
) : (
""
)}
{props.studentCourse.course.codes}
{allDist.length > 0 ? (
<DistCircDiv dist={allDist}/>) : ("")}
</div>
);
}
Expand Down
6 changes: 2 additions & 4 deletions frontend/src/commons/components/courses/CourseModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState } from "react";

import React from "react";
import styles from "./CourseModal.module.css";
import { useModal } from "../../../hooks/modalContext";
import { Dialog } from "@headlessui/react";
Expand All @@ -22,9 +23,6 @@ export default function CourseModal() {
{isOpen !== undefined ? isOpen.title : 'No title'}
</Dialog.Title>
<div style={{ marginTop: "2px" }}>
<p className={styles.descriptionStyle}>
{isOpen !== undefined ? isOpen.description : 'No description'}
</p>
</div>
</Dialog.Panel>
</div>
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/commons/mock/MockCourses.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Course } from "./../types/TypeCourse"

export const EMPTYCOURSE: Course = { code: "N/A", title: "Title NULL", description: "No course", seasons: [], distribution: [] };
export const EMPTYCOURSE: Course = { codes: ["N/A"], title: "Title NULL", credit: 1, areas: [], skills: [], seasons: [] };

export const CPSC201: Course = { code: "CPSC 201", title: "Introduction", description: "", seasons: [], distribution: [] };
export const CPSC202: Course = { code: "CPSC 202", title: "Math Tools", description: "", seasons: [], distribution: [] };
export const CPSC223: Course = { code: "CPSC 223", title: "Data Structures", description: "", seasons: [], distribution: [] };
export const CPSC323: Course = { code: "CPSC 323", title: "Systems", description: "", seasons: [], distribution: [] };
export const CPSC365: Course = { code: "CPSC 365", title: "Algorithms", description: "", seasons: [], distribution: [] };
export const CPSC201: Course = { codes: ["CPSC 201"], title: "Introduction", credit: 1, areas: [], skills: [], seasons: [] };
export const CPSC202: Course = { codes: ["CPSC 202"], title: "Math Tools", credit: 1, areas: [], skills: [], seasons: [] };
export const CPSC223: Course = { codes: ["CPSC 223"], title: "Data Structures", credit: 1, areas: [], skills: [], seasons: [] };
export const CPSC323: Course = { codes: ["CPSC 323"], title: "Systems", credit: 1, areas: [], skills: [], seasons: [] };
export const CPSC365: Course = { codes: ["CPSC 365"], title: "Algorithms", credit: 1, areas: [], skills: [], seasons: [] };
2 changes: 1 addition & 1 deletion frontend/src/commons/mock/MockStudent.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Course, StudentCourse } from "./../types/TypeCourse";
import { Student } from "./../types/TypeStudent";

const CGSC110: Course = { code: "CGSC 110", title: "Introduction to Cognitive Science", seasons: ["Fall"], distribution: ["So"] };
const CGSC110: Course = { codes: ["CGSC 110"], title: "Introduction to Cognitive Science", credit: 1, areas: [], skills: [], seasons: ["Fall"] };
const StudentCGSC110: StudentCourse = { course: CGSC110, status: "COMPLETE", season: "Fall", year: 2022 };

export const MockStudent: Student = {
Expand Down
25 changes: 4 additions & 21 deletions frontend/src/commons/types/TypeCourse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ interface CourseEvaluation {
}

export interface Course {
code: string;
codes: Array<string>;
title: string;
distribution: Array<string>;
credit: number
areas: Array<string>;
skills: Array<string>
seasons: Array<string>;
description?: string;
}

export interface StudentCourse {
Expand All @@ -34,21 +35,3 @@ export interface ClassLists {
clWR: Array<StudentCourse>;
clL: Array<StudentCourse>;
}

// /*Other*/

// type CRN = number;

// interface DistributionalRequirementDIFF {
// title: string;
// }

// interface CourseDIFF {
// crn: CRN;
// all_course_codes: string[];
// skills: DistributionalRequirementDIFF[]; // Distributional requirements
// // professor_names: string[];
// // professor_ids: string[];
// // season_code: string;
// }

5 changes: 2 additions & 3 deletions frontend/src/pages/Courses/Courses.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import React, { useState, useEffect } from "react";
import styles from "./Courses.module.css";

import YearBox from "./components/YearBox";
import AddCourseMenu from "./components/add_course/AddCourse";
// import AddCourseMenu from "./components/add_course/AddCourse";

import MeDropdown from "../../navbar/account/MeDropdown";
// import MeDropdown from "../../navbar/account/MeDropdown";
import nav_styles from "./../../navbar/NavBar.module.css";
import img_logo from "./../../commons/images/ma_logo.png";
import { NavLink } from "react-router-dom";
import PageLinks from "./../../navbar/PageLinks";

function NavBar() {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/Courses/components/CourseBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function CourseBox(props: {course: StudentCourse, displaySetting: DisplaySetting
</div>
<img style={{ width: "15px", height: "15px", marginRight: "6px" }} src={props.course.season === "FALL" ? img_fall : img_spring} alt={props.course.season}></img>
<div>
<div style={{ fontSize: "12px", fontWeight: "500" }}>{props.course.course.code}</div>
<div style={{ fontSize: "12px", fontWeight: "500" }}>{props.course.course.codes[0]}</div>
<div style={{ fontSize: "8px", fontWeight: "500" }}>{props.course.course.title}</div>
</div>
</div>
Expand All @@ -49,7 +49,7 @@ function CourseBox(props: {course: StudentCourse, displaySetting: DisplaySetting
</div>
)} */}
<div>
<DistributionsCircle distributions={props.course.course.distribution}/>
<DistributionsCircle distributions={props.course.course.areas}/>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit 42a043b

Please sign in to comment.