Spaces:
Paused
Paused
| import streamlit as st | |
| import time | |
| from app5_selectbox import academic_list, class_tbl, instructor, program, student, subject, subj_inst, evaluation, evaluation_fac | |
| from app5_selectbox.database_con import cursor, db_connection | |
| def student_login(username, password): | |
| cursor.execute(f"SELECT s.stud_id, s.stud_name, s.class_id, s.user_type FROM student s WHERE s.stud_username='{username}' AND s.stud_password='{password}'") | |
| return cursor.fetchone() | |
| def instructor_login(username, password): | |
| cursor.execute(f"SELECT i.inst_id, i.inst_name, i.prog_id FROM instructor i WHERE i.inst_username='{username}' AND i.inst_password='{password}'") | |
| return cursor.fetchone() | |
| def app5(): | |
| st.title("Student-Faculty Evaluation") | |
| if not hasattr(st.session_state, "logged_in") or not st.session_state.logged_in: | |
| st.subheader("User Login") | |
| username = st.text_input("Username") | |
| password = st.text_input("Password", type="password") | |
| if st.button("Login", type="primary"): | |
| student_info = student_login(username, password) | |
| if student_info: | |
| st.success(f"Hello, {student_info[1]}! Login Successful") | |
| st.session_state.logged_in = True | |
| st.session_state.student_id = student_info[0] | |
| st.session_state.class_id = student_info[2] | |
| st.session_state.user_type = student_info[3] | |
| time.sleep(1) | |
| st.rerun() | |
| elif not student_info: | |
| instructor_info = instructor_login(username, password) | |
| if instructor_info: | |
| st.success(f"Hello, {instructor_info[1]}! Login Successful") | |
| st.session_state.logged_in = True | |
| st.session_state.inst_id = instructor_info[0] | |
| st.session_state.inst_name = instructor_info[1] | |
| st.session_state.prog_id = instructor_info[2] | |
| st.session_state.user_type = 'faculty' | |
| time.sleep(1) | |
| st.rerun() | |
| else: | |
| st.error("Invalid Credentials") | |
| else: | |
| st.error("Invalid Credentials") | |
| else: | |
| if st.session_state.user_type == 'student': | |
| cursor.execute(f"SELECT s.stud_name, c.class_year, c.class_section FROM student s JOIN class c ON s.class_id = c.class_id WHERE s.stud_id='{st.session_state.student_id}'") | |
| student_info = cursor.fetchone() | |
| student_name, class_year, class_section = student_info | |
| st.subheader(f"Hello, {student_name} (Class Year: {class_year}, Section: {class_section}) - Student Evaluation") | |
| cursor.execute(f""" | |
| SELECT si.subj_inst_id, si.sub_id_code, sub.sub_name, i.inst_name | |
| FROM subj_inst si | |
| LEFT JOIN evaluation e ON e.subj_inst_id = si.subj_inst_id AND e.stud_id = {st.session_state.student_id} | |
| INNER JOIN subject sub ON sub.sub_id_code = si.sub_id_code | |
| INNER JOIN instructor i ON i.inst_id = si.inst_id | |
| WHERE e.stud_id IS NULL AND si.class_id = '{st.session_state.class_id}' | |
| """) | |
| subjects = cursor.fetchall() | |
| subject_names = [f"{subject[2]} with Instructor: {subject[3]}" for subject in subjects] | |
| if not subjects: | |
| st.warning("You have evaluated all available subjects. Thank you!") | |
| st.balloons() | |
| progress_text = "logging-out . ..." | |
| my_bar = st.progress(0, text=progress_text) | |
| for percent_complete in range(100): | |
| time.sleep(0.01) | |
| my_bar.progress(percent_complete + 1, text=progress_text) | |
| cursor.execute(f"UPDATE student SET is_eval='TRUE' WHERE stud_id = '{st.session_state.student_id}'") | |
| db_connection.commit() | |
| st.session_state.pop("logged_in", None) | |
| st.session_state.pop("student_id", None) | |
| st.session_state.pop("class_id", None) | |
| st.rerun() | |
| else: | |
| selected_subject = st.selectbox("Select a Subject to Evaluate", subject_names) | |
| selected_subject_id = None | |
| for sel_subject in subjects: | |
| if f"{sel_subject[2]} with Instructor: {sel_subject[3]}" == selected_subject: | |
| selected_subject_id = sel_subject[0] | |
| keys = {} | |
| if selected_subject_id: | |
| st.write(f"You are evaluating the {selected_subject}.") | |
| criteria_list = [ | |
| "Teaching Effectiveness", | |
| "Course Organization", | |
| "Accessibility and Communication", | |
| "Assessment and Grading", | |
| "Respect and Inclusivity", | |
| "Engagement and Interactivity", | |
| "Feedback and Improvement", | |
| "Accessibility of Learning Resources", | |
| "Passion and Enthusiasm", | |
| "Professionalism and Ethical Conduct", | |
| ] | |
| criteria = {} | |
| for i in range(10): | |
| criteria_key = f"criteria_{i}_{selected_subject_id}" | |
| criteria_text = f"{criteria_list[i]} (1-5)" | |
| criteria[i] = st.slider(criteria_text, 1.00, 5.00, 1.00, step=0.05, key=criteria_key) | |
| keys[f"criteria_{i}"] = criteria_key | |
| feedback_comment_key = f"feedback_comment_{selected_subject_id}" | |
| feedback_comment = st.text_area("Feedback/Comments", key=feedback_comment_key) | |
| if st.button("Submit Evaluation"): | |
| if not feedback_comment: | |
| st.warning("Please provide feedback comments.") | |
| else: | |
| cursor.execute(f"SELECT si.inst_id FROM subj_inst si WHERE si.subj_inst_id = '{selected_subject_id}'") | |
| instructor_id = cursor.fetchone() | |
| if instructor_id: | |
| instructor_id = instructor_id[0] | |
| cursor.execute(f"""INSERT INTO evaluation ( | |
| stud_id, | |
| subj_inst_id, | |
| inst_id, | |
| Teaching_Effectiveness, | |
| Course_Organization, | |
| Accessibility_and_Communication, | |
| Assessment_and_Grading, | |
| Respect_and_Inclusivity, | |
| Engagement_and_Interactivity, | |
| Feedback_and_Improvement, | |
| Accessibility_of_Learning_Resources, | |
| Passion_and_Enthusiasm, | |
| Professionalism_and_Ethical_Conduct, | |
| comments, | |
| eval_timestamp) | |
| VALUES ('{st.session_state.student_id}', '{selected_subject_id}', '{instructor_id}', '{criteria[0]}', '{criteria[1]}', '{criteria[2]}', '{criteria[3]}', '{criteria[4]}', '{criteria[5]}', '{criteria[6]}', '{criteria[7]}', '{criteria[8]}', '{criteria[9]}','{feedback_comment}', strftime('%Y-%m-%d %H:%M:%S','now'))""") | |
| db_connection.commit() | |
| with st.empty(): | |
| st.write("Submitting evaluation...") | |
| time.sleep(0.3) | |
| st.success("Evaluation submitted successfully") | |
| time.sleep(0.4) | |
| feedback_comment = "" | |
| st.rerun() | |
| else: | |
| for i in keys.keys(): | |
| keys[i] = None | |
| feedback_comment = None | |
| if st.button("Log Out"): | |
| st.session_state.pop("logged_in", None) | |
| st.session_state.pop("student_id", None) | |
| st.session_state.pop("class_id", None) | |
| st.rerun() | |
| elif st.session_state.user_type == 'faculty': | |
| evaluation_fac.evaluation() | |
| elif st.session_state.user_type == 'admin': | |
| table_name = st.sidebar.selectbox("Select Table", ("academic_list", "class", "instructor", "program", "student", "subject", "subj_inst", "evaluation")) | |
| if table_name == "academic_list": | |
| academic_list.academic_list(table_name) | |
| elif table_name == "class": | |
| class_tbl.class_tbl(table_name) | |
| elif table_name == "instructor": | |
| instructor.instructor(table_name) | |
| elif table_name == "program": | |
| program.program(table_name) | |
| elif table_name == "student": | |
| student.student(table_name) | |
| elif table_name == "subject": | |
| subject.subject(table_name) | |
| elif table_name == "subj_inst": | |
| subj_inst.subj_inst(table_name) | |
| elif table_name == "evaluation": | |
| evaluation.evaluation() | |
| else: | |
| st.error("Select a valid table from the sidebar.") | |
| if st.button("Log Out"): | |
| st.session_state.pop("logged_in", None) | |
| st.session_state.pop("student_id", None) | |
| st.session_state.pop("class_id", None) | |
| st.rerun() | |
| # Call the main function | |
| if __name__ == "__main__": | |
| app5() | |