Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pinned Majors #51

Merged
merged 8 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 117 additions & 9 deletions backend/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
{
"metadata": {
"name": "Computer Science",
"abbreviation": "CPSC",
"degreeType": "BACH_ART",
"stats": {
"courses": 10,
"courses": 12,
"rating": 0,
"workload": 0,
"type": "QR"
"type": "So"
},
"students": 0,
"about": (
Expand Down Expand Up @@ -42,8 +41,8 @@
"flexible": True,
"courses": [
{
"status": "DA_COMPLETE",
"term": 202203,
"status": "NA",
"term": 0,
"course": {
"codes": ["CPSC 201"],
"title": "Introduction to Computer Science",
Expand Down Expand Up @@ -88,8 +87,8 @@
"flexible": False,
"courses": [
{
"status": "DA_COMPLETE",
"term": 202301,
"status": "NA",
"term": 0,
"course": {
"codes": ["CPSC 223"],
"title": "Data Structures",
Expand All @@ -105,8 +104,8 @@
"flexible": False,
"courses": [
{
"status": "DA_COMPLETE",
"term": 202401,
"status": "NA",
"term": 0,
"course": {
"codes": ["CPSC 323"],
"title": "Introduction to Systems Programming and Computer Organization",
Expand Down Expand Up @@ -156,3 +155,112 @@
}
]
}



ECON_Program = {
"name": "Economics",
"abbreviation": "ECON",
"degrees": [
{
"metadata": {
"name": "Economics",
"degreeType": "BACH_ART",
"stats": {
"courses": 10,
"rating": 0,
"workload": 0,
"type": "So"
},
"students": 0,
"about": "Economics is much broader than the study of recessions and inflation or stocks and bonds. Economists study decision making and incentives such as how taxes create incentives for labor market and savings behavior. Many current public policy debates concern questions of economics, including causes and consequences of inequality and gender and racial wage gaps; how to address poverty; the impact of immigration and trade on the well-being of a country’s citizens; the cause of the Great Recession; and how to predict future downturns.",
"dus": {
"name": "Giovanni Maggi",
"address": "115 Prospect St., Rosenkranz Hall, Room 334",
"email": "cpsc.yale.edu"
},
"catologLink": "https://catalog.yale.edu/ycps/subjects-of-instruction/economics/",
"wesbiteLink": "economics.yale.edu/undergraduate-program"
},
"codesCore": ["ECON 490"],
"codesAdded": [],
"requirements": [
{
"name": "ELECTIVES",
"description": "Usually, courses with course numbers above 200 work for this requirement.",
"subsections": [
{
"flexible": True,
"courses": []
}
]
},
{
"name": "SENIOR REQUIREMENT",
"subsections": [
{
"flexible": False,
"courses": [
{
"status": "NA",
"term": 0,
"course": {
"codes": ["ECON 490"],
"title": "Project",
"credit": 1,
"areas": [],
"skills": ["QR"],
"seasons": ["Fall", "Spring"]
}
}
]
}
]
}
]
}
]
}


HIST_Program = {
"name": "History",
"abbreviation": "HIST",
"degrees": [
{
"metadata": {
"name": "History",
"degreeType": "BACH_ART",
"stats": {
"courses": 10,
"rating": 0,
"workload": 0,
"type": "So"
},
"students": 0,
"about": "Economics is much broader than the study of recessions and inflation or stocks and bonds. Economists study decision making and incentives such as how taxes create incentives for labor market and savings behavior. Many current public policy debates concern questions of economics, including causes and consequences of inequality and gender and racial wage gaps; how to address poverty; the impact of immigration and trade on the well-being of a country’s citizens; the cause of the Great Recession; and how to predict future downturns.",
"dus": {
"name": "Giovanni Maggi",
"address": "115 Prospect St., Rosenkranz Hall, Room 334",
"email": "cpsc.yale.edu"
},
"catologLink": "https://catalog.yale.edu/ycps/subjects-of-instruction/economics/",
"wesbiteLink": "economics.yale.edu/undergraduate-program"
},
"codesCore": [],
"codesAdded": [],
"requirements": [
{
"name": "ELECTIVES",
"description": "Usually, courses with course numbers above 200 work for this requirement.",
"subsections": [
{
"flexible": True,
"courses": []
}
]
}
]
}
]
}
85 changes: 85 additions & 0 deletions backend/ct-script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import http.client
import json

def get_ct_courses():
cookies = {
'session': 'enter_session_here',
'session.sig': 'enter_session_sig_here'
}

conn = http.client.HTTPSConnection("api.coursetable.com")
headers = {
'Cookie': f'session={cookies["session"]}; session.sig={cookies["session.sig"]}'
}

conn.request("GET", "/api/catalog/public/202301", headers=headers)
response = conn.getresponse()
data = response.read()
course_data = json.loads(data.decode("utf-8"))
unique_courses = singalize(course_data)
transformed_data = simplify(unique_courses)

# Splitting the data into four parts
quarter_size = len(transformed_data) // 4
first_part = transformed_data[:quarter_size]
second_part = transformed_data[quarter_size:2*quarter_size]
third_part = transformed_data[2*quarter_size:3*quarter_size]
fourth_part = transformed_data[3*quarter_size:]

# Writing each part to separate files without indents and extra whitespace
with open("results1.txt", "w") as f:
json.dump(first_part, f, separators=(",", ":"))

with open("results2.txt", "w") as f:
json.dump(second_part, f, separators=(",", ":"))

with open("results3.txt", "w") as f:
json.dump(third_part, f, separators=(",", ":"))

with open("results4.txt", "w") as f:
json.dump(fourth_part, f, separators=(",", ":"))

conn.close()

return transformed_data, 200


def singalize(courses):
record = set()
unique = []
for obj in courses:
code = obj.get("course_code")
if code not in record:
record.add(code)
unique.append(obj)
return unique

def simplify(courses):
dict = {}

for obj in courses:
course_code = obj.get("course_code")
listings = obj["course"].get("listings", [])

found_key = None
for code in [listing["course_code"] for listing in listings]:
if code in dict:
found_key = code
break

if found_key:
dict[found_key]["c"].append(course_code)
else:
dict[course_code] = {
"c": [course_code],
"t": obj["course"].get("title"),
"r": obj["course"].get("credits"),
"d": obj["course"].get("skills", []) + obj["course"].get("areas", []),
}

transform = list(dict.values())
return transform


if __name__ == "__main__":
get_ct_courses()
69 changes: 39 additions & 30 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,36 +182,45 @@ def getUser():
return make_response(response_body, 200)


@app.get("/getCTCourses")
def getCTCourses():
key = request.args.get('key')
if not key:
result = {"Error": "Missing Param"}
status_code = 400

cookies = {
'session': 'enter_session_here',
'session.sig': 'enter_session_sig_here'
}
url = f"https://api.coursetable.com/api/catalog/public/{key}"

try:
response = requests.get(url, cookies=cookies)
course_data = response.json()
transformed_data = simplify_CT_courses(course_data)
result = transformed_data
status_code = 200
except requests.exceptions.RequestException as e:
result = {"Error": str(e)}
status_code = 500

# output_file = "output.json"
# with open(output_file, "w") as f:
# json.dump(result, f, indent=2)
# print(f"Result -> {output_file}")

return jsonify(result), status_code

@app.get("/getCatalog")
def getCatalog():
key = request.args.get('key')
if not key:
print("Error: Missing 'key' parameter in request.")
return jsonify({"Error": "Missing Param"}), 400

try:
collections = db.collections()
root_collection_names = [collection.id for collection in collections]

if 'Catalogs' not in root_collection_names:
return jsonify({"Error": "Catalogs Nonexistent"}), 404

print(f"Key: {key}")
slices_ref = db.collection("Catalogs").document(key).collection("Slices")
slices_docs = list(slices_ref.stream())

print(f"# Slices: {len(slices_docs)}")

combined_list = []
for slice_doc in slices_docs:
slice_data = slice_doc.to_dict().get('C', "")

try:
parsed_data = json.loads(slice_data)
combined_list.extend(parsed_data)
except json.JSONDecodeError as e:
return jsonify({"Error": f"Invalid JSON Document {slice_doc.id}"}), 500

if not combined_list:
return jsonify({"Error": "Data Not Found"}), 404

return jsonify(combined_list), 200

except Exception as e:
print(f"Error Firestore: {str(e)}")
return jsonify({"Error": str(e)}), 500


# * * * POST * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Expand Down
5 changes: 2 additions & 3 deletions backend/program.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from copy import deepcopy

from clone import CPSC_Program
from clone import CPSC_Program, ECON_Program, HIST_Program

all_programs = [CPSC_Program]
all_programs = [CPSC_Program, ECON_Program, HIST_Program]

def clone_programs(studentCourses):
# Extract course codes from student courses
Expand All @@ -21,7 +21,6 @@ def clone_programs(studentCourses):
for course in subsection['courses']:
for studentCourse in studentCourses:
if set(course['course']['codes']).intersection(studentCourse['course']['codes']):
# Update course's term and status if there's a match
course['term'] = studentCourse['term']
course['status'] = studentCourse['status']
break # Break after updating to avoid multiple updates
Expand Down
Loading
Loading