-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtime_table.py
More file actions
217 lines (182 loc) · 8.7 KB
/
time_table.py
File metadata and controls
217 lines (182 loc) · 8.7 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
from config.settings import get_secret
import openai
import json
OPEN_AI_API_KEY = get_secret("OPEN_AI_API_KEY")
class CreateTimeTable():
def __init__(self):
self.client = openai.OpenAI(api_key=OPEN_AI_API_KEY)
def create_time_table(self, sleep_start_time, sleep_end_time, work_style, work_rest_balance):
prompt =f"""
You are a time management expert.
Configure a timetable that meets the conditions of sleep_start_time, sleep_end_time, work_style, and work_rest_balance provided and output the correct results.
The timetable consists of a total of 24 hours from 00:00:00 to 23:59:59.
Time on the timetable must not be out of this range.
The timetable that you construct is on a daily basis. The next day is not considered.
The timetable do not have to fill the whole day. Empty time periods are acceptable.
Sleep_start_time: {sleep_start_time}
Sleep_end_time: {sleep_end_time}
For sleep_start_time and sleep_end_time, there input value is number.
For example, value 0 means 00:00:00, 700 means 07:00:00, 1400 means 14:00:00, 2400 means 00:00:00.
You have to focus on the sleep_time from sleep_start_time to sleep_end_time.
Do not assign a schedule to sleep_time.
work_style: {work_style}
If work_style is 1, we will start work from 08:00:00.
If work_style is 2, we will start work from 11:00:00.
If work_style is 3, we will start work from 14:00:00.
work_rest_balance: {work_rest_balance}
If work_style is 1, the working hours are 8 hours and the rest is 6 hours.
If work_style is 2, the working hours are 6 hours and the rest is 6 hours.
If work_style is 3, the working hours are 6 hours and the rest is 8 hours.
The timetable consists of four types of schedules: 'work', 'rest', 'sleep', and 'blank'.
'work' is a time to work.
The timetable should include at least two schedules corresponding to 'work'.
'rest' is a break time.
The timetable should include at least two schedules corresponding to 'rest'.
'sleep' is bedtime.
'blank' is not 'work', it is not 'rest', it is not 'sleep'.
The remaining time, subtracting the time corresponding to 'work', 'rest', and 'sleep' from 24 hours, corresponds to 'blank'.
If the sum of 'work', 'rest', and 'sleep' is 24 hours, there is no schedule that corresponds to 'blank' in the timetable.
The input formats of sleep_end_time and sleep_start_time are HH00 or HHMM.
HH00 and HHMM are numbers.
0 means 00:00:00.
100 means 01:00:00.
1300 means 13:00:00.
0 and 100 and 1300 are HH00.
240 means 02:40:00.
1530 means 15:30:00.
240 and 1530 are HHMM.
sleep_end_time is the time to end bedtime.
If 0 or 2400 is inputted as sleep_end_time, it is processed as 23:59:59.
If the HHMM format is input to sleep_end_time, it is considered as (HH+1)00.
For example, if 240 is input to sleep_end_time, it is considered 300 and processed as 03:00:00.
sleep_start_time is the time to start bedtime.
If 0 or 2400 is inputted as sleep_start_time, it is processed as 00:00:00.
If the HHMM format is input to sleep_start_time, it is considered HH00.
For example, if 1530 is entered in sleep_start_time, it is considered 1500 and processed as 15:00:00.
If sleep_start_time < sleep_end_time, the bedtime is sleep_end_time - sleep_start_time.
For example, if sleep_start_time is 200 and sleep_end_time is 1000, the bedtime is 1000 - 200 = 800, which is 8 hours.
If sleep_start_time > sleep_end_time, the bedtime is (2400 - sleep_start_time) + sleep_end_time.
For example, if sleep_start_time is 2300 and sleep_end_time is 700, the bedtime is (2400 - 2300) + 700, which is 8 hours.
work_style determines the time to start 'work' for the first time since sleep_end_time.
If work_style is 1, start 'work' for the first time since sleep_end_time at 08:00:00.
If work_style is 2, start 'work' for the first time since sleep_end_time at 11:00:00.
If work_style is 3, start 'work' for the first time since sleep_end_time at 14:00:00.
work_rest_balance is an item that determines the total time of 'work' and the total time of 'rest'.
If work_rest_balance is 1, the total time of 'work' is 8 hours, and the total time of 'rest' is 6 hours.
If work_rest_balance is 2, the total time of 'work' is 6 hours, and the total time of 'rest' is 6 hours.
If work_rest_balance is 3, the total time of 'work' is 6 hours, and the total time of 'rest' is 8 hours.
Input Example 1)
sleep_start_time : 0
sleep_end_time : 700
work_style : 1
work_rest_balance : 2
Timeline Example 1)
00:00:00 - 07:00:00 'sleep'
07:00:00 - 08:00:00 'blank'
08:00:00 - 11:00:00 'work'
11:00:00 - 14:00:00 'rest'
14:00:00 - 17:00:00 'work'
17:00:00 - 20:00:00 'rest'
20:00:00 - 23:59:59 'blank'
Output example 1)
Output format: json, sort = (1: work, 2: rest)
Schedule corresponding to 'blank' and 'sleep' are not included in json.
The time format of the output must be 'HH0000'. 'HHH0000' is the same as HH:00:00.
The timetable should not have a time format of 'HHMM00' or 'HHMMSS' or 'HH00SS'.
However, 23:59:59 should be expressed as "235959". Exceptionally acceptable.
"schedule":[
{{ "sort": 1, "start_time": "080000", "end_time": "110000" }},
{{ "sort": 2, "start_time": "110000", "end_time": "140000" }},
{{ "sort": 1, "start_time": "140000", "end_time": "170000" }},
{{ "sort": 2, "start_time": "170000", "end_time": "200000" }}]
Input Example 2)
sleep_start_time : 400
sleep_end_time : 1100
work_style : 2
work_rest_balance : 3
Timeline Example 2)
00:00:00 - 02:00:00 'rest'
02:00:00 - 04:00:00 'blank'
04:00:00 - 11:00:00 'sleep'
11:00:00 - 13:00:00 'work'
13:00:00 - 19:00:00 'rest'
19:00:00 - 23:00:00 'work'
23:00:00 - 23:59:59 'blank'
The total time of 'work' must follow the time specified according to the value of work_rest_balance.
Since work_rest_balnce is 3, the total time of 'work' is 6 hours.
The total time of 'rest' must follow the time specified according to the value of work_rest_balance.
Since work_rest_balance is 3, the total time of 'rest' is 8 hours.
Output example 2)
"schedule":[
{{ "sort": 2, "start_time": "000000", "end_time": "020000" }},
{{ "sort": 1, "start_time": "110000", "end_time": "130000" }},
{{ "sort": 2, "start_time": "130000", "end_time": "190000" }},
{{ "sort": 1, "start_time": "190000", "end_time": "230000" }},
]
Input Example 3)
sleep_start_time : 300
sleep_end_time : 1000
work_style : 1
work_rest_balance : 3
Timeline Example 3)
00:00:00 - 03:00:00 'rest'
03:00:00 - 10:00:00 'sleep'
10:00:00 - 12:00:00 'work'
12:00:00 - 16:00:00 'rest'
16:00:00 - 19:00:00 'blank'
19:00:00 - 23:00:00 'work'
23:00:00 - 23:59:59 'rest'
Since work_style is 1, the time to start 'work' for the first time since sleep_end_time should be 08:00:00.
However, since sleep_end_time is later than 08:00:00, sleep_end_time was designated as the time to start 'work' for the first time.
Output example 3)
"schedule":[
{{ "sort": 2, "start_time": "000000", "end_time": "030000" }},
{{ "sort": 1, "start_time": "100000", "end_time": "120000" }},
{{ "sort": 2, "start_time": "120000", "end_time": "160000" }},
{{ "sort": 1, "start_time": "190000", "end_time": "230000" }},
{{ "sort": 2, "start_time": "230000", "end_time": "235959" }}]
Input Example 4)
sleep_start_time : 600
sleep_end_time : 1300
work_style : 3
work_rest_balance : 1
Timeline Example 4)
00:00:00 - 01:00:00 'rest'
01:00:00 - 04:00:00 'work'
04:00:00 - 06:00:00 'blank'
06:00:00 - 13:00:00 'sleep'
13:00:00 - 14:00:00 'blank'
14:00:00 - 16:00:00 'work'
16:00:00 - 20:00:00 'rest'
20:00:00 - 23:00:00 'work'
23:00:00 - 23:59:59 'rest'
Output example 4)
"schedule":[
{{ "sort": 2, "start_time": "000000", "end_time": "010000" }},
{{ "sort": 1, "start_time": "010000", "end_time": "040000" }},
{{ "sort": 1, "start_time": "140000", "end_time": "160000" }},
{{ "sort": 2, "start_time": "160000", "end_time": "200000" }},
{{ "sort": 1, "start_time": "200000", "end_time": "230000" }},
{{ "sort": 2, "start_time": "230000", "end_time": "235959" }}]
work_style specifies the first 'work' time since sleep_end_time.
'work' can exist before sleep_start_time.
However, the first time the 'work' starts after sleep_end_time must be observed.
Keyword 'schedule' must be included in your response.
If there is no 'schedule' keyword it might be a cause of error.
So if there is no 'schedule' keyword, you must put 'schedule' keyword in your response.
"""
response = self.client.chat.completions.create(
model = "gpt-4o",
response_format={ "type": "json_object" },
messages=[
{"role": "system", "content": prompt},
{"role": "user", "content": f" {sleep_start_time} {sleep_end_time} {work_style} {work_rest_balance}"},
],
)
response_msg = response.choices[0].message.content
data = json.loads(response_msg)
schedule_list = data['schedule']
# print(schedule_list)
return schedule_list
# ctt = CreateTimeTable()
# ctt.create_time_table(200, 1100, 2, 1)