Spaces:
Sleeping
Sleeping
mistermprah
commited on
Commit
•
e14ffb0
1
Parent(s):
975946e
Update app.py
Browse files
app.py
CHANGED
@@ -1,40 +1,81 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
|
|
3 |
|
4 |
-
# Function to parse the uploaded
|
5 |
def parse_roster(file):
|
6 |
-
df = pd.read_excel(file
|
7 |
-
st.write("File read successfully. Columns in the file:", df.columns)
|
8 |
return df
|
9 |
|
10 |
-
# Function to generate the
|
11 |
def generate_yearly_roster(df):
|
|
|
|
|
12 |
nurses = df['NAMES'].unique()
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
st.title("Nurse Duty Roster Generator")
|
22 |
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
if uploaded_file
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
28 |
one_year_roster = generate_yearly_roster(current_roster)
|
29 |
-
|
30 |
-
st.write("Generated Yearly Roster:")
|
31 |
st.dataframe(one_year_roster)
|
32 |
-
|
33 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
st.download_button(
|
35 |
-
label="Download
|
36 |
-
data=
|
37 |
-
file_name=
|
|
|
38 |
)
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
+
from datetime import timedelta
|
4 |
|
5 |
+
# Function to parse the uploaded file and return a DataFrame
|
6 |
def parse_roster(file):
|
7 |
+
df = pd.read_excel(file)
|
|
|
8 |
return df
|
9 |
|
10 |
+
# Function to generate the next one-year roster
|
11 |
def generate_yearly_roster(df):
|
12 |
+
days_in_year = 365
|
13 |
+
new_roster = []
|
14 |
nurses = df['NAMES'].unique()
|
15 |
+
|
16 |
+
for nurse in nurses:
|
17 |
+
current_day = 0
|
18 |
+
nurse_schedule = []
|
19 |
+
|
20 |
+
while current_day < days_in_year:
|
21 |
+
if nurse == "ADOMAKO SIMON" or nurse == "MAHAMA RAHMAT":
|
22 |
+
shift_pattern = ['M', 'M', 'M', 'M', 'M', 'X', 'X']
|
23 |
+
else:
|
24 |
+
shift_pattern = ['M', 'A', 'N', 'N', 'N', 'N', 'N', 'X', 'X', 'M', 'A', 'A', 'M', 'X', 'X']
|
25 |
+
|
26 |
+
for shift in shift_pattern:
|
27 |
+
if current_day >= days_in_year:
|
28 |
+
break
|
29 |
+
nurse_schedule.append(shift)
|
30 |
+
current_day += 1
|
31 |
+
|
32 |
+
new_roster.append(nurse_schedule)
|
33 |
+
|
34 |
+
return pd.DataFrame(new_roster, index=nurses).T
|
35 |
+
|
36 |
+
# Streamlit app layout
|
37 |
st.title("Nurse Duty Roster Generator")
|
38 |
|
39 |
+
st.markdown("""
|
40 |
+
This app generates a one-year duty roster for nurses based on the current month's schedule.
|
41 |
+
* **Upload**: Upload the current month's roster in Excel format.
|
42 |
+
* **Generate**: Generate the duty roster for the next one year.
|
43 |
+
* **Modify**: Make modifications to the generated roster.
|
44 |
+
""")
|
45 |
+
|
46 |
+
uploaded_file = st.file_uploader("Upload current month's roster", type=['xlsx'])
|
47 |
|
48 |
+
if uploaded_file:
|
49 |
+
current_roster = parse_roster(uploaded_file)
|
50 |
+
st.write("### Current Month's Roster")
|
51 |
+
st.dataframe(current_roster)
|
52 |
+
|
53 |
+
generate_button = st.button("Generate One-Year Roster")
|
54 |
+
if generate_button:
|
55 |
one_year_roster = generate_yearly_roster(current_roster)
|
56 |
+
st.write("### One-Year Duty Roster")
|
|
|
57 |
st.dataframe(one_year_roster)
|
58 |
+
|
59 |
+
# Option to download the generated roster
|
60 |
+
@st.cache
|
61 |
+
def convert_df(df):
|
62 |
+
return df.to_csv(index=False).encode('utf-8')
|
63 |
+
|
64 |
+
csv = convert_df(one_year_roster)
|
65 |
+
|
66 |
st.download_button(
|
67 |
+
label="Download roster as CSV",
|
68 |
+
data=csv,
|
69 |
+
file_name='one_year_roster.csv',
|
70 |
+
mime='text/csv',
|
71 |
)
|
72 |
+
|
73 |
+
# Save changes and regenerate
|
74 |
+
st.write("### Modify and Regenerate Roster")
|
75 |
+
edit_roster = st.text_area("Edit the roster here (CSV format):", height=300)
|
76 |
+
|
77 |
+
if st.button("Save Changes and Regenerate"):
|
78 |
+
edited_df = pd.read_csv(pd.compat.StringIO(edit_roster))
|
79 |
+
one_year_roster = generate_yearly_roster(edited_df)
|
80 |
+
st.write("### Updated One-Year Duty Roster")
|
81 |
+
st.dataframe(one_year_roster)
|