File size: 2,994 Bytes
2c59485
 
 
 
 
9f9b802
a07d7fa
2c59485
9f9b802
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2c59485
9f9b802
 
a07d7fa
9f9b802
 
 
a07d7fa
 
 
 
2c59485
 
9f9b802
 
 
 
2c59485
9f9b802
 
2c59485
9f9b802
 
2c59485
9f9b802
2c59485
 
 
 
 
 
 
 
 
 
9f9b802
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2c59485
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt

def process_data(df):
    # Clean data and handle date parsing
    df = df[df['Project Category'].notna()]
    
    # Convert date strings to datetime
    df['Start Date'] = pd.to_datetime(
        df['Date'].str.split(' to ').str[0], 
        format='%d/%b/%y', 
        errors='coerce'
    )
    
    # Filter valid dates and assign weeks
    df = df.dropna(subset=['Start Date'])
    df['Week'] = df['Start Date'].apply(
        lambda x: 1 if x <= pd.Timestamp('2025-01-05') else 2
    )
    
    # Consolidate billable categories
    df['Category'] = df['Project Category'].apply(
        lambda x: 'Billable' if 'Billable' in x else x
    )
    
    # Aggregate data
    utilization = df.groupby(['Week', 'Category'])['Logged'].sum().unstack(fill_value=0)
    
    # Select relevant categories and calculate percentages
    categories = ['Billable', 'Non-Billable', 'Leaves']
    utilization = utilization.reindex(categories, axis=1, fill_value=0)
    total_hours = utilization.sum(axis=1)
    utilization_percent = utilization.div(total_hours, axis=0) * 100
    
    return utilization_percent

def create_utilization_chart(week_data, week_number):
    fig, ax = plt.subplots(figsize=(6, 6))
    labels = week_data.index[week_data > 0]
    sizes = week_data[week_data > 0]
    
    wedges, texts, autotexts = ax.pie(
        sizes,
        labels=labels,
        autopct='%1.1f%%',
        colors=['#4CAF50', '#FFC107', '#9E9E9E'],
        startangle=90
    )
    
    plt.setp(autotexts, size=10, weight="bold", color='white')
    ax.set_title(f'Week {week_number} Utilization', pad=20)
    return fig

def main():
    st.title('QA Team Utilization Dashboard')
    
    uploaded_file = st.file_uploader("Upload Tempo Timesheet", type=['xls', 'xlsx'])
    
    if uploaded_file:
        try:
            df = pd.read_excel(uploaded_file, sheet_name='Report')
            utilization_percent = process_data(df)
            
            # Page 4 Visualization
            st.header("Bi-Weekly Utilization Report")
            col1, col2 = st.columns(2)
            
            with col1:
                if 1 in utilization_percent.index:
                    week1 = utilization_percent.loc[1]
                    st.pyplot(create_utilization_chart(week1, 1))
                else:
                    st.warning("No data for Week 1")
            
            with col2:
                if 2 in utilization_percent.index:
                    week2 = utilization_percent.loc[2]
                    st.pyplot(create_utilization_chart(week2, 2))
                else:
                    st.warning("No data for Week 2")
            
            # Show raw data for verification
            st.subheader("Processed Data Preview")
            st.dataframe(utilization_percent)
            
        except Exception as e:
            st.error(f"Error processing file: {str(e)}")

if __name__ == "__main__":
    main()