EU law requires at least 11 hours of rest between shifts. How can I ensure compliance?
Prepare a CSV file, which should contain the shift name, shift start time, and shift duration minutes as in the following example.
At the end of the enumeration, also describe the off shift.
Matin,6:30,480
Journée,8:00,510
Après-midi,13:30,480
Nuit,20:45,600
Off,0:00,0
You can get the forbidden shift sequence by reading the CSV file using the following project file
Specify the CSV file.
Specify a rest time of 11 hours.
The forbidden shift sequence will appear on the right screen of the solving pane.
Après-midi → Matin are forbidden shift sequence 9:00:00
Après-midi → Journée are forbidden shift sequence 10:30:00
Nuit → Matin are forbidden shift sequence -1 day, 23:45:00
Nuit → Journée are forbidden shift sequence 1:15:00
Nuit → Après-midi are forbidden shift sequence 6:45:00
This reveals the shift sequence that should be prohibited.
Describe the prohibition in your project as follows.
import sc3
import datetime
import ctypes
import os
import csv
import win32gui, win32con
import pywin.dialogs.list
def get_open_file_name(title):
filter='csv\0*.csv\0'
customfilter='Other file types\0*.*\0'
fname, customfilter, flags=win32gui.GetOpenFileNameW(
InitialDir=project_file_path,
Flags=win32con.OFN_ALLOWMULTISELECT|win32con.OFN_EXPLORER,
File='', DefExt='csv',
Title=title,#
Filter=filter,
CustomFilter=customfilter,
FilterIndex=0)
return str(fname)
def get_hours_selection():
title="Daily rest hours selection"
list=[]
start_hours=9
for m in range(start_hours,15):
list.append(str(m)+"hours")
result=pywin.dialogs.list.SelectFromList(title, list)
print(result)
if result==None :
return 0
return result+start_hours
def get_start_time(s):
start_time = datetime.datetime.strptime(s[1], '%H:%M')
return start_time
duration=datetime.timedelta(minutes=int(s[2]))
end_time=w1+duration
work_end_duration=datetime.timedelta(hours=end_time.hour,minutes=end_time.minute)
oneday_duration=datetime.timedelta(hours=24)
def get_end_time(s):
start_time = get_start_time(s)
duration=datetime.timedelta(minutes=int(s[2]))
end_time=start_time+duration
return end_time
def get_forbidden_shift_seq(list,rest_time):
rest_duration=datetime.timedelta(hours=rest_time)
oneday_duration=datetime.timedelta(hours=24)
print()
for i in range(0,len(list)-1):
start_time=get_start_time(list[i])
end_time=get_end_time(list[i])
#print(start_time,end_time)
for m in range(0,len(list)-1):
next_days_start_time=get_start_time(list[m])+oneday_duration
if next_days_start_time<end_time+rest_duration:
print(list[i][0],'→',list[m][0],'are forbidden shift sequence',next_days_start_time-end_time)
print()
def get_weekly_rest_time(list,rest_time):
rest_duration=datetime.timedelta(hours=rest_time)
oneday_duration=datetime.timedelta(hours=24)
print()
def get_shift_info():
filename=get_open_file_name("Open CSV File")
print(filename,'\n')
list=[]
with open(filename, encoding='utf8', newline='') as f:
csvreader = csv.reader(f)
for row in csvreader:
list.append(row)
#print(row)
hours=get_hours_selection()
if hours !=0:
print("hours=",hours)
get_forbidden_shift_seq(list,hours)# EU rule is dayily 11hours
get_shift_info()#Your Operation
As for night shifts, it is clear that for all shifts except night shift and Day Off, the following shifts should be prohibited.
Other rest periods of less than 11 hours must also be prohibited.