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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Smart Study Planner with Performance Prediction
|
| 2 |
+
|
| 3 |
+
import streamlit as st
|
| 4 |
+
import numpy as np
|
| 5 |
+
import pandas as pd
|
| 6 |
+
|
| 7 |
+
# -------------------------------
|
| 8 |
+
# OOP CLASSES
|
| 9 |
+
# -------------------------------
|
| 10 |
+
|
| 11 |
+
class Subject:
|
| 12 |
+
def __init__(self, name, study_hours, marks):
|
| 13 |
+
self.name = name
|
| 14 |
+
self.study_hours = study_hours
|
| 15 |
+
self.marks = marks
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class Student:
|
| 19 |
+
def __init__(self, name):
|
| 20 |
+
self.name = name
|
| 21 |
+
self.subjects = []
|
| 22 |
+
|
| 23 |
+
def add_subject(self, subject):
|
| 24 |
+
self.subjects.append(subject)
|
| 25 |
+
|
| 26 |
+
def get_data(self):
|
| 27 |
+
data = {
|
| 28 |
+
"Subject": [],
|
| 29 |
+
"Study Hours": [],
|
| 30 |
+
"Marks": []
|
| 31 |
+
}
|
| 32 |
+
for sub in self.subjects:
|
| 33 |
+
data["Subject"].append(sub.name)
|
| 34 |
+
data["Study Hours"].append(sub.study_hours)
|
| 35 |
+
data["Marks"].append(sub.marks)
|
| 36 |
+
return pd.DataFrame(data)
|
| 37 |
+
|
| 38 |
+
def calculate_average(self):
|
| 39 |
+
marks = [sub.marks for sub in self.subjects]
|
| 40 |
+
return np.mean(marks) if marks else 0
|
| 41 |
+
|
| 42 |
+
def get_max_min(self):
|
| 43 |
+
marks = [sub.marks for sub in self.subjects]
|
| 44 |
+
return np.max(marks), np.min(marks)
|
| 45 |
+
|
| 46 |
+
def predict_performance(self, extra_hours=0):
|
| 47 |
+
predicted_marks = []
|
| 48 |
+
for sub in self.subjects:
|
| 49 |
+
increase = extra_hours * 3 # simple formula
|
| 50 |
+
predicted_marks.append(min(sub.marks + increase, 100))
|
| 51 |
+
return np.mean(predicted_marks) if predicted_marks else 0
|
| 52 |
+
|
| 53 |
+
def get_grade(self, marks):
|
| 54 |
+
if marks >= 85:
|
| 55 |
+
return "A"
|
| 56 |
+
elif marks >= 70:
|
| 57 |
+
return "B"
|
| 58 |
+
elif marks >= 55:
|
| 59 |
+
return "C"
|
| 60 |
+
elif marks >= 40:
|
| 61 |
+
return "D"
|
| 62 |
+
else:
|
| 63 |
+
return "F"
|
| 64 |
+
|
| 65 |
+
def best_subject(self):
|
| 66 |
+
return max(self.subjects, key=lambda x: x.marks).name
|
| 67 |
+
|
| 68 |
+
def weak_subject(self):
|
| 69 |
+
return min(self.subjects, key=lambda x: x.marks).name
|
| 70 |
+
|
| 71 |
+
def suggest_improvement(self):
|
| 72 |
+
weak = self.weak_subject()
|
| 73 |
+
return f"Focus more on {weak} and increase study hours."
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
# -------------------------------
|
| 77 |
+
# STREAMLIT UI
|
| 78 |
+
# -------------------------------
|
| 79 |
+
|
| 80 |
+
st.title("π Smart Study Planner")
|
| 81 |
+
|
| 82 |
+
# Student Name
|
| 83 |
+
student_name = st.text_input("Enter Student Name")
|
| 84 |
+
|
| 85 |
+
# Initialize session state
|
| 86 |
+
if "student" not in st.session_state:
|
| 87 |
+
st.session_state.student = None
|
| 88 |
+
|
| 89 |
+
if student_name:
|
| 90 |
+
st.session_state.student = Student(student_name)
|
| 91 |
+
|
| 92 |
+
# Input Fields
|
| 93 |
+
subject_name = st.text_input("Subject Name")
|
| 94 |
+
study_hours = st.number_input("Study Hours", min_value=0.0, step=0.5)
|
| 95 |
+
marks = st.number_input("Marks", min_value=0, max_value=100)
|
| 96 |
+
|
| 97 |
+
# Add Subject Button
|
| 98 |
+
if st.button("Add Subject"):
|
| 99 |
+
if subject_name and st.session_state.student:
|
| 100 |
+
subject = Subject(subject_name, study_hours, marks)
|
| 101 |
+
st.session_state.student.add_subject(subject)
|
| 102 |
+
st.success(f"{subject_name} added!")
|
| 103 |
+
else:
|
| 104 |
+
st.error("Please enter valid data!")
|
| 105 |
+
|
| 106 |
+
# Analyze Button
|
| 107 |
+
if st.button("Analyze Performance"):
|
| 108 |
+
student = st.session_state.student
|
| 109 |
+
|
| 110 |
+
if student and student.subjects:
|
| 111 |
+
df = student.get_data()
|
| 112 |
+
|
| 113 |
+
st.subheader("π Data Table")
|
| 114 |
+
st.dataframe(df)
|
| 115 |
+
|
| 116 |
+
avg = student.calculate_average()
|
| 117 |
+
st.write(f"Average Marks: {avg:.2f}")
|
| 118 |
+
|
| 119 |
+
max_marks, min_marks = student.get_max_min()
|
| 120 |
+
st.write(f"Highest Marks: {max_marks}")
|
| 121 |
+
st.write(f"Lowest Marks: {min_marks}")
|
| 122 |
+
|
| 123 |
+
grade = student.get_grade(avg)
|
| 124 |
+
st.write(f"Current Grade: {grade}")
|
| 125 |
+
|
| 126 |
+
predicted = student.predict_performance(extra_hours=2)
|
| 127 |
+
predicted_grade = student.get_grade(predicted)
|
| 128 |
+
|
| 129 |
+
st.write(f"π If you study 2 more hours, expected marks: {predicted:.2f}")
|
| 130 |
+
st.write(f"Predicted Grade: {predicted_grade}")
|
| 131 |
+
|
| 132 |
+
st.write(f"π Best Subject: {student.best_subject()}")
|
| 133 |
+
st.write(f"β Weak Subject: {student.weak_subject()}")
|
| 134 |
+
|
| 135 |
+
st.write("π‘ Suggestion:", student.suggest_improvement())
|
| 136 |
+
|
| 137 |
+
# Simple chart
|
| 138 |
+
st.subheader("π Study Hours vs Marks")
|
| 139 |
+
st.line_chart(df.set_index("Subject")[["Study Hours", "Marks"]])
|
| 140 |
+
|
| 141 |
+
else:
|
| 142 |
+
st.error("Please add subjects first!")
|
| 143 |
+
|
| 144 |
+
# -------------------------------
|
| 145 |
+
# KAGGLE DATASET INTEGRATION (OPTIONAL)
|
| 146 |
+
# -------------------------------
|
| 147 |
+
|
| 148 |
+
st.subheader("π Optional: Load Dataset")
|
| 149 |
+
|
| 150 |
+
uploaded_file = st.file_uploader("Upload CSV Dataset", type=["csv"])
|
| 151 |
+
|
| 152 |
+
if uploaded_file:
|
| 153 |
+
df = pd.read_csv(uploaded_file)
|
| 154 |
+
|
| 155 |
+
st.write("Raw Data:", df.head())
|
| 156 |
+
|
| 157 |
+
# Cleaning
|
| 158 |
+
df = df.drop_duplicates()
|
| 159 |
+
df = df.fillna(df.mean(numeric_only=True))
|
| 160 |
+
|
| 161 |
+
st.write("Cleaned Data:", df.head())
|
| 162 |
+
|
| 163 |
+
st.write("Dataset Average:", df.mean(numeric_only=True))
|
| 164 |
+
|
| 165 |
+
st.success("Dataset processed successfully!")
|