我正在尝试创建一个基本的调度系统。这是我到目前为止所拥有的:
我有一个 pandas 数据框job_data,如下所示:
| 厕所 | 工作 | 开始 | 期间 |
|---|---|---|---|
| 1 | J1 | 2022-08-16 07:30:00 | 17 号 |
| 1 | J2 | 2022-08-16 07:30:00 | 5 |
| 2 | J3 | 2022-08-16 07:30:00 | 21 |
| 2 | J4 | 2022-08-16 07:30:00 | 12 |
它包含 wc(工作中心)、作业、作业的开始日期和持续时间(以小时为单位)。
我创建了一个函数add_hours,它接受以下参数:start(日期时间)、hours(int)。
它根据开始时间和持续时间计算作业何时完成。
add_hours的代码是:
def is_in_open_hours(dt):
return (
dt.weekday() in business_hours["weekdays"]
and dt.date() not in holidays
and business_hours["from"].hour <= dt.time().hour < business_hours["to"].hour
)
def get_next_open_datetime(dt):
while True:
dt = dt + timedelta(days=1)
if dt.weekday() in business_hours["weekdays"] and dt.date() …Run Code Online (Sandbox Code Playgroud)