我正在努力创造这种人员配置的勇气,以使我的管理工作更轻松天包含一周
天数=[M,T,W,Th,F]
days=[0,1,1,1,1]表示他/她每天工作,星期一除外
如果该值为2,则表示他们进行特殊轮班
他/她从开始工作到结束工作-例如,wakana每天工作0600-1400。 他/她在值为2的日期从特殊开始到特殊结束工作,例如eleonor周一和周五工作0700-1900,周三工作0700-1500
我星期一写了下来,但我知道有一个更好的方法,也许是使用函数,来打印所有的日子。我现在一直在玩它,但我想不出来。提前谢谢你!我非常尊敬各位专家
staffing_data = [
{'name': 'wakana',
'start_time': 6,
'end_time': 14,
'days': [1, 1, 1, 1, 1],
'special_start': None,
'special_end': None},
{'name': 'kate',
'start_time': 11,
'end_time': 21,
'days': [0, 1, 1, 1, 1],
'special_start': None,
'special_end': None},
{'name': 'eleonor',
'start_time': 7,
'end_time': 19,
'days': [1, 0, 2, 0, 1],
'special_start': 7,
'special_end': 15}]
at_7 = 0
at_11 = 0
at_15 = 0
at_19 = 0
for person in staffing_data:
if person['start_time'] <= 7 and person['end_time'] > 7 and person['days'][0] == 1:
at_7 += 1
if person['start_time'] <= 11 and person['end_time'] > 11 and person['days'][0] == 1:
at_11 += 1
if person['start_time'] <= 15 and person['end_time'] > 15 and person['days'][0] == 1:
at_15 += 1
if person['start_time'] <= 19 and person['end_time'] > 19 and person['days'][0] == 1:
at_19 += 1
print(f"{at_7} at 7")
print(f"{at_11} at 11")
print(f"{at_15} at 15")
print(f"{at_19} at 19")
#Monday Staffing
#2 at 7
#3 at 11
#1 at 15
#0 at 19
您只需要另一个循环来循环天数,并存储数据
相关问题 更多 >
编程相关推荐