a app for student projection, this include funtion devide UG and TPG, RPG student, allow users to input expected future target, to get the result of total students number at different level
To upload files, please first save the app
import streamlit as st
import pandas as pd
import numpy as np
st.title("Student Enrollment Projection Tool")
# Initialize session state for storing projections
if 'projections' not in st.session_state:
st.session_state.projections = {}
# Sidebar for input parameters
st.sidebar.header("Enrollment Parameters")
# Current year input
current_year = st.sidebar.number_input("Current Year", min_value=2023, max_value=2050, value=2023)
# Student category inputs
st.sidebar.subheader("Current Student Numbers")
current_ug = st.sidebar.number_input("Current Undergraduate (UG) Students", min_value=0, value=1000)
current_tpg = st.sidebar.number_input("Current Taught Postgraduate (TPG) Students", min_value=0, value=200)
current_rpg = st.sidebar.number_input("Current Research Postgraduate (RPG) Students", min_value=0, value=100)
# Growth rate inputs
st.sidebar.subheader("Expected Annual Growth Rate (%)")
ug_growth = st.sidebar.slider("UG Growth Rate", -20.0, 20.0, 5.0, 0.1)
tpg_growth = st.sidebar.slider("TPG Growth Rate", -20.0, 20.0, 3.0, 0.1)
rpg_growth = st.sidebar.slider("RPG Growth Rate", -20.0, 20.0, 2.0, 0.1)
# Projection years
projection_years = st.sidebar.slider("Number of Years to Project", 1, 10, 5)
# Calculate projections
def calculate_projections(initial, growth_rate, years):
projections = []
current = initial
for _ in range(years + 1):
projections.append(round(current))
current *= (1 + growth_rate/100)
return projections
# Generate year labels
years = list(range(current_year, current_year + projection_years + 1))
# Calculate projections for each category
ug_projections = calculate_projections(current_ug, ug_growth, projection_years)
tpg_projections = calculate_projections(current_tpg, tpg_growth, projection_years)
rpg_projections = calculate_projections(current_rpg, rpg_growth, projection_years)
total_projections = [ug + tpg + rpg for ug, tpg, rpg in zip(ug_projections, tpg_projections, rpg_projections)]
# Create DataFrame for display
df_projections = pd.DataFrame({
'Year': years,
'Undergraduate': ug_projections,
'Taught Postgraduate': tpg_projections,
'Research Postgraduate': rpg_projections,
'Total': total_projections
})
# Display results
st.header("Enrollment Projections")
# Display the projection table
st.subheader("Projected Student Numbers")
st.table(df_projections)
# Create a line chart
st.subheader("Projection Trends")
chart_data = df_projections.melt('Year', var_name='Category', value_name='Students')
st.line_chart(data=df_projections.set_index('Year'))
# Summary statistics
st.subheader("Summary")
final_year = current_year + projection_years
total_growth = {
'UG': ((ug_projections[-1] - ug_projections[0]) / ug_projections[0] * 100),
'TPG': ((tpg_projections[-1] - tpg_projections[0]) / tpg_projections[0] * 100),
'RPG': ((rpg_projections[-1] - rpg_projections[0]) / rpg_projections[0] * 100),
'Total': ((total_projections[-1] - total_projections[0]) / total_projections[0] * 100)
}
st.write(f"By {final_year}:")
col1, col2, col3, col4 = st.columns(4)
with col1:
st.metric("UG Growth", f"{total_growth['UG']:.1f}%")
with col2:
st.metric("TPG Growth", f"{total_growth['TPG']:.1f}%")
with col3:
st.metric("RPG Growth", f"{total_growth['RPG']:.1f}%")
with col4:
st.metric("Total Growth", f"{total_growth['Total']:.1f}%")
# Download the projections as CSV
csv = df_projections.to_csv(index=False)
st.download_button(
label="Download Projections as CSV",
data=csv,
file_name=f"student_projections_{current_year}-{final_year}.csv",
mime="text/csv",
)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?