-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschedeuling_tasks.py
More file actions
108 lines (108 loc) · 5.74 KB
/
schedeuling_tasks.py
File metadata and controls
108 lines (108 loc) · 5.74 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
# import datetime
# from typing import List, NamedTuple
#
# class Task(NamedTuple):
# name: str
# due: datetime.datetime
# duration: datetime.timedelta
# habit: bool
# frequency: datetime.timedelta
# importance: int
# category: str
# flexibility: int
# energy_required: int
# dependency: str
# interruption_level: int
# enjoyment_level: int
#
# def schedule_tasks(tasks: List[Task], start_time: datetime.datetime, end_time: datetime.datetime, user_peak_hours: List[int], current_stress_level: int) -> List[tuple]:
# """
# Generates an optimized schedule of tasks and breaks within a given timeframe, taking into account the user's peak cognitive hours, current stress level, and task attributes.
#
# The function sorts tasks by importance, urgency, and flexibility. It schedules tasks during the user's peak cognitive hours if the task's required energy level is within the user's current capacity. It also incorporates breaks following scientific productivity techniques, such as the Pomodoro technique and ultradian rhythm alignment.
#
# Parameters:
# - tasks (List[Task]): A list of Task namedtuples, where each Task contains information about the task name, due date, estimated duration, whether it's a habit, frequency of the habit, importance, category, flexibility, energy required, dependency, interruption level, and enjoyment level.
# - start_time (datetime.datetime): The start time from which the scheduling should begin.
# - end_time (datetime.datetime): The end time by which all tasks should be scheduled.
# - user_peak_hours (List[int]): A list of integers representing the hours of the day during which the user is most productive.
# - current_stress_level (int): The user's self-assessed current stress level on a scale from 1 to 5, with 1 being the least stressed and 5 being the most.
#
# Returns:
# - List[tuple]: A list of tuples, where each tuple contains a datetime object representing the start time of the task or break, and the task itself or a string 'Break' indicating a break period.
#
# The function assumes that the user has a consistent set of peak hours. It does not account for the variability of peak hours throughout the week or changes in stress levels over time. The function also assumes that the user can accurately predict the duration of each task and their stress levels.
#
# Example usage:
# tasks = [
# Task('Linear Algebra', datetime.datetime(2023, 11, 10, 17, 0), datetime.timedelta(hours=2), False, None, 5, 'Study', 2, 4, None, 1, 3),
# Task('Exercise', datetime.datetime(2023, 11, 8, 12, 0), datetime.timedelta(hours=1), True, datetime.timedelta(days=1), 3, 'Health', 5, 2, None, 2, 5),
# # Add more tasks as needed
# ]
#
# start_time = datetime.datetime.now()
# end_time = start_time + datetime.timedelta(days=1)
# user_peak_hours = [9, 10, 11, 14, 15, 16] # Example peak hours based on user input
# current_stress_level = 2 # On a scale from 1 to 5
#
# my_schedule = schedule_tasks(tasks, start_time, end_time, user_peak_hours, current_stress_level)
#
# for time_slot in my_schedule:
# if isinstance(time_slot[1], Task):
# print(f"At {time_slot[0]}, work on: {time_slot[1].name}")
# else:
# print(f"At {time_slot[0]}, take a: {time_slot[1]}")
# """
# # Sort tasks by importance, urgency, and flexibility
# sorted_tasks = sorted(tasks, key=lambda x: (-x.importance, -x.flexibility, x.due))
#
# # Initialize the schedule
# schedule = []
# current_time = start_time
#
# for task in sorted_tasks:
# # Check dependencies and adjust the schedule if necessary
# if task.dependency and task.dependency not in [t.name for t, _ in schedule]:
# continue # Skip the task if the dependency is not scheduled yet
#
# # Allocate time for each task based on user's peak hours and energy required
# if current_time.hour in user_peak_hours and task.energy_required > current_stress_level:
# # Schedule the task during peak hours
# schedule.append((current_time, task))
# current_time += task.duration
# else:
# # Schedule the task during off-peak hours if it's less energy-demanding or if the user is stressed
# schedule.append((current_time, task))
# current_time += task.duration
#
# # Add breaks based on task duration and rest intervals
# if task.duration > datetime.timedelta(hours=1.5):
# # Add a longer break after a long task
# schedule.append((current_time, 'Break'))
# current_time += datetime.timedelta(minutes=30)
# else:
# # Add a short break after a short task
# schedule.append((current_time, 'Break'))
# current_time += datetime.timedelta(minutes=5)
#
# return schedule
#
# # Example usage
# tasks = [
# Task('Linear Algebra', datetime.datetime(2023, 11, 10, 17, 0), datetime.timedelta(hours=2), False, None, 5, 'Study', 2, 4, None, 1, 3),
# Task('Exercise', datetime.datetime(2023, 11, 8, 12, 0), datetime.timedelta(hours=1), True, datetime.timedelta(days=1), 3, 'Health', 5, 2, None, 2, 5),
# # Add more tasks as needed
# ]
#
# start_time = datetime.datetime.now()
# end_time = start_time + datetime.timedelta(days=1)
# user_peak_hours = [9, 10, 11, 14, 15, 16] # Example peak hours based on user input
# current_stress_level = 2 # On a scale from 1 to 5
#
# my_schedule = schedule_tasks(tasks, start_time, end_time, user_peak_hours, current_stress_level)
#
# for time_slot in my_schedule:
# if isinstance(time_slot[1], Task):
# print(fAt {time_slot[0]}, work on: {time_slot[1].name})
# else:
# print(fAt {time_slot[0]}, take a: {time_slot[1]})