jdt / task_visualization.py
shamimjony1000's picture
Update task_visualization.py
d4a1459 verified
# components/task_visualization.py
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')