Advertisement
Guest User

Untitled

a guest
May 29th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. from exceptions import InvalidJobError
  2.  
  3. class Job:
  4.  
  5. existing_jobs = set()
  6.  
  7. def __init__(self, location=None, start_time=None, end_time=None,
  8. name=None, capacity_demand=0, capacity_dimension=0,
  9. service_time=0, skill_requirements=()):
  10.  
  11. # Validate inputs
  12. if not any([location, start_time, end_time]):
  13. raise InvalidJobError("All jobs must have a location, a start "
  14. "time and and end time.")
  15.  
  16. try:
  17. self.start_time = int(start_time)
  18. self.end_time = int(end_time)
  19. except (ValueError, TypeError):
  20. raise InvalidJobError("Could not discern time slot for job "
  21. "at location: {}".format(location))
  22.  
  23. if self.start_time > self.end_time:
  24. raise InvalidJobError("Start time greater than end time for: "
  25. "{}".format(location))
  26.  
  27. self.location = location
  28. self.name = name if name else self.location
  29.  
  30. if self.name in Job.existing_jobs:
  31. raise InvalidJobError("Jobs with duplicate locations must be given"
  32. " unique names. Location: {}".format(location)
  33. )
  34.  
  35. self.capacity_demand = int(capacity_demand)
  36. self.capacity_dimension = int(capacity_dimension)
  37. self.service_time = int(service_time)
  38. if not skill_requirements:
  39. self.skill_requirements = {-1}
  40. else:
  41. try:
  42. self.skill_requirements = set(skill_requirements)
  43. except TypeError:
  44. raise InvalidJobError("Skill requirements must be a sequence, "
  45. "location: {}".format(self.location))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement