File size: 2,003 Bytes
197bf20
459d4ec
 
197bf20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
459d4ec
197bf20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
459d4ec
 
 
 
 
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
import matplotlib.pyplot as plt
import pandas as pd
import streamlit as st

class TaskVisualizer:
    def plot_performance(self):
        df = pd.DataFrame(st.session_state.tasks)
        df['Total Duration'] = df['Task Duration (hours)'] + df['Task Duration (minutes)'] / 60.0

        plt.figure(figsize=(10, 5))
        task_times = df.groupby('Task Name')['Total Duration'].sum()
        task_times.plot(kind='bar')
        plt.xlabel('Task')
        plt.ylabel('Hours Spent')
        plt.title('Overall Task Performance')
        plt.xticks(rotation=45)
        plt.tight_layout()
        st.pyplot(plt)

    def plot_category_performance(self, timeframe, task_manager):
        report = task_manager.generate_report(timeframe)
        if not report.empty:
            category_times = report.groupby('Category')['Total Duration'].sum()

            plt.figure(figsize=(10, 5))
            category_times.plot(kind='bar', color='skyblue')
            plt.xlabel('Category')
            plt.ylabel('Total Hours Spent')
            plt.title(f'Task Performance by Category - {timeframe.capitalize()} Report')
            plt.xticks(rotation=45)
            plt.tight_layout()
            st.pyplot(plt)

    def plot_overall_category_performance(self):
        df = pd.DataFrame(st.session_state.tasks)
        df['Total Duration'] = df['Task Duration (hours)'] + df['Task Duration (minutes)'] / 60.0

        category_times = df.groupby('Category')['Total Duration'].sum()

        plt.figure(figsize=(10, 5))
        category_times.plot(kind='bar', color='lightgreen')
        plt.xlabel('Category')
        plt.ylabel('Total Hours Spent')
        plt.title('Overall Task Performance by Category')
        plt.xticks(rotation=45)
        plt.tight_layout()
        st.pyplot(plt)

    def download_report(self):
        df = pd.DataFrame(st.session_state.tasks)
        csv = df.to_csv(index=False)
        st.download_button("Download CSV", data=csv, file_name="task_report.csv", mime='text/csv')