shamimjony1000 commited on
Commit
d4c4acd
·
verified ·
1 Parent(s): cd980e0

Upload 2 files

Browse files
Files changed (2) hide show
  1. task_operations.py +62 -0
  2. task_visualization.py +52 -0
task_operations.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import os
3
+ from datetime import datetime
4
+ import streamlit as st
5
+
6
+ class TaskManager:
7
+ TASKS_FILE = "tasks.csv"
8
+ CATEGORIES = ['Learning', 'Gym', 'Personal', 'Family', 'Work', 'Prayer']
9
+
10
+ def __init__(self):
11
+ if 'tasks' not in st.session_state:
12
+ st.session_state.tasks = self.load_tasks()
13
+
14
+ def load_tasks(self):
15
+ if os.path.exists(self.TASKS_FILE):
16
+ if os.path.getsize(self.TASKS_FILE) > 0:
17
+ return pd.read_csv(self.TASKS_FILE, parse_dates=['Task Time']).to_dict(orient='records')
18
+ else:
19
+ return []
20
+ else:
21
+ df = pd.DataFrame(columns=["Task Name", "Task Time", "Task Duration (hours)", "Task Duration (minutes)", "Category"])
22
+ df.to_csv(self.TASKS_FILE, index=False)
23
+ return []
24
+
25
+ def save_tasks(self, tasks):
26
+ df = pd.DataFrame(tasks)
27
+ df.to_csv(self.TASKS_FILE, index=False)
28
+
29
+ def add_task(self, task_name, task_time, task_duration_hours, task_duration_minutes, task_category):
30
+ task_time_full = datetime.combine(datetime.today(), task_time)
31
+ task_entry = {
32
+ "Task Name": task_name,
33
+ "Task Time": task_time_full,
34
+ "Task Duration (hours)": int(task_duration_hours),
35
+ "Task Duration (minutes)": int(task_duration_minutes),
36
+ "Category": task_category
37
+ }
38
+ st.session_state.tasks.append(task_entry)
39
+ self.save_tasks(st.session_state.tasks)
40
+
41
+ def delete_task_by_name(self, task_name):
42
+ for index, task in enumerate(st.session_state.tasks):
43
+ if task['Task Name'] == task_name:
44
+ st.session_state.tasks.pop(index)
45
+ self.save_tasks(st.session_state.tasks)
46
+ return True
47
+ return False
48
+
49
+ def generate_report(self, timeframe):
50
+ df = pd.DataFrame(st.session_state.tasks)
51
+ if timeframe == 'daily':
52
+ report = df[df['Task Time'].dt.date == pd.Timestamp.today().date()]
53
+ elif timeframe == 'weekly':
54
+ week_start = pd.Timestamp.today() - pd.DateOffset(days=pd.Timestamp.today().dayofweek)
55
+ report = df[(df['Task Time'] >= week_start) & (df['Task Time'] <= pd.Timestamp.today())]
56
+ elif timeframe == 'monthly':
57
+ report = df[df['Task Time'].dt.month == pd.Timestamp.today().month]
58
+ elif timeframe == 'yearly':
59
+ report = df[df['Task Time'].dt.year == pd.Timestamp.today().year]
60
+
61
+ report['Total Duration'] = report['Task Duration (hours)'] + report['Task Duration (minutes)'] / 60.0
62
+ return report
task_visualization.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import matplotlib.pyplot as plt
2
+ import pandas as pd
3
+ import streamlit as st
4
+
5
+ class TaskVisualizer:
6
+ def plot_performance(self):
7
+ df = pd.DataFrame(st.session_state.tasks)
8
+ df['Total Duration'] = df['Task Duration (hours)'] + df['Task Duration (minutes)'] / 60.0
9
+
10
+ plt.figure(figsize=(10, 5))
11
+ task_times = df.groupby('Task Name')['Total Duration'].sum()
12
+ task_times.plot(kind='bar')
13
+ plt.xlabel('Task')
14
+ plt.ylabel('Hours Spent')
15
+ plt.title('Overall Task Performance')
16
+ plt.xticks(rotation=45)
17
+ plt.tight_layout()
18
+ st.pyplot(plt)
19
+
20
+ def plot_category_performance(self, timeframe, task_manager):
21
+ report = task_manager.generate_report(timeframe)
22
+ if not report.empty:
23
+ category_times = report.groupby('Category')['Total Duration'].sum()
24
+
25
+ plt.figure(figsize=(10, 5))
26
+ category_times.plot(kind='bar', color='skyblue')
27
+ plt.xlabel('Category')
28
+ plt.ylabel('Total Hours Spent')
29
+ plt.title(f'Task Performance by Category - {timeframe.capitalize()} Report')
30
+ plt.xticks(rotation=45)
31
+ plt.tight_layout()
32
+ st.pyplot(plt)
33
+
34
+ def plot_overall_category_performance(self):
35
+ df = pd.DataFrame(st.session_state.tasks)
36
+ df['Total Duration'] = df['Task Duration (hours)'] + df['Task Duration (minutes)'] / 60.0
37
+
38
+ category_times = df.groupby('Category')['Total Duration'].sum()
39
+
40
+ plt.figure(figsize=(10, 5))
41
+ category_times.plot(kind='bar', color='lightgreen')
42
+ plt.xlabel('Category')
43
+ plt.ylabel('Total Hours Spent')
44
+ plt.title('Overall Task Performance by Category')
45
+ plt.xticks(rotation=45)
46
+ plt.tight_layout()
47
+ st.pyplot(plt)
48
+
49
+ def download_report(self):
50
+ df = pd.DataFrame(st.session_state.tasks)
51
+ csv = df.to_csv(index=False)
52
+ st.download_button("Download CSV", data=csv, file_name="task_report.csv", mime='text/csv')