import streamlit as st
import json
import os
st.set_page_config(
page_title="Ole Miss Degree Planner",
page_icon="π",
layout="wide",
initial_sidebar_state="collapsed",
)
st.markdown("""
""", unsafe_allow_html=True)
# ββ Data ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
@st.cache_data
def load_majors():
data_path = os.path.join(os.path.dirname(__file__), "majors_data.json")
with open(data_path) as f:
return json.load(f)
majors_data = load_majors()
sorted_majors = sorted(majors_data.keys())
GRADE_POINTS = {
"A": 4.0, "A-": 3.7, "B+": 3.3, "B": 3.0, "B-": 2.7,
"C+": 2.3, "C": 2.0, "C-": 1.7, "D+": 1.3, "D": 1.0, "D-": 0.7, "F": 0.0,
}
GRADE_OPTIONS = ["β", "A", "A-", "B+", "B", "B-", "C+", "C", "C-", "D+", "D", "D-", "F"]
OLE_MISS_RMP_ID = 1265
if "grades" not in st.session_state:
st.session_state.grades = {}
# ββ RMP lookup (cached so same name isn't fetched twice per session) ββββββββββ
@st.cache_data(show_spinner=False)
def lookup_professor(name: str):
"""Returns a dict with professor data or an error string."""
try:
import ratemyprofessor
school = ratemyprofessor.get_school_by_name("University of Mississippi")
if school is None:
return {"error": "Could not connect to Rate My Professor. Try again later."}
prof = ratemyprofessor.get_professor_by_school_and_name(school, name)
if prof is None:
return {"error": f"No professor named \"{name}\" found at Ole Miss on Rate My Professor."}
data = {
"name": prof.name,
"department": prof.department,
"rating": prof.rating,
"difficulty": prof.difficulty,
"num_ratings": prof.num_ratings,
"would_take_again": round(prof.would_take_again, 1) if prof.would_take_again is not None else None,
"url": f"https://www.ratemyprofessors.com/professor/{prof.id}",
}
return data
except ImportError:
return {"error": "The ratemyprofessor library is not installed. Make sure requirements.txt includes RateMyProfessorAPI."}
except Exception as e:
return {"error": f"Something went wrong: {str(e)}"}
# ββ Hero ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
st.markdown("""
Degree Planner
Plan your degree, track your GPA, and look up professor ratings β all in one place.
""", unsafe_allow_html=True)
# ββ Tabs ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
tab_planner, tab_rmp = st.tabs(["π Degree Planner", "β Rate My Professor"])
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# TAB 1 β Degree Planner
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
with tab_planner:
left, right = st.columns([1.1, 1], gap="large")
with left:
st.markdown('', unsafe_allow_html=True)
st.markdown('', unsafe_allow_html=True)
selected_major = st.selectbox("Major", options=["β Select a major β"] + sorted_majors, label_visibility="collapsed")
st.markdown('
', unsafe_allow_html=True)
if selected_major and selected_major != "β Select a major β":
all_courses = majors_data[selected_major]
st.markdown('', unsafe_allow_html=True)
st.markdown('', unsafe_allow_html=True)
st.caption("Select every course from this major's requirements that you have already passed.")
completed = st.multiselect(
"Completed courses", options=all_courses,
default=[c for c in st.session_state.grades.keys() if c in all_courses],
label_visibility="collapsed", key=f"completed_{selected_major}",
)
for k in [k for k in st.session_state.grades if k not in completed]:
del st.session_state.grades[k]
st.markdown('
', unsafe_allow_html=True)
if completed:
st.markdown('', unsafe_allow_html=True)
st.markdown('', unsafe_allow_html=True)
st.caption("Select a letter grade for each completed course to calculate your GPA.")
h1, h2 = st.columns([3, 1])
h1.markdown("**Course**")
h2.markdown("**Grade**")
for course in sorted(completed):
c1, c2 = st.columns([3, 1])
c1.markdown(f"{course}", unsafe_allow_html=True)
current = st.session_state.grades.get(course, "β")
new_grade = c2.selectbox(f"g_{course}", options=GRADE_OPTIONS,
index=GRADE_OPTIONS.index(current) if current in GRADE_OPTIONS else 0,
label_visibility="collapsed", key=f"gs_{course}")
st.session_state.grades[course] = new_grade
st.markdown('
', unsafe_allow_html=True)
remaining = [c for c in all_courses if c not in completed]
total = len(all_courses)
done = len(completed)
pct = int(done / total * 100) if total else 0
graded = [(c, g) for c, g in st.session_state.grades.items() if g in GRADE_POINTS and c in completed]
gpa = sum(GRADE_POINTS[g] for _, g in graded) / len(graded) if graded else None
gpa_display = f"{gpa:.2f}" if gpa is not None else "β"
st.markdown('', unsafe_allow_html=True)
st.markdown('', unsafe_allow_html=True)
st.markdown(f"""
{done} of {total} courses completed{pct}%
""", unsafe_allow_html=True)
st.markdown('
', unsafe_allow_html=True)
with right:
if selected_major and selected_major != "β Select a major β":
all_courses = majors_data[selected_major]
completed_list = st.session_state.get(f"completed_{selected_major}", []) or []
remaining = [c for c in all_courses if c not in completed_list]
graded = [(c, g) for c, g in st.session_state.grades.items() if g in GRADE_POINTS and c in completed_list]
gpa = sum(GRADE_POINTS[g] for _, g in graded) / len(graded) if graded else None
# GPA card
st.markdown('', unsafe_allow_html=True)
st.markdown('', unsafe_allow_html=True)
gpa_val = f"{gpa:.2f}" if gpa is not None else "β"
gpa_w = int(gpa / 4.0 * 100) if gpa is not None else 0
if gpa is None: bar_color = "#d1d1d6"
elif gpa >= 3.5: bar_color = "#34c759"
elif gpa >= 3.0: bar_color = "#007aff"
elif gpa >= 2.0: bar_color = "#ff9f0a"
else: bar_color = "#CE2128"
gpa_sub = f"out of 4.0 Β· {len(graded)} graded course(s)" if gpa is not None else "Enter grades in Step 3 to calculate your GPA"
st.markdown(f"""
{gpa_val}
{gpa_sub}
""", unsafe_allow_html=True)
if gpa is not None:
if gpa >= 3.5: st.success("π Dean's List range β excellent work!")
elif gpa >= 3.0: st.info("π Good standing β keep it up!")
elif gpa >= 2.0: st.warning("β οΈ Above minimum β aim higher for more opportunities.")
else: st.error("π¨ Below 2.0 β academic probation risk. Seek advising soon.")
st.markdown('
', unsafe_allow_html=True)
# Remaining courses
st.markdown('', unsafe_allow_html=True)
st.markdown('', unsafe_allow_html=True)
if not remaining:
st.success("π You've completed all listed courses for this major!")
else:
st.caption(f"{len(remaining)} course(s) remaining to finish your degree requirements.")
pills = "".join(f'
{c}' for c in sorted(remaining))
st.markdown(f'
{pills}
', unsafe_allow_html=True)
st.markdown('
', unsafe_allow_html=True)
if completed_list:
st.markdown('', unsafe_allow_html=True)
st.markdown('', unsafe_allow_html=True)
pills = "".join(f'
{c}' for c in sorted(completed_list))
st.markdown(f'
{pills}
', unsafe_allow_html=True)
st.markdown('
', unsafe_allow_html=True)
else:
st.markdown("""
π
Select a major to get started
Your remaining courses, progress, and GPA will appear here.
""", unsafe_allow_html=True)
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# TAB 2 β Rate My Professor
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
with tab_rmp:
st.markdown('', unsafe_allow_html=True)
st.markdown('', unsafe_allow_html=True)
st.caption("Type a professor's last name (or full name) and hit Search to pull their Rate My Professor data.")
col_input, col_btn = st.columns([3, 1])
prof_name = col_input.text_input("Professor name", placeholder="e.g. Smith or John Smith", label_visibility="collapsed")
search_clicked = col_btn.button("Search", use_container_width=True)
st.markdown('
', unsafe_allow_html=True)
if search_clicked and prof_name.strip():
with st.spinner("Looking up professor on Rate My Professorβ¦"):
result = lookup_professor(prof_name.strip())
if "error" in result:
st.error(result["error"])
else:
# Color coding for rating
r = result["rating"]
if r >= 4.0:
rating_color = "#34c759"
elif r >= 3.0:
rating_color = "#007aff"
elif r >= 2.0:
rating_color = "#ff9f0a"
else:
rating_color = "#CE2128"
# Difficulty β lower is better
d = result["difficulty"]
if d <= 2.5:
diff_color = "#34c759"
elif d <= 3.5:
diff_color = "#ff9f0a"
else:
diff_color = "#CE2128"
wta = result["would_take_again"]
wta_display = f"{wta}%" if wta is not None else "N/A"
st.markdown(f"""
{result['name']}
{result['department']} Β· University of Mississippi Β· {result['num_ratings']} rating(s)
{result['rating']}
Overall / 5.0
{result['difficulty']}
Difficulty / 5.0
{wta_display}
Would Retake
View Full Profile on RMP β
""", unsafe_allow_html=True)
elif search_clicked and not prof_name.strip():
st.warning("Please enter a professor's name before searching.")
else:
st.markdown("""
β
Look up any Ole Miss professor
Ratings, difficulty, and would-take-again percentage pulled live from Rate My Professor.
""", unsafe_allow_html=True)
# ββ Footer ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
st.markdown("""
""", unsafe_allow_html=True)