[docs]
class AssignmentFinder:
[docs]
@classmethod
def next_assignment(cls, vessel, acquisition):
'''
Gets the next activities to assign using '_pop_next_activities', passing it the given acquisition and vessel
Creates the model using '_model_for_vessel', passing it the given source and receiver models, and the given vessel
Gets the upcoming activities using '_read_next_activities', passing it the given acquisition, vessel and vessel number
If there are activities to assign, it assigns work using '_assign_work',
passing it the activities to assign, the model and the given vessel
If the waiting point for the vessel was reached, it assigns transit or wait using '_assign_transit_or_wait',
passing it the upcoming activities, the model and the given vessel
Else (no activities to assign, not in waiting point) it sets the vessel to wait with 'make_waiting'
'''
activities_to_assign = cls._pop_next_activities(acquisition, vessel)
upcoming_activities = cls._read_next_activities(acquisition, vessel)
if activities_to_assign:
cls._assign_work(vessel, activities_to_assign)
elif cls._waiting_point_reached_for_vessel(acquisition, vessel):
cls._assign_transit_or_wait(vessel, upcoming_activities)
else:
vessel.make_waiting()
@classmethod
def _pop_next_activities(cls, acquisition, vessel):
'''
Gets the count of target lines as the 'lines_count_in_standard_work_task' from the given vessel
If the given vessel is a source vessel:
- Gets the next source activities using 'pop_next_source_activities' from acquisition.py, passing it the count of target lines
If the given vessel is a receiver vessel:
- Gets the next receiver activities using 'pop_next_receiver_activities' from acquisition.py, passing it the count of target lines
If the given vessel is not source nor receiver, it raises 'Unknown vessel type'
Returns the next activities
'''
target_lines_count = vessel.lines_count_in_standard_work_task()
if vessel.category == 'source':
next_activities = acquisition.pop_next_source_activities(target_lines_count)
elif vessel.category == 'receiver':
next_activities = acquisition.pop_next_receiver_activities(target_lines_count)
else:
raise Exception('Unknown vessel type') # pragma: no cover
return next_activities
@classmethod
def _read_next_activities(cls, acquisition, vessel):
'''
Gets the count of lines worked on as the 'lines_count_in_standard_work_task' from the given vessel
If the given vessel is a source vessel:
- Gets the next source activities using 'read_next_source_activities' from acquisition.py,
passing it the count of lines worked on and the given vessel number
If the given vessel is a receiver vessel:
- Gets the next receiver activities using 'read_next_receiver_activities' from acquisition.py,
passing it the count of lines worked on and the given vessel number
If the given vessel is not source nor receiver, it raises 'Unknown vessel type'
Returns the next activities
'''
lines_worked_on = vessel.lines_count_in_standard_work_task()
if vessel.category == 'source':
next_activities = acquisition.read_next_source_activities(lines_worked_on, vessel)
elif vessel.category == 'receiver':
next_activities = acquisition.read_next_receiver_activities(lines_worked_on, vessel)
else:
raise Exception('Unknown vessel type') # pragma: no cover
return next_activities
@classmethod
def _waiting_point_reached_for_vessel(cls, acquisition, vessel):
'''
If the given vessel is a source vessel:
- Gets the waiting point reached using 'source_waiting_point_reached' from acquisition.py
If the given vessel is a receiver vessel:
- Gets the waiting point reached using 'receiver_waiting_point_reached' from acquisition.py
If the given vessel is not source nor receiver, it raises 'Unknown vessel type'
Returns the waiting point reached
'''
if vessel.category == 'source':
waiting_point_reached = acquisition.source_waiting_point_reached()
elif vessel.category == 'receiver':
waiting_point_reached = acquisition.receiver_waiting_point_reached()
else:
raise Exception('Unknown vessel type') # pragma: no cover
return waiting_point_reached
@classmethod
def _assign_transit_or_wait(cls, vessel, activities):
'''
Gets the next sail line using 'create_sail_line_for_activities' from operational_model.py, passing it the given activities
Gets the transit operations using 'create_transit_to_sail_line_start' from operational_model.py,
passing it the the last position and time of the given vessel, and the next sail line
If there are no transit operations, it sets the vessel to wait with 'make_waiting'
If there are transit operations, it sets the vessel to busy with 'make_busy' and,
for each transit operation, it schedules the work of the vessel for that operation with 'schedule_work'
'''
next_sail_line = vessel.model.create_sail_line_for_activities(activities)
transit_operations = vessel.model.create_transit_to_sail_line_start(vessel.last_position(), next_sail_line)
if transit_operations is None or vessel.category == 'source':
vessel.make_waiting()
else:
vessel.make_busy()
for op in transit_operations:
vessel.schedule_work(op)
@classmethod
def _assign_work(cls, vessel, activities):
'''
Sets the vessel to busy with 'make_busy'
Converts the given activities of the vessel using 'convert_to_operations' from operational_model.py
For each operation, it schedules the work of the vessel with 'schedule_work'
'''
vessel.make_busy()
operations = vessel.model.convert_to_operations(vessel, activities)
for op in operations:
vessel.schedule_work(op)