Commit dca04b5e authored by Georgios Dagkakis's avatar Georgios Dagkakis

cleanup, duplicate code moved in separate method

parent 9515ab9e
...@@ -206,22 +206,8 @@ class CapacityStationController(EventGenerator): ...@@ -206,22 +206,8 @@ class CapacityStationController(EventGenerator):
# loop through the entities # loop through the entities
for entity in entitiesInBuffer: for entity in entitiesInBuffer:
if self.checkIfProjectCanStartInStation(entity.capacityProject, station): if self.checkIfProjectCanStartInStation(entity.capacityProject, station):
# calculate what is the capacity that should proceed and what that should remain self.breakEntity(entity, buffer, station, totalAvailableCapacity, totalRequestedCapacity)
capacityToMove=totalAvailableCapacity*(entity.requiredCapacity)/float(totalRequestedCapacity)
capacityToStay=entity.requiredCapacity-capacityToMove
# remove the capacity entity by the buffer so that the broken ones are created
buffer.getActiveObjectQueue().remove(entity)
entityToMoveName=entity.capacityProjectId+'_'+station.objName+'_'+str(capacityToMove)
entityToMove=CapacityEntity(name=entityToMoveName, capacityProjectId=entity.capacityProjectId, requiredCapacity=capacityToMove)
entityToMove.initialize()
entityToMove.currentStation=buffer
entityToMove.shouldMove=True
entityToStayName=entity.capacityProjectId+'_'+station.objName+'_'+str(capacityToStay)
entityToStay=CapacityEntity(name=entityToStayName, capacityProjectId=entity.capacityProjectId, requiredCapacity=capacityToStay)
entityToStay.initialize()
entityToStay.currentStation=buffer
import Globals
Globals.setWIP([entityToMove,entityToStay]) #set the new components as wip
# if the buffer is assembly there are different calculations # if the buffer is assembly there are different calculations
else: else:
# calculate the total capacity that is requested # calculate the total capacity that is requested
...@@ -245,22 +231,26 @@ class CapacityStationController(EventGenerator): ...@@ -245,22 +231,26 @@ class CapacityStationController(EventGenerator):
# break only the assembled projects # break only the assembled projects
if self.checkIfProjectAssembledInBuffer(entity.capacityProject, buffer) and\ if self.checkIfProjectAssembledInBuffer(entity.capacityProject, buffer) and\
self.checkIfProjectCanStartInStation(entity.capacityProject, station): self.checkIfProjectCanStartInStation(entity.capacityProject, station):
# calculate what is the capacity that should proceed and what that should remain self.breakEntity(entity, buffer, station, totalAvailableCapacity, totalRequestedCapacity)
capacityToMove=totalAvailableCapacity*(entity.requiredCapacity)/float(totalRequestedCapacity)
capacityToStay=entity.requiredCapacity-capacityToMove # breaks an entity in the part that should move and the one that should stay
# remove the capacity entity by the buffer so that the broken ones are created def breakEntity(self, entity, buffer, station, totalAvailableCapacity, totalRequestedCapacity):
buffer.getActiveObjectQueue().remove(entity) # calculate what is the capacity that should proceed and what that should remain
entityToMoveName=entity.capacityProjectId+'_'+station.objName+'_'+str(capacityToMove) capacityToMove=totalAvailableCapacity*(entity.requiredCapacity)/float(totalRequestedCapacity)
entityToMove=CapacityEntity(name=entityToMoveName, capacityProjectId=entity.capacityProjectId, requiredCapacity=capacityToMove) capacityToStay=entity.requiredCapacity-capacityToMove
entityToMove.initialize() # remove the capacity entity by the buffer so that the broken ones are created
entityToMove.currentStation=buffer buffer.getActiveObjectQueue().remove(entity)
entityToMove.shouldMove=True entityToMoveName=entity.capacityProjectId+'_'+station.objName+'_'+str(capacityToMove)
entityToStayName=entity.capacityProjectId+'_'+station.objName+'_'+str(capacityToStay) entityToMove=CapacityEntity(name=entityToMoveName, capacityProjectId=entity.capacityProjectId, requiredCapacity=capacityToMove)
entityToStay=CapacityEntity(name=entityToStayName, capacityProjectId=entity.capacityProjectId, requiredCapacity=capacityToStay) entityToMove.initialize()
entityToStay.initialize() entityToMove.currentStation=buffer
entityToStay.currentStation=buffer entityToMove.shouldMove=True
import Globals entityToStayName=entity.capacityProjectId+'_'+station.objName+'_'+str(capacityToStay)
Globals.setWIP([entityToMove,entityToStay]) #set the new components as wip entityToStay=CapacityEntity(name=entityToStayName, capacityProjectId=entity.capacityProjectId, requiredCapacity=capacityToStay)
entityToStay.initialize()
entityToStay.currentStation=buffer
import Globals
Globals.setWIP([entityToMove,entityToStay]) #set the new components as wip
# merges the capacity entities if they belong to the same project # merges the capacity entities if they belong to the same project
def mergeEntities(self): def mergeEntities(self):
......
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