Akshayram1 commited on
Commit
28b188b
·
verified ·
1 Parent(s): 9f9b802

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -62
app.py CHANGED
@@ -3,89 +3,77 @@ import pandas as pd
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
54
 
55
  def main():
56
- st.title('QA Team Utilization Dashboard')
57
 
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()
 
3
  import matplotlib.pyplot as plt
4
 
5
  def process_data(df):
6
+ # Clean data and consolidate categories
7
+ df = df[['Project Category', 'Logged']].copy()
8
 
9
+ # Map to main categories
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  df['Category'] = df['Project Category'].apply(
11
+ lambda x: 'Billable' if 'Billable' in x else x.strip()
12
  )
13
 
14
  # Aggregate data
15
+ summary = df.groupby('Category')['Logged'].sum().reset_index()
16
+ total = summary['Logged'].sum()
17
+ summary['Percentage'] = (summary['Logged'] / total * 100).round(1)
18
 
19
+ return summary
 
 
 
 
 
 
20
 
21
+ def create_pie_chart(data):
22
  fig, ax = plt.subplots(figsize=(6, 6))
 
 
 
23
  wedges, texts, autotexts = ax.pie(
24
+ data['Logged'],
25
+ labels=data['Category'],
26
  autopct='%1.1f%%',
27
  colors=['#4CAF50', '#FFC107', '#9E9E9E'],
28
  startangle=90
29
  )
 
30
  plt.setp(autotexts, size=10, weight="bold", color='white')
31
+ ax.set_title('Overall Utilization', pad=20)
32
+ return fig
33
+
34
+ def create_bar_chart(data):
35
+ fig, ax = plt.subplots(figsize=(10, 4))
36
+ data[data['Category'] == 'Non-Billable'].plot(
37
+ kind='bar',
38
+ x='Project Category',
39
+ y='Logged',
40
+ ax=ax,
41
+ legend=False
42
+ )
43
+ ax.set_title('Non-Billable Details')
44
+ ax.set_ylabel('Hours')
45
+ plt.xticks(rotation=45)
46
  return fig
47
 
48
  def main():
49
+ st.title('QA Utilization Dashboard')
50
 
51
+ uploaded_file = st.file_uploader("Upload Timesheet", type=['xls', 'xlsx'])
52
 
53
  if uploaded_file:
54
+ df = pd.read_excel(uploaded_file, sheet_name='Report')
55
+ processed_data = process_data(df)
56
+
57
+ # Show main visualization
58
+ st.header("Overall Utilization")
59
+ col1, col2 = st.columns([2, 1])
60
+
61
+ with col1:
62
+ st.pyplot(create_pie_chart(processed_data))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
+ with col2:
65
+ st.dataframe(
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()