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