Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,86 +3,84 @@ import pandas as pd
|
|
3 |
import matplotlib.pyplot as plt
|
4 |
|
5 |
def process_data(df):
|
6 |
-
# Clean
|
7 |
df = df[['Project Category', 'Logged']].copy()
|
8 |
-
df = df.dropna(subset=['Project Category'])
|
9 |
|
10 |
-
#
|
11 |
-
df['Category'] = df['Project Category'].apply(
|
12 |
lambda x: 'Billable' if 'Billable' in str(x) else str(x).strip()
|
13 |
)
|
14 |
|
15 |
-
#
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
|
20 |
-
|
|
|
|
|
|
|
|
|
21 |
|
22 |
def create_pie_chart(data):
|
23 |
fig, ax = plt.subplots(figsize=(6, 6))
|
24 |
wedges, texts, autotexts = ax.pie(
|
25 |
data['Logged'],
|
26 |
-
labels=data['Category'],
|
27 |
autopct='%1.1f%%',
|
28 |
colors=['#4CAF50', '#FFC107', '#9E9E9E'],
|
29 |
startangle=90
|
30 |
)
|
31 |
plt.setp(autotexts, size=10, weight="bold", color='white')
|
32 |
-
ax.set_title('Overall Utilization', pad=20)
|
33 |
return fig
|
34 |
|
35 |
-
def create_bar_chart(
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
fig, ax = plt.subplots(figsize=(10, 4))
|
41 |
-
non_billable.plot(
|
42 |
-
kind='bar',
|
43 |
-
x='Project Category',
|
44 |
-
y='Logged',
|
45 |
-
ax=ax,
|
46 |
-
legend=False
|
47 |
-
)
|
48 |
-
ax.set_title('Non-Billable Details')
|
49 |
ax.set_ylabel('Hours')
|
50 |
-
|
|
|
|
|
51 |
return fig
|
52 |
|
53 |
def main():
|
54 |
-
st.title('QA Utilization Dashboard')
|
55 |
|
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 |
-
|
62 |
|
63 |
-
#
|
64 |
st.header("Overall Utilization")
|
65 |
col1, col2 = st.columns([2, 1])
|
66 |
|
67 |
with col1:
|
68 |
-
|
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 |
-
|
76 |
hide_index=True,
|
77 |
column_config={
|
78 |
-
'
|
|
|
79 |
'Percentage': st.column_config.NumberColumn(format="%.1f%%")
|
80 |
}
|
81 |
)
|
82 |
|
83 |
-
#
|
84 |
-
st.header("Non-Billable Breakdown")
|
85 |
-
st.pyplot(create_bar_chart(
|
|
|
|
|
|
|
|
|
86 |
|
87 |
except Exception as e:
|
88 |
st.error(f"Error processing file: {str(e)}")
|
|
|
3 |
import matplotlib.pyplot as plt
|
4 |
|
5 |
def process_data(df):
|
6 |
+
# Clean and prepare data
|
7 |
df = df[['Project Category', 'Logged']].copy()
|
8 |
+
df = df.dropna(subset=['Project Category'])
|
9 |
|
10 |
+
# Consolidate categories
|
11 |
+
df['Main Category'] = df['Project Category'].apply(
|
12 |
lambda x: 'Billable' if 'Billable' in str(x) else str(x).strip()
|
13 |
)
|
14 |
|
15 |
+
# Group by main categories
|
16 |
+
main_categories = df.groupby('Main Category')['Logged'].sum().reset_index()
|
17 |
+
total_hours = main_categories['Logged'].sum()
|
18 |
+
main_categories['Percentage'] = (main_categories['Logged'] / total_hours * 100).round(1)
|
19 |
|
20 |
+
# Prepare non-billable breakdown
|
21 |
+
non_billable = df[df['Main Category'] == 'Non-Billable']
|
22 |
+
non_billable_breakdown = non_billable.groupby('Project Category')['Logged'].sum().reset_index()
|
23 |
+
|
24 |
+
return main_categories, non_billable_breakdown
|
25 |
|
26 |
def create_pie_chart(data):
|
27 |
fig, ax = plt.subplots(figsize=(6, 6))
|
28 |
wedges, texts, autotexts = ax.pie(
|
29 |
data['Logged'],
|
30 |
+
labels=data['Main Category'],
|
31 |
autopct='%1.1f%%',
|
32 |
colors=['#4CAF50', '#FFC107', '#9E9E9E'],
|
33 |
startangle=90
|
34 |
)
|
35 |
plt.setp(autotexts, size=10, weight="bold", color='white')
|
36 |
+
ax.set_title('Overall Utilization Distribution', pad=20)
|
37 |
return fig
|
38 |
|
39 |
+
def create_bar_chart(data):
|
40 |
+
fig, ax = plt.subplots(figsize=(10, 5))
|
41 |
+
data.plot(kind='bar', x='Project Category', y='Logged', ax=ax, legend=False)
|
42 |
+
ax.set_title('Non-Billable Time Breakdown')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
ax.set_ylabel('Hours')
|
44 |
+
ax.set_xlabel('')
|
45 |
+
plt.xticks(rotation=45, ha='right')
|
46 |
+
plt.tight_layout()
|
47 |
return fig
|
48 |
|
49 |
def main():
|
50 |
+
st.title('QA Team Utilization Dashboard')
|
51 |
|
52 |
+
uploaded_file = st.file_uploader("Upload Timesheet Excel File", type=['xls', 'xlsx'])
|
53 |
|
54 |
if uploaded_file:
|
55 |
try:
|
56 |
df = pd.read_excel(uploaded_file, sheet_name='Report')
|
57 |
+
main_cats, non_billable = process_data(df)
|
58 |
|
59 |
+
# Main utilization section
|
60 |
st.header("Overall Utilization")
|
61 |
col1, col2 = st.columns([2, 1])
|
62 |
|
63 |
with col1:
|
64 |
+
st.pyplot(create_pie_chart(main_cats))
|
|
|
|
|
|
|
65 |
|
66 |
with col2:
|
67 |
st.dataframe(
|
68 |
+
main_cats[['Main Category', 'Logged', 'Percentage']],
|
69 |
hide_index=True,
|
70 |
column_config={
|
71 |
+
'Main Category': 'Category',
|
72 |
+
'Logged': st.column_config.NumberColumn('Hours', format="%.2f"),
|
73 |
'Percentage': st.column_config.NumberColumn(format="%.1f%%")
|
74 |
}
|
75 |
)
|
76 |
|
77 |
+
# Non-billable breakdown
|
78 |
+
st.header("Non-Billable Detailed Breakdown")
|
79 |
+
st.pyplot(create_bar_chart(non_billable))
|
80 |
+
|
81 |
+
# Raw data preview
|
82 |
+
st.subheader("Raw Data Preview")
|
83 |
+
st.dataframe(df.head(10), hide_index=True)
|
84 |
|
85 |
except Exception as e:
|
86 |
st.error(f"Error processing file: {str(e)}")
|