offshift intervals handled

parent fa371ab9
...@@ -14,6 +14,20 @@ class ReadJSShifts(plugin.InputPreparationPlugin, TimeSupportMixin): ...@@ -14,6 +14,20 @@ class ReadJSShifts(plugin.InputPreparationPlugin, TimeSupportMixin):
reads the shifts from a spreadsheet reads the shifts from a spreadsheet
""" """
def correctTimePair(self, start, end):
'''takes a pair of times and returns the corrected pair according to the current time'''
# if the end of shift shift already finished we do not need to consider in simulation
if start<0 and end<=0:
return None
# if the start of the shift is before now, set the start to 0
if start<0:
start=0
# sometimes the date may change (e.g. shift from 23:00 to 01:00).
# these would be declared in the date of the start so add a date (self.timeUnitPerDay) to the end
if end<start:
end+=self.timeUnitPerDay
return (start, end)
def preprocess(self, data): def preprocess(self, data):
""" reads the shifts from a spreadsheet and updates the interruptions of the corresponding node objects """ reads the shifts from a spreadsheet and updates the interruptions of the corresponding node objects
""" """
...@@ -34,10 +48,20 @@ class ReadJSShifts(plugin.InputPreparationPlugin, TimeSupportMixin): ...@@ -34,10 +48,20 @@ class ReadJSShifts(plugin.InputPreparationPlugin, TimeSupportMixin):
if shiftData: if shiftData:
shiftData.pop(0) shiftData.pop(0)
#iteration through the raw data to structure it into ManPy config #iteration through the raw data to structure it into ManPy config
for line in shiftData: for line in shiftData:
# if all the records of that line are none then continue # if all the records of that line are none then continue
if any(record==None for record in line): toContinue = False
for record in line:
if record != None:
toContinue = True
break
if not toContinue:
continue continue
# list to hold the working intervals start times
timeStartList = []
# list to hold the working intervals end times
timeEndList = []
#if no shift start was given, assume standard 8:00 #if no shift start was given, assume standard 8:00
startTime = line[2] startTime = line[2]
if startTime == '': if startTime == '':
...@@ -48,21 +72,55 @@ class ReadJSShifts(plugin.InputPreparationPlugin, TimeSupportMixin): ...@@ -48,21 +72,55 @@ class ReadJSShifts(plugin.InputPreparationPlugin, TimeSupportMixin):
if endTime == '': if endTime == '':
endTime = "18:00" endTime = "18:00"
shiftEnd = self.convertToSimulationTime(strptime("%s %s" % (line[1], endTime), '%Y/%m/%d %H:%M')) shiftEnd = self.convertToSimulationTime(strptime("%s %s" % (line[1], endTime), '%Y/%m/%d %H:%M'))
timePair = self.correctTimePair(shiftStart, shiftEnd)
if not timePair:
continue
else:
shiftStart, shiftEnd = timePair
timeStartList.append(shiftStart)
timeEndList.append(shiftEnd)
if line[-1]:
offshifts = line[-1].replace(" ", "").split(";")
for offshift in offshifts:
limits = offshift.split("-")
breakStart = self.convertToSimulationTime(strptime("%s %s" % (line[1], limits[0]), '%Y/%m/%d %H:%M'))
breakEnd = self.convertToSimulationTime(strptime("%s %s" % (line[1], limits[1]), '%Y/%m/%d %H:%M'))
timePair = self.correctTimePair(breakStart, breakEnd)
if not timePair:
continue
else:
breakStart, breakEnd = timePair
timeStartList.append(breakEnd)
timeEndList.insert(0, breakStart)
#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
entityID = line[0].split("-")[0] entityID = line[0].split("-")[0]
if str(entityID) == '': if str(entityID) == '':
#take it as a continuation for the last entered resource #take it as a continuation for the last entered resource
shiftPattern[lastrec].append([shiftStart,shiftEnd]) for index, start in enumerate(timeStartList):
end = timeEndList[index]
if not start and not end:
continue
shiftPattern[lastrec].append([start, end])
#if resource name is defined #if resource name is defined
elif str(entityID) not in shiftPattern: elif str(entityID) not in shiftPattern:
#take the name of the last entered resource from here #take the name of the last entered resource from here
lastrec = str(entityID) lastrec = str(entityID)
shiftPattern[str(entityID)] = [[shiftStart,shiftEnd]] for index, start in enumerate(timeStartList):
end = timeEndList[index]
if not start and not end:
continue
shiftPattern[lastrec] = [[start, end]]
#to avoid overwriting existing records, if there is another entry for a resource but does not follow it immediately (e.g. W2-FS) #to avoid overwriting existing records, if there is another entry for a resource but does not follow it immediately (e.g. W2-FS)
else: else:
lastrec = str(entityID) lastrec = str(entityID)
#extend the previous entry for the resource #extend the previous entry for the resource
shiftPattern[str(entityID)].append([shiftStart,shiftEnd]) for index, start in enumerate(timeStartList):
end = timeEndList[index]
if not start and not end:
continue
shiftPattern[lastrec].append([start, end])
#sorts the list in case the records were not entered in correct ascending order #sorts the list in case the records were not entered in correct ascending order
for info in shiftPattern: for info in shiftPattern:
......
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