-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
341 lines (282 loc) · 10.8 KB
/
app.py
File metadata and controls
341 lines (282 loc) · 10.8 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
"""
Student Performance Tracker - Main Application (SQLite Version)
Streamlit-based academic performance management system
"""
import streamlit as st
import pandas as pd
from datetime import date
import sys
import os
# Add the current directory to Python path for imports
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
# Import custom modules
# In app.py - Use this import
from db.connection import get_db_connection, init_database
# Initialize database
try:
if get_db_connection():
if init_database():
st.success("✅ Database ready!")
else:
st.error("❌ Database initialization failed")
except Exception as e:
st.error(f"Database error: {e}")
from db.connection import get_database_info
from models.student import Student
from models.subject import Subject
from models.marks import Marks
# Page configuration
st.set_page_config(
page_title="Student Performance Tracker",
page_icon="🎓",
layout="wide",
initial_sidebar_state="expanded"
)
# Custom CSS for better styling
st.markdown("""
<style>
.main-header {
text-align: center;
color: #1f77b4;
font-size: 2.5rem;
font-weight: bold;
margin-bottom: 2rem;
}
.metric-card {
background-color: #f0f2f6;
padding: 1rem;
border-radius: 10px;
text-align: center;
}
.success-message {
background-color: #d4edda;
border: 1px solid #c3e6cb;
border-radius: 5px;
padding: 10px;
color: #155724;
}
.sidebar .sidebar-content {
background-color: #f8f9fa;
}
</style>
""", unsafe_allow_html=True)
def initialize_app():
"""Initialize the application"""
# Initialize database if needed
if 'db_initialized' not in st.session_state:
with st.spinner("Initializing SQLite database..."):
try:
if init_database():
st.session_state.db_initialized = True
st.success("✅ Database initialized successfully!")
else:
st.error("Failed to initialize database")
return False
except Exception as e:
st.error(f"Database initialization error: {str(e)}")
return False
return True
def display_dashboard():
"""Display the main dashboard"""
# Header
st.markdown('<h1 class="main-header">🎓 Student Performance Tracker</h1>', unsafe_allow_html=True)
st.markdown("### Welcome to your comprehensive academic performance management system")
st.info("📋 **SQLite Version** - Ready to use without external database setup!")
# Quick stats
with st.spinner("Loading dashboard data..."):
try:
# Get basic statistics
students = Student.get_all_students()
subjects = Subject.get_all_subjects()
marks = Marks.get_all_marks()
# Calculate overall statistics
student_count = len(students) if students else 0
subject_count = len(subjects) if subjects else 0
marks_count = len(marks) if marks else 0
# Calculate overall pass rate
if marks:
passing_marks = sum(1 for mark in marks
if Marks.calculate_percentage(mark[3], mark[4]) >= 40)
pass_rate = (passing_marks / marks_count * 100) if marks_count > 0 else 0
else:
pass_rate = 0
# Calculate overall average
if marks:
total_obtained = sum(mark[3] for mark in marks)
total_possible = sum(mark[4] for mark in marks)
overall_avg = (total_obtained / total_possible * 100) if total_possible > 0 else 0
else:
overall_avg = 0
# Display metrics
col1, col2, col3, col4 = st.columns(4)
with col1:
st.metric("Total Students", student_count)
with col2:
st.metric("Total Subjects", subject_count)
with col3:
st.metric("Total Assessments", marks_count)
with col4:
st.metric("Overall Average", f"{overall_avg:.1f}%")
except Exception as e:
st.error(f"Error loading statistics: {str(e)}")
# Fallback stats
col1, col2, col3, col4 = st.columns(4)
with col1:
st.metric("Total Students", 0)
with col2:
st.metric("Total Subjects", 0)
with col3:
st.metric("Total Assessments", 0)
with col4:
st.metric("Overall Average", "0%")
st.markdown("---")
# Quick actions
st.subheader("🚀 Quick Actions")
col1, col2, col3, col4 = st.columns(4)
with col1:
if st.button("👥 Manage Students", use_container_width=True):
st.switch_page("pages/1_Manage_Students.py")
with col2:
if st.button("📚 Manage Subjects", use_container_width=True):
st.switch_page("pages/2_Manage_Subjects.py")
with col3:
if st.button("📝 Enter Marks", use_container_width=True):
st.switch_page("pages/3_Enter_Update_Marks.py")
with col4:
if st.button("📊 View Analytics", use_container_width=True):
st.switch_page("pages/5_Class_Analytics.py")
st.markdown("---")
# Recent activity section
st.subheader("📈 Recent Activity")
col1, col2 = st.columns(2)
with col1:
st.markdown("#### Latest Students")
try:
recent_students = Student.get_all_students()[:5] # First 5 students
if recent_students:
for student in recent_students:
st.write(f"• {student[1]} - Class {student[2]}-{student[3]}")
else:
st.info("No students found - start by adding some students!")
except Exception as e:
st.warning("Could not load recent students")
with col2:
st.markdown("#### Available Subjects")
try:
subjects = Subject.get_all_subjects()[:5] # First 5 subjects
if subjects:
for subject in subjects:
st.write(f"• {subject[1]}")
else:
st.info("No subjects found - add subjects to get started!")
except Exception as e:
st.warning("Could not load subjects")
# Grade distribution preview
st.markdown("---")
st.subheader("📊 System Overview")
try:
marks = Marks.get_all_marks()
if marks:
# Calculate grade distribution
grade_counts = {}
for mark in marks:
percentage = Marks.calculate_percentage(mark[3], mark[4])
grade = Marks.calculate_grade(percentage)
grade_counts[grade] = grade_counts.get(grade, 0) + 1
col1, col2, col3, col4 = st.columns(4)
with col1:
a_count = grade_counts.get('A+', 0) + grade_counts.get('A', 0)
st.metric("A Grades", a_count)
with col2:
b_count = grade_counts.get('B+', 0) + grade_counts.get('B', 0)
st.metric("B Grades", b_count)
with col3:
c_count = grade_counts.get('C+', 0) + grade_counts.get('C', 0)
st.metric("C Grades", c_count)
with col4:
f_count = grade_counts.get('F', 0)
st.metric("Failing Grades", f_count)
else:
st.info("📝 No marks data available yet. Enter some assessments to see grade distribution!")
except Exception as e:
st.info("Grade distribution will appear when marks are entered")
def display_sidebar():
"""Display sidebar navigation"""
with st.sidebar:
st.title("🎓 Student Tracker")
st.caption("SQLite Edition")
# Navigation menu
st.subheader("📋 Navigation")
if st.button("🏠 Dashboard", use_container_width=True):
st.rerun()
if st.button("👥 Students", use_container_width=True):
st.switch_page("pages/1_Manage_Students.py")
if st.button("📚 Subjects", use_container_width=True):
st.switch_page("pages/2_Manage_Subjects.py")
if st.button("📝 Enter Marks", use_container_width=True):
st.switch_page("pages/3_Enter_Update_Marks.py")
if st.button("📋 Report Cards", use_container_width=True):
st.switch_page("pages/4_Student_Report_Card.py")
if st.button("📊 Analytics", use_container_width=True):
st.switch_page("pages/5_Class_Analytics.py")
st.markdown("---")
# Database status
st.subheader("📊 Database Status")
try:
# Get database info
db_info = get_database_info()
if db_info.get('database_exists'):
st.success("✅ SQLite Database Connected")
# Display basic stats
st.metric("Students", db_info.get('student_count', 0))
st.metric("Subjects", db_info.get('subject_count', 0))
st.metric("Assessments", db_info.get('marks_count', 0))
# Database file size
db_size = db_info.get('database_size', 0)
if db_size > 0:
size_mb = db_size / (1024 * 1024)
st.caption(f"Database size: {size_mb:.2f} MB")
else:
st.warning("⚠️ Database file not found")
except Exception as e:
st.error("❌ Database Connection Error")
st.caption("Database will be created automatically")
st.markdown("---")
# Quick help
with st.expander("ℹ️ Quick Help"):
st.markdown("""
**Getting Started:**
1. Add students in "Students" section
2. Add subjects in "Subjects" section
3. Enter marks in "Enter Marks"
4. View reports and analytics
**Features:**
- No external database required
- Automatic grade calculation
- Performance analytics
- Export capabilities
**SQLite Benefits:**
- Zero configuration
- Portable database file
- Fast and reliable
- Perfect for single-user scenarios
""")
def main():
"""Main application function"""
# Initialize the application
if not initialize_app():
st.stop()
# Display sidebar
display_sidebar()
# Display main dashboard
display_dashboard()
# Footer
st.markdown("---")
st.markdown("""
<div style='text-align: center; color: #666; padding: 20px;'>
<p>🎓 <strong>Student Performance Tracker</strong> | SQLite Edition</p>
<p>Built with ❤️ using Streamlit & SQLite</p>
</div>
""", unsafe_allow_html=True)
if __name__ == "__main__":
main()