Spaces:
Sleeping
Sleeping
mistermprah
commited on
Commit
•
13492c4
1
Parent(s):
3616e26
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|