-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
83 lines (64 loc) · 3.18 KB
/
app.py
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
import pandas as pd
import streamlit as st
import src.compilatore as compilatore
from os.path import join
import src.constants as constants
st.markdown('# Study Plan maker')
st.markdown("### for the MSc in Mathematical Engineering")
CFU_max_tot = st.number_input('Max Total CFUs', min_value=120, max_value=122, value=121, step=1)
CFU_max_sem = st.number_input('Max CFUs per semester', min_value=30, max_value=80, value=35, step=1)
@st.cache_data
def format_func(track):
return {
'MCS': 'MCS - Computational Science and Computational Learning',
'MMF': 'MMF - Quantitative Finance',
'MST': 'MST - Statistical Learning'
}[track]
track_choice = st.selectbox('Major', ('MCS', 'MMF', 'MST'), 2, format_func=format_func)
st.write('Download the example file and fill in the ``Rating`` column.')
PATH = join('assets', 'source.csv')
df_base = pd.read_csv(PATH, header=0)
df_base['Rating'] = 0
st.download_button('Download Example Source CSV File', data=df_base.to_csv(index=False).encode('utf-8'), file_name='study_plan_source_example.csv',)
st.write("To easily edit the CSV file without messing up the formatting, you can use this tool https://www.convertcsv.com/csv-viewer-editor.htm")
df = df_base
uploaded_file = st.file_uploader('Upload your input CSV file', type=['csv'], accept_multiple_files=False)
if uploaded_file:
df = pd.read_csv(uploaded_file).dropna()
st.success('File uploaded correctly.')
st.dataframe(df)
num_suboptimal = st.number_input('How many sub-optimal plans would you like to compute? (default: 0)', min_value=0, max_value=5, value=0, step=1)
if st.button('Compute the best Study Plan!'):
if uploaded_file:
plans, objective = compilatore.generate_plan(
df=df,
track=track_choice,
CFU_max_sem=CFU_max_sem,
CFU_max_tot=CFU_max_tot,
num_suboptimal=num_suboptimal
)
if len(plans) == 0:
st.error(constants.message_infeasible)
elif len(plans) == num_suboptimal + 1:
st.success(constants.message_success)
for plan, obj in zip(plans, objective):
st.dataframe(plan)
cfu_tot = sum(plan['CFU']*plan['%'])
cfu_sem = plan.groupby(['Anno', 'Sem'])['CFU'].sum()
st.write(f'Total interest: {obj}')
st.write(f'The total number of CFUs is: {cfu_tot}')
st.write('Here is the number of CFUs per semester:')
st.dataframe(cfu_sem)
st.write(compilatore.get_exchangable_exams(plan, df, track_choice))
#st.download_button('Download the generated Study Plan', data=piano.to_csv(index=False).encode('utf-8'), file_name='study_plan_output.csv',)
st.markdown("""---""")
else:
st.success('Problem is Optimal!')
st.warning('But the desired number of sub-optimal solutions could not be computed.')
else:
st.error('Please upload a valid input and try again.')
with st.expander("See explanation of the model"):
st.write(constants.model_description)
with st.expander("About"):
st.markdown(constants.disclaimer)
st.markdown(constants.credits, unsafe_allow_html=True)