shamimjony1000 commited on
Commit
d669316
1 Parent(s): 2315e7a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -21
app.py CHANGED
@@ -4,46 +4,54 @@ import streamlit as st
4
  from task_operations import TaskManager
5
  from task_visualization import TaskVisualizer
6
  import pandas as pd
 
7
 
8
  def main():
9
- st.title("Jony Daily Task Tracker")
10
 
11
  task_manager = TaskManager()
12
  visualizer = TaskVisualizer()
13
 
14
- # Input fields for adding a task
 
 
 
 
15
  task_name = st.text_input("Task Name")
16
  task_time = st.time_input("Task Time")
17
  task_duration_hours = st.number_input("Task Duration (Hours)", min_value=0, step=1, format="%d")
18
  task_duration_minutes = st.number_input("Task Duration (Minutes)", min_value=0, max_value=59, step=1, format="%d")
19
  task_category = st.selectbox("Task Category", TaskManager.CATEGORIES)
20
 
21
- # Button to add a task
22
  if st.button("Add Task"):
23
  task_manager.add_task(task_name, task_time, task_duration_hours, task_duration_minutes, task_category)
24
  st.success(f"Task '{task_name}' added!")
25
 
26
- # Display the tasks in a table format with Task ID
27
-
28
-
29
  if st.session_state.tasks:
30
  st.write("Today's Tasks:")
 
 
31
  df = pd.DataFrame(st.session_state.tasks)
32
- df['Task Duration (hours)'] = df['Task Duration (hours)'].astype(int)
33
- df['Task Duration (minutes)'] = df['Task Duration (minutes)'].astype(int)
34
- st.table(df[['Task ID', 'Task Name', 'Task Time', 'Task Duration (hours)', 'Task Duration (minutes)', 'Category']]) # Include Task ID here
35
-
36
-
37
-
38
- # Input field for deleting a task by ID
39
- task_id_to_delete = st.text_input("Enter Task ID to Delete") # Task ID instead of Task Name
40
- if st.button("Delete Task"):
41
- if task_manager.delete_task_by_id(task_id_to_delete): # Delete by Task ID
 
 
 
 
42
  st.success(f"Task with ID '{task_id_to_delete}' deleted!")
43
  else:
44
  st.error(f"Task with ID '{task_id_to_delete}' not found.")
45
 
46
- # Daily Report
47
  if st.button("Daily Report"):
48
  report = task_manager.generate_report('daily')
49
  if not report.empty:
@@ -53,7 +61,6 @@ def main():
53
  else:
54
  st.warning("No tasks for today.")
55
 
56
- # Weekly Report
57
  if st.button("Weekly Report"):
58
  report = task_manager.generate_report('weekly')
59
  if not report.empty:
@@ -63,7 +70,6 @@ def main():
63
  else:
64
  st.warning("No tasks for this week.")
65
 
66
- # Monthly Report
67
  if st.button("Monthly Report"):
68
  report = task_manager.generate_report('monthly')
69
  if not report.empty:
@@ -73,7 +79,6 @@ def main():
73
  else:
74
  st.warning("No tasks for this month.")
75
 
76
- # Yearly Report
77
  if st.button("Yearly Report"):
78
  report = task_manager.generate_report('yearly')
79
  if not report.empty:
@@ -83,9 +88,11 @@ def main():
83
  else:
84
  st.warning("No tasks for this year.")
85
 
86
- # Visualizer Plots
87
  visualizer.plot_performance()
88
  visualizer.plot_overall_category_performance()
 
 
89
  visualizer.download_report()
90
 
91
  if __name__ == "__main__":
 
4
  from task_operations import TaskManager
5
  from task_visualization import TaskVisualizer
6
  import pandas as pd
7
+ from datetime import datetime
8
 
9
  def main():
10
+ st.title("Daily Task Tracker")
11
 
12
  task_manager = TaskManager()
13
  visualizer = TaskVisualizer()
14
 
15
+ # Ensure tasks are loaded from the database into session state
16
+ if 'tasks' not in st.session_state:
17
+ st.session_state.tasks = task_manager.load_tasks()
18
+
19
+ # Task input fields
20
  task_name = st.text_input("Task Name")
21
  task_time = st.time_input("Task Time")
22
  task_duration_hours = st.number_input("Task Duration (Hours)", min_value=0, step=1, format="%d")
23
  task_duration_minutes = st.number_input("Task Duration (Minutes)", min_value=0, max_value=59, step=1, format="%d")
24
  task_category = st.selectbox("Task Category", TaskManager.CATEGORIES)
25
 
 
26
  if st.button("Add Task"):
27
  task_manager.add_task(task_name, task_time, task_duration_hours, task_duration_minutes, task_category)
28
  st.success(f"Task '{task_name}' added!")
29
 
30
+ # Display tasks for today only
 
 
31
  if st.session_state.tasks:
32
  st.write("Today's Tasks:")
33
+
34
+ # Convert session tasks to DataFrame and filter tasks for today
35
  df = pd.DataFrame(st.session_state.tasks)
36
+ df['Task Time'] = pd.to_datetime(df['Task Time']) # Ensure 'Task Time' is in datetime format
37
+ today_tasks = df[df['Task Time'].dt.date == datetime.today().date()] # Filter tasks for today
38
+
39
+ if not today_tasks.empty:
40
+ today_tasks['Task Duration (hours)'] = today_tasks['Task Duration (hours)'].astype(int)
41
+ today_tasks['Task Duration (minutes)'] = today_tasks['Task Duration (minutes)'].astype(int)
42
+ st.table(today_tasks[['Task ID', 'Task Name', 'Task Time', 'Task Duration (hours)', 'Task Duration (minutes)', 'Category']])
43
+ else:
44
+ st.write("No tasks for today.")
45
+
46
+ # Task deletion option by ID
47
+ task_id_to_delete = st.number_input("Enter Task ID to Delete", min_value=0, step=1)
48
+ if st.button("Delete Task by ID"):
49
+ if task_manager.delete_task_by_id(task_id_to_delete):
50
  st.success(f"Task with ID '{task_id_to_delete}' deleted!")
51
  else:
52
  st.error(f"Task with ID '{task_id_to_delete}' not found.")
53
 
54
+ # Report options and other visualizations are unchanged
55
  if st.button("Daily Report"):
56
  report = task_manager.generate_report('daily')
57
  if not report.empty:
 
61
  else:
62
  st.warning("No tasks for today.")
63
 
 
64
  if st.button("Weekly Report"):
65
  report = task_manager.generate_report('weekly')
66
  if not report.empty:
 
70
  else:
71
  st.warning("No tasks for this week.")
72
 
 
73
  if st.button("Monthly Report"):
74
  report = task_manager.generate_report('monthly')
75
  if not report.empty:
 
79
  else:
80
  st.warning("No tasks for this month.")
81
 
 
82
  if st.button("Yearly Report"):
83
  report = task_manager.generate_report('yearly')
84
  if not report.empty:
 
88
  else:
89
  st.warning("No tasks for this year.")
90
 
91
+ # Performance visualizations
92
  visualizer.plot_performance()
93
  visualizer.plot_overall_category_performance()
94
+
95
+ # Option to download the report
96
  visualizer.download_report()
97
 
98
  if __name__ == "__main__":