-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
124 lines (102 loc) · 4.83 KB
/
Copy pathapp.py
File metadata and controls
124 lines (102 loc) · 4.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import streamlit as st
import pandas as pd
import plotly.express as px
import sys
import os
sys.path.append(os.path.abspath('src'))
import db
st.set_page_config(page_title="Student Performance Tracker", page_icon="🎓", layout="wide")
# Session State for Login
if 'logged_in' not in st.session_state:
st.session_state['logged_in'] = False
st.session_state['role'] = None
st.session_state['department'] = None
st.session_state['username'] = None
def login():
st.title("🔒 Login")
with st.form("login_form"):
username = st.text_input("Username")
password = st.text_input("Password", type="password")
submit = st.form_submit_button("Login")
if submit:
try:
user = db.authenticate_user(username, password)
if user:
st.session_state['logged_in'] = True
st.session_state['role'] = user[0]
st.session_state['department'] = user[1]
st.session_state['username'] = username
st.rerun()
else:
st.error("Invalid username or password")
except Exception as e:
st.error(f"Database error: {e}. Please run generate_data.py and db.py.")
def logout():
st.session_state['logged_in'] = False
st.session_state['role'] = None
st.session_state['department'] = None
st.session_state['username'] = None
st.rerun()
if not st.session_state['logged_in']:
login()
else:
st.sidebar.markdown(f"**User:** {st.session_state['username']}")
st.sidebar.markdown(f"**Role:** {st.session_state['role']}")
st.sidebar.button("Logout", on_click=logout)
st.title("🎓 Student Performance Predictor Dashboard")
# Load Data
try:
df = db.get_all_students()
# Filter data based on role
if st.session_state['role'] == 'HOD' and st.session_state['department'] != 'All':
df = df[df['department'] == st.session_state['department']]
except Exception as e:
st.error(f"Database not found. Please run the setup scripts. Error: {e}")
df = pd.DataFrame()
if not df.empty:
# Priority Queue
st.subheader("🚨 Priority Queue: Top Students Needing Urgent Attention")
critical_df = df[df['risk_label'] == 'Critical Risk'].sort_values(by='risk_score', ascending=False).head(20)
if not critical_df.empty:
st.dataframe(critical_df[['student_id', 'name', 'department', 'semester', 'risk_score', 'consecutive_absences']], width='stretch')
else:
st.success("No students in critical risk category.")
st.divider()
st.header("Overview Metrics")
total_students = len(df)
high_risk_students = len(df[df['risk_label'].isin(['High Risk', 'Critical Risk'])])
avg_attendance = df['attendance_percentage'].mean()
avg_marks = df['internal_marks'].mean()
col1, col2, col3, col4 = st.columns(4)
with col1:
st.metric("Total Students", f"{total_students}")
with col2:
st.metric("High/Critical Risk", f"{high_risk_students}")
with col3:
st.metric("Average Attendance", f"{avg_attendance:.1f}%")
with col4:
st.metric("Average Internal Marks", f"{avg_marks:.1f}")
st.divider()
col_chart1, col_chart2 = st.columns(2)
with col_chart1:
st.subheader("Risk Distribution")
risk_counts = df['risk_label'].value_counts().reset_index()
risk_counts.columns = ['Risk Level', 'Count']
color_map = {"Low Risk": "#28a745", "Moderate Risk": "#ffc107", "High Risk": "#fd7e14", "Critical Risk": "#dc3545"}
fig = px.pie(risk_counts, values='Count', names='Risk Level', color='Risk Level', color_discrete_map=color_map, hole=0.4)
st.plotly_chart(fig, width='stretch')
with col_chart2:
st.subheader("Risk by Department")
dept_risk = df.groupby(['department', 'risk_label']).size().reset_index(name='Count')
fig2 = px.bar(dept_risk, x='department', y='Count', color='risk_label', color_discrete_map=color_map, barmode='stack')
st.plotly_chart(fig2, width='stretch')
st.divider()
# ERP Upload
st.subheader("📤 College ERP Upload")
uploaded_file = st.file_uploader("Upload CSV containing new student data", type=['csv'])
if uploaded_file is not None:
new_df = pd.read_csv(uploaded_file)
st.write(f"Uploaded {len(new_df)} records. In production, this would parse and append to the database.")
st.dataframe(new_df.head(), width='stretch')
else:
st.info("No data available.")