shamimjony1000 commited on
Commit
93a0f5c
1 Parent(s): 69e3818

Update task_operations.py

Browse files
Files changed (1) hide show
  1. task_operations.py +56 -1
task_operations.py CHANGED
@@ -1,6 +1,56 @@
 
 
 
 
 
1
  class TaskManager:
 
 
 
2
  def __init__(self):
3
- # Initialization code (e.g., setting up local time zones and loading tasks)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  def generate_report(self, timeframe):
6
  df = pd.DataFrame(st.session_state.tasks)
@@ -26,3 +76,8 @@ class TaskManager:
26
 
27
  report['Total Duration'] = report['Task Duration (hours)'] + report['Task Duration (minutes)'] / 60.0
28
  return report
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ from datetime import datetime
4
+ import os
5
+
6
  class TaskManager:
7
+ TASKS_FILE = "tasks.csv"
8
+ CATEGORIES = ['Learning', 'Gym', 'Personal', 'Family', 'Work', 'Prayer']
9
+
10
  def __init__(self):
11
+ self.local_timezone = 'Asia/Dhaka' # GMT+6
12
+ if 'tasks' not in st.session_state:
13
+ st.session_state.tasks = self.load_tasks()
14
+
15
+ def load_tasks(self):
16
+ if os.path.exists(self.TASKS_FILE):
17
+ if os.path.getsize(self.TASKS_FILE) > 0:
18
+ tasks = pd.read_csv(self.TASKS_FILE, parse_dates=['Task Time']).to_dict(orient='records')
19
+ # Ensure timezone-awareness when loading tasks
20
+ for task in tasks:
21
+ task['Task Time'] = pd.Timestamp(task['Task Time']).tz_localize('UTC').tz_convert(self.local_timezone)
22
+ return tasks
23
+ else:
24
+ return []
25
+ else:
26
+ df = pd.DataFrame(columns=["Task Name", "Task Time", "Task Duration (hours)", "Task Duration (minutes)", "Category"])
27
+ df.to_csv(self.TASKS_FILE, index=False)
28
+ return []
29
+
30
+ def save_tasks(self, tasks):
31
+ df = pd.DataFrame(tasks)
32
+ df['Task Time'] = df['Task Time'].apply(lambda x: x.tz_convert('UTC'))
33
+ df.to_csv(self.TASKS_FILE, index=False)
34
+
35
+ def add_task(self, task_name, task_time, task_duration_hours, task_duration_minutes, task_category):
36
+ task_time_full = datetime.combine(datetime.today(), task_time).astimezone(self.local_timezone)
37
+ task_entry = {
38
+ "Task Name": task_name,
39
+ "Task Time": task_time_full,
40
+ "Task Duration (hours)": int(task_duration_hours),
41
+ "Task Duration (minutes)": int(task_duration_minutes),
42
+ "Category": task_category
43
+ }
44
+ st.session_state.tasks.append(task_entry)
45
+ self.save_tasks(st.session_state.tasks)
46
+
47
+ def delete_task_by_name(self, task_name):
48
+ for index, task in enumerate(st.session_state.tasks):
49
+ if task['Task Name'] == task_name:
50
+ st.session_state.tasks.pop(index)
51
+ self.save_tasks(st.session_state.tasks)
52
+ return True
53
+ return False
54
 
55
  def generate_report(self, timeframe):
56
  df = pd.DataFrame(st.session_state.tasks)
 
76
 
77
  report['Total Duration'] = report['Task Duration (hours)'] + report['Task Duration (minutes)'] / 60.0
78
  return report
79
+
80
+ def download_report(self):
81
+ df = pd.DataFrame(st.session_state.tasks)
82
+ csv = df.to_csv(index=False)
83
+ st.download_button("Download CSV", data=csv, file_name="task_report.csv", mime='text/csv')