-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.py
More file actions
253 lines (215 loc) · 8.59 KB
/
demo.py
File metadata and controls
253 lines (215 loc) · 8.59 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#!/usr/bin/env python3
"""
Demo script for Productivity Tracker.
This script demonstrates the functionality of the productivity tracker
by adding some sample data and generating reports.
"""
from tracker import Task, ProductivityTracker
from report import ReportGenerator
from utils import get_current_date_string, get_week_start_date
from datetime import date, timedelta
def create_sample_data():
"""Create sample task data for demonstration."""
tracker = ProductivityTracker()
# Get current date and create sample dates
today = date.today()
yesterday = today - timedelta(days=1)
two_days_ago = today - timedelta(days=2)
# Sample tasks
sample_tasks = [
# Today's tasks
Task(
date=today.strftime('%Y-%m-%d'),
task_name="Morning Standup",
duration_minutes=30,
category="Work",
focus_score=7,
notes="Team sync meeting"
),
Task(
date=today.strftime('%Y-%m-%d'),
task_name="Code Review",
duration_minutes=90,
category="Work",
focus_score=8,
notes="Reviewed 3 pull requests"
),
Task(
date=today.strftime('%Y-%m-%d'),
task_name="Gym Workout",
duration_minutes=60,
category="Exercise",
focus_score=9,
notes="Strength training session"
),
Task(
date=today.strftime('%Y-%m-%d'),
task_name="Python Learning",
duration_minutes=45,
category="Study",
focus_score=8,
notes="Advanced Python concepts"
),
# Yesterday's tasks
Task(
date=yesterday.strftime('%Y-%m-%d'),
task_name="Feature Development",
duration_minutes=180,
category="Work",
focus_score=9,
notes="Implemented new API endpoint"
),
Task(
date=yesterday.strftime('%Y-%m-%d'),
task_name="Documentation",
duration_minutes=60,
category="Work",
focus_score=6,
notes="Updated API documentation"
),
Task(
date=yesterday.strftime('%Y-%m-%d'),
task_name="Reading",
duration_minutes=30,
category="Personal",
focus_score=7,
notes="Read productivity book"
),
# Two days ago
Task(
date=two_days_ago.strftime('%Y-%m-%d'),
task_name="Project Planning",
duration_minutes=120,
category="Work",
focus_score=8,
notes="Sprint planning meeting"
),
Task(
date=two_days_ago.strftime('%Y-%m-%d'),
task_name="House Cleaning",
duration_minutes=90,
category="Household",
focus_score=5,
notes="Weekly house cleaning"
),
Task(
date=two_days_ago.strftime('%Y-%m-%d'),
task_name="Cooking",
duration_minutes=45,
category="Personal",
focus_score=6,
notes="Prepared dinner"
)
]
print("Adding sample tasks...")
for task in sample_tasks:
try:
task_id = tracker.add_task(task)
print(f"✅ Added {task.task_name} (ID: {task_id})")
except Exception as e:
print(f"❌ Failed to add {task.task_name}: {e}")
return tracker
def demonstrate_features(tracker):
"""Demonstrate various features of the productivity tracker."""
print("\n" + "="*60)
print("PRODUCTIVITY TRACKER DEMONSTRATION")
print("="*60)
# List all tasks
print("\n1. ALL TASKS:")
print("-" * 30)
tasks = tracker.get_all_tasks()
for task in tasks:
print(f"• {task.task_name} ({task.category}) - {task.duration_minutes}m - Focus: {task.focus_score}/10")
# Daily summaries
print(f"\n2. DAILY SUMMARIES:")
print("-" * 25)
today = date.today()
for i in range(3):
target_date = (today - timedelta(days=i)).strftime('%Y-%m-%d')
total_time = tracker.get_total_time_by_date(target_date)
avg_focus = tracker.get_average_focus_by_date(target_date)
tasks_count = len(tracker.get_tasks_by_date(target_date))
print(f"{target_date}: {total_time}m ({total_time/60:.1f}h) - {tasks_count} tasks - Focus: {avg_focus:.1f}")
# Category summary
print(f"\n3. CATEGORY SUMMARY:")
print("-" * 25)
category_data = tracker.get_category_summary()
for category, data in sorted(category_data.items(), key=lambda x: x[1]['total_time_minutes'], reverse=True):
print(f"{category}: {data['total_time_minutes']}m ({data['total_time_hours']:.1f}h) - "
f"{data['task_count']} tasks - Avg Focus: {data['average_focus']:.1f}")
# Weekly summary
print(f"\n4. WEEKLY SUMMARY:")
print("-" * 20)
week_start = get_week_start_date(today.strftime('%Y-%m-%d'))
weekly_data = tracker.get_weekly_summary(week_start)
total_week_time = sum(day['total_time_minutes'] for day in weekly_data.values())
total_week_tasks = sum(day['task_count'] for day in weekly_data.values())
avg_week_focus = sum(day['average_focus'] for day in weekly_data.values()) / 7
print(f"Week of {week_start}: {total_week_time}m ({total_week_time/60:.1f}h) - "
f"{total_week_tasks} tasks - Avg Focus: {avg_week_focus:.1f}")
# Productivity stats
print(f"\n5. PRODUCTIVITY STATISTICS:")
print("-" * 30)
stats = tracker.get_productivity_stats()
print(f"Total Tasks: {stats['total_tasks']}")
print(f"Total Time: {stats['total_time_hours']:.1f} hours")
print(f"Average Focus: {stats['average_focus']:.1f}/10")
print(f"Average Task Duration: {stats['average_task_duration']:.1f} minutes")
print(f"Most Productive Category: {stats['most_productive_category']}")
print(f"Most Productive Day: {stats['most_productive_day']}")
def generate_sample_reports(tracker):
"""Generate sample reports."""
print(f"\n6. GENERATING REPORTS:")
print("-" * 25)
report_generator = ReportGenerator(tracker)
today = date.today()
week_start = get_week_start_date(today.strftime('%Y-%m-%d'))
try:
print("Generating daily summary report...")
report_generator.generate_daily_summary(today.strftime('%Y-%m-%d'))
print("✅ Daily summary report generated")
print("Generating weekly summary report...")
report_generator.generate_weekly_summary(week_start)
print("✅ Weekly summary report generated")
print("Generating category summary report...")
report_generator.generate_category_summary()
print("✅ Category summary report generated")
print("Generating weekly time chart...")
report_generator.generate_weekly_time_chart(week_start)
print("✅ Weekly time chart generated")
print("Generating category time chart...")
report_generator.generate_category_time_chart()
print("✅ Category time chart generated")
print("Generating focus trend chart...")
report_generator.generate_focus_trend_chart(7) # Last 7 days
print("✅ Focus trend chart generated")
print("Generating productivity heatmap...")
report_generator.generate_productivity_heatmap(2) # Last 2 weeks
print("✅ Productivity heatmap generated")
print("\nAll reports saved to the 'reports/' directory!")
except Exception as e:
print(f"❌ Error generating reports: {e}")
def main():
"""Main demonstration function."""
print("Productivity Tracker Demo")
print("This demo will create sample data and demonstrate features.")
try:
# Create sample data
tracker = create_sample_data()
# Demonstrate features
demonstrate_features(tracker)
# Generate reports
generate_sample_reports(tracker)
print(f"\n" + "="*60)
print("DEMO COMPLETED SUCCESSFULLY!")
print("="*60)
print("You can now:")
print("• Run 'python main.py' for the CLI interface")
print("• Check the 'reports/' directory for generated files")
print("• Check the 'data/' directory for the database")
print("• Use the search functionality to find specific tasks")
print("• Generate custom reports for different date ranges")
except Exception as e:
print(f"❌ Demo failed: {e}")
if __name__ == "__main__":
main()