ReadJSShifts now only for operators, minor correction

parent 664d0895
...@@ -98,6 +98,9 @@ class ReadJSShifts(plugin.InputPreparationPlugin, TimeSupportMixin): ...@@ -98,6 +98,9 @@ class ReadJSShifts(plugin.InputPreparationPlugin, TimeSupportMixin):
breakStart, breakEnd = timePair breakStart, breakEnd = timePair
timeStartList.append(breakEnd) timeStartList.append(breakEnd)
timeEndList.insert(0, breakStart) timeEndList.insert(0, breakStart)
# sort the list before proceeding
timeEndList.sort()
timeStartList.sort()
#if it is the current row is an extended row for the information belonging to a resource, and no resource name is entered #if it is the current row is an extended row for the information belonging to a resource, and no resource name is entered
if line[0]: if line[0]:
entityID = line[0].split("-")[0] entityID = line[0].split("-")[0]
...@@ -142,7 +145,7 @@ class ReadJSShifts(plugin.InputPreparationPlugin, TimeSupportMixin): ...@@ -142,7 +145,7 @@ class ReadJSShifts(plugin.InputPreparationPlugin, TimeSupportMixin):
#create default pattern for all operators (10 days long) #create default pattern for all operators (10 days long)
timeStartList = [] timeStartList = []
timeEndList = [] timeEndList = []
for dayNumber in range(0,10): for dayNumber in range(0,20):
startTime = "08:00" startTime = "08:00"
endTime = "18:00" endTime = "18:00"
upDate = now.date()+datetime.timedelta(days=dayNumber) upDate = now.date()+datetime.timedelta(days=dayNumber)
...@@ -167,43 +170,44 @@ class ReadJSShifts(plugin.InputPreparationPlugin, TimeSupportMixin): ...@@ -167,43 +170,44 @@ class ReadJSShifts(plugin.InputPreparationPlugin, TimeSupportMixin):
# ================================================================ # ================================================================
for node, node_data in nodes.items(): for node, node_data in nodes.items():
modifiedDefaultDays = [] # the days of the defaultShiftPattern that have been modified according to the exceptionShiftPattern if node_data.get('_class', None) == 'Dream.Operator':
if node in exceptionShiftPattern: modifiedDefaultDays = [] # the days of the defaultShiftPattern that have been modified according to the exceptionShiftPattern
for index1, exception in enumerate(exceptionShiftPattern[node]): if node in exceptionShiftPattern:
# XXX think of the case where the exception starts one day and finishes the next for index1, exception in enumerate(exceptionShiftPattern[node]):
# calculate the time difference in hours from the end of the first day to the end of the exception # XXX think of the case where the exception starts one day and finishes the next
# check if we are still in the first day # calculate the time difference in hours from the end of the first day to the end of the exception
if hoursToEndFirstDay.total_seconds()/3600 > exception[-1]: # check if we are still in the first day
exceptionDay = 0 if hoursToEndFirstDay.total_seconds()/3600 > exception[-1]:
# calculate the number of days till the end of the exception exceptionDay = 0
else: # calculate the number of days till the end of the exception
exceptionDay = math.floor((exception[-1] - hoursToEndFirstDay.total_seconds()/3600)/24) + 1
for index2, default in enumerate(defaultShiftPattern[node]):
# check if we still are in the first day
if hoursToEndFirstDay.total_seconds()/3600 > default[-1]:
defaultDay = 0
# calculate the number of days till the end of the default shift
else: else:
defaultDay = math.floor((default[-1] - hoursToEndFirstDay.total_seconds()/3600)/24) + 1 exceptionDay = math.floor((exception[-1] - hoursToEndFirstDay.total_seconds()/3600)/24) + 1
if exceptionDay == defaultDay: for index2, default in enumerate(defaultShiftPattern[node]):
# update the defaultShiftPattern of the node (operator or machine) # check if we still are in the first day
# if the exception day has not been modified then delete the previous entry and use the first exception that occurs if hoursToEndFirstDay.total_seconds()/3600 > default[-1]:
if not exceptionDay in modifiedDefaultDays: defaultDay = 0
defaultShiftPattern[node][index2] = exception # calculate the number of days till the end of the default shift
# otherwise append it at the end
else: else:
defaultShiftPattern[node].append(exception) defaultDay = math.floor((default[-1] - hoursToEndFirstDay.total_seconds()/3600)/24) + 1
modifiedDefaultDays.append(exceptionDay) # the day has been modified, add to the modified days if exceptionDay == defaultDay:
break # update the defaultShiftPattern of the node (operator or machine)
# update the interruptions of the nodes that have a defaultShiftPattern # if the exception day has not been modified then delete the previous entry and use the first exception that occurs
if node in defaultShiftPattern: if not exceptionDay in modifiedDefaultDays:
# sort the shift pattern of every node defaultShiftPattern[node][index2] = exception
defaultShiftPattern[node].sort(key=itemgetter(0)) # otherwise append it at the end
# get the interruptions of the object else:
interruptions = node_data.get("interruptions", {}) defaultShiftPattern[node].append(exception)
if not interruptions: modifiedDefaultDays.append(exceptionDay) # the day has been modified, add to the modified days
node_data["interruptions"] = {} break
node_data["interruptions"]["shift"] = {"shiftPattern": defaultShiftPattern.pop(node), # update the interruptions of the nodes that have a defaultShiftPattern
"endUnfinished": 0} if node in defaultShiftPattern:
# sort the shift pattern of every node
defaultShiftPattern[node].sort(key=itemgetter(0))
# get the interruptions of the object
interruptions = node_data.get("interruptions", {})
if not interruptions:
node_data["interruptions"] = {}
node_data["interruptions"]["shift"] = {"shiftPattern": defaultShiftPattern.pop(node),
"endUnfinished": 0}
return data return data
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment