Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,39 +3,51 @@ import pandas as pd
|
|
3 |
import matplotlib.pyplot as plt
|
4 |
|
5 |
def process_data(df):
|
6 |
-
# Clean and
|
7 |
df = df[df['Project Category'].notna()]
|
8 |
|
9 |
-
#
|
10 |
-
df['Start Date'] = pd.to_datetime(
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
# Aggregate
|
14 |
-
utilization = df.groupby(['Week', '
|
15 |
|
16 |
-
#
|
|
|
|
|
17 |
total_hours = utilization.sum(axis=1)
|
18 |
utilization_percent = utilization.div(total_hours, axis=0) * 100
|
19 |
|
20 |
-
# Select relevant categories
|
21 |
-
utilization_percent = utilization_percent[['Fixed Bid Projects - Billable',
|
22 |
-
'Non-Billable',
|
23 |
-
'Leaves']].rename(columns={
|
24 |
-
'Fixed Bid Projects - Billable': 'Billable',
|
25 |
-
'Non-Billable': 'Non-Billable',
|
26 |
-
'Leaves': 'Leaves'
|
27 |
-
})
|
28 |
-
|
29 |
return utilization_percent
|
30 |
|
31 |
def create_utilization_chart(week_data, week_number):
|
32 |
-
fig, ax = plt.subplots()
|
|
|
|
|
|
|
33 |
wedges, texts, autotexts = ax.pie(
|
34 |
-
|
35 |
-
labels=
|
36 |
autopct='%1.1f%%',
|
37 |
-
colors=['#4CAF50', '#FFC107', '#9E9E9E']
|
|
|
38 |
)
|
|
|
39 |
plt.setp(autotexts, size=10, weight="bold", color='white')
|
40 |
ax.set_title(f'Week {week_number} Utilization', pad=20)
|
41 |
return fig
|
@@ -46,20 +58,34 @@ def main():
|
|
46 |
uploaded_file = st.file_uploader("Upload Tempo Timesheet", type=['xls', 'xlsx'])
|
47 |
|
48 |
if uploaded_file:
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
if __name__ == "__main__":
|
65 |
main()
|
|
|
3 |
import matplotlib.pyplot as plt
|
4 |
|
5 |
def process_data(df):
|
6 |
+
# Clean data and handle date parsing
|
7 |
df = df[df['Project Category'].notna()]
|
8 |
|
9 |
+
# Convert date strings to datetime
|
10 |
+
df['Start Date'] = pd.to_datetime(
|
11 |
+
df['Date'].str.split(' to ').str[0],
|
12 |
+
format='%d/%b/%y',
|
13 |
+
errors='coerce'
|
14 |
+
)
|
15 |
+
|
16 |
+
# Filter valid dates and assign weeks
|
17 |
+
df = df.dropna(subset=['Start Date'])
|
18 |
+
df['Week'] = df['Start Date'].apply(
|
19 |
+
lambda x: 1 if x <= pd.Timestamp('2025-01-05') else 2
|
20 |
+
)
|
21 |
+
|
22 |
+
# Consolidate billable categories
|
23 |
+
df['Category'] = df['Project Category'].apply(
|
24 |
+
lambda x: 'Billable' if 'Billable' in x else x
|
25 |
+
)
|
26 |
|
27 |
+
# Aggregate data
|
28 |
+
utilization = df.groupby(['Week', 'Category'])['Logged'].sum().unstack(fill_value=0)
|
29 |
|
30 |
+
# Select relevant categories and calculate percentages
|
31 |
+
categories = ['Billable', 'Non-Billable', 'Leaves']
|
32 |
+
utilization = utilization.reindex(categories, axis=1, fill_value=0)
|
33 |
total_hours = utilization.sum(axis=1)
|
34 |
utilization_percent = utilization.div(total_hours, axis=0) * 100
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
return utilization_percent
|
37 |
|
38 |
def create_utilization_chart(week_data, week_number):
|
39 |
+
fig, ax = plt.subplots(figsize=(6, 6))
|
40 |
+
labels = week_data.index[week_data > 0]
|
41 |
+
sizes = week_data[week_data > 0]
|
42 |
+
|
43 |
wedges, texts, autotexts = ax.pie(
|
44 |
+
sizes,
|
45 |
+
labels=labels,
|
46 |
autopct='%1.1f%%',
|
47 |
+
colors=['#4CAF50', '#FFC107', '#9E9E9E'],
|
48 |
+
startangle=90
|
49 |
)
|
50 |
+
|
51 |
plt.setp(autotexts, size=10, weight="bold", color='white')
|
52 |
ax.set_title(f'Week {week_number} Utilization', pad=20)
|
53 |
return fig
|
|
|
58 |
uploaded_file = st.file_uploader("Upload Tempo Timesheet", type=['xls', 'xlsx'])
|
59 |
|
60 |
if uploaded_file:
|
61 |
+
try:
|
62 |
+
df = pd.read_excel(uploaded_file, sheet_name='Report')
|
63 |
+
utilization_percent = process_data(df)
|
64 |
+
|
65 |
+
# Page 4 Visualization
|
66 |
+
st.header("Bi-Weekly Utilization Report")
|
67 |
+
col1, col2 = st.columns(2)
|
68 |
+
|
69 |
+
with col1:
|
70 |
+
if 1 in utilization_percent.index:
|
71 |
+
week1 = utilization_percent.loc[1]
|
72 |
+
st.pyplot(create_utilization_chart(week1, 1))
|
73 |
+
else:
|
74 |
+
st.warning("No data for Week 1")
|
75 |
+
|
76 |
+
with col2:
|
77 |
+
if 2 in utilization_percent.index:
|
78 |
+
week2 = utilization_percent.loc[2]
|
79 |
+
st.pyplot(create_utilization_chart(week2, 2))
|
80 |
+
else:
|
81 |
+
st.warning("No data for Week 2")
|
82 |
+
|
83 |
+
# Show raw data for verification
|
84 |
+
st.subheader("Processed Data Preview")
|
85 |
+
st.dataframe(utilization_percent)
|
86 |
+
|
87 |
+
except Exception as e:
|
88 |
+
st.error(f"Error processing file: {str(e)}")
|
89 |
|
90 |
if __name__ == "__main__":
|
91 |
main()
|