Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,12 +3,13 @@ import pandas as pd
|
|
3 |
import matplotlib.pyplot as plt
|
4 |
|
5 |
def process_data(df):
|
6 |
-
# Clean data and
|
7 |
df = df[['Project Category', 'Logged']].copy()
|
|
|
8 |
|
9 |
-
#
|
10 |
df['Category'] = df['Project Category'].apply(
|
11 |
-
lambda x: 'Billable' if 'Billable' in x else x.strip()
|
12 |
)
|
13 |
|
14 |
# Aggregate data
|
@@ -31,9 +32,13 @@ def create_pie_chart(data):
|
|
31 |
ax.set_title('Overall Utilization', pad=20)
|
32 |
return fig
|
33 |
|
34 |
-
def create_bar_chart(
|
|
|
|
|
|
|
|
|
35 |
fig, ax = plt.subplots(figsize=(10, 4))
|
36 |
-
|
37 |
kind='bar',
|
38 |
x='Project Category',
|
39 |
y='Logged',
|
@@ -51,29 +56,36 @@ def main():
|
|
51 |
uploaded_file = st.file_uploader("Upload Timesheet", type=['xls', 'xlsx'])
|
52 |
|
53 |
if uploaded_file:
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
-
|
65 |
-
st.
|
66 |
-
processed_data[['Category', 'Logged', 'Percentage']],
|
67 |
-
hide_index=True,
|
68 |
-
column_config={
|
69 |
-
'Logged': 'Hours',
|
70 |
-
'Percentage': st.column_config.NumberColumn(format="%.1f%%")
|
71 |
-
}
|
72 |
-
)
|
73 |
-
|
74 |
-
# Show non-billable details
|
75 |
-
st.header("Non-Billable Breakdown")
|
76 |
-
st.pyplot(create_bar_chart(df))
|
77 |
|
78 |
if __name__ == "__main__":
|
79 |
main()
|
|
|
3 |
import matplotlib.pyplot as plt
|
4 |
|
5 |
def process_data(df):
|
6 |
+
# Clean data and handle missing values
|
7 |
df = df[['Project Category', 'Logged']].copy()
|
8 |
+
df = df.dropna(subset=['Project Category']) # Remove rows with missing categories
|
9 |
|
10 |
+
# Convert to string and consolidate categories
|
11 |
df['Category'] = df['Project Category'].apply(
|
12 |
+
lambda x: 'Billable' if 'Billable' in str(x) else str(x).strip()
|
13 |
)
|
14 |
|
15 |
# Aggregate data
|
|
|
32 |
ax.set_title('Overall Utilization', pad=20)
|
33 |
return fig
|
34 |
|
35 |
+
def create_bar_chart(df):
|
36 |
+
# Filter and prepare non-billable data
|
37 |
+
non_billable = df[df['Category'] == 'Non-Billable']
|
38 |
+
non_billable = non_billable.groupby('Project Category')['Logged'].sum().reset_index()
|
39 |
+
|
40 |
fig, ax = plt.subplots(figsize=(10, 4))
|
41 |
+
non_billable.plot(
|
42 |
kind='bar',
|
43 |
x='Project Category',
|
44 |
y='Logged',
|
|
|
56 |
uploaded_file = st.file_uploader("Upload Timesheet", type=['xls', 'xlsx'])
|
57 |
|
58 |
if uploaded_file:
|
59 |
+
try:
|
60 |
+
df = pd.read_excel(uploaded_file, sheet_name='Report')
|
61 |
+
processed_data = process_data(df)
|
62 |
+
|
63 |
+
# Show main visualization
|
64 |
+
st.header("Overall Utilization")
|
65 |
+
col1, col2 = st.columns([2, 1])
|
66 |
+
|
67 |
+
with col1:
|
68 |
+
if not processed_data.empty:
|
69 |
+
st.pyplot(create_pie_chart(processed_data))
|
70 |
+
else:
|
71 |
+
st.warning("No data available for visualization")
|
72 |
+
|
73 |
+
with col2:
|
74 |
+
st.dataframe(
|
75 |
+
processed_data[['Category', 'Logged', 'Percentage']],
|
76 |
+
hide_index=True,
|
77 |
+
column_config={
|
78 |
+
'Logged': 'Hours',
|
79 |
+
'Percentage': st.column_config.NumberColumn(format="%.1f%%")
|
80 |
+
}
|
81 |
+
)
|
82 |
+
|
83 |
+
# Show non-billable details
|
84 |
+
st.header("Non-Billable Breakdown")
|
85 |
+
st.pyplot(create_bar_chart(processed_data))
|
86 |
|
87 |
+
except Exception as e:
|
88 |
+
st.error(f"Error processing file: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
|
90 |
if __name__ == "__main__":
|
91 |
main()
|