Advertisement
Guest User

quickpaste

a guest
May 5th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. 'Imports'
  2.  
  3. import csv
  4. import os
  5. import sys
  6.  
  7.  
  8. 'Constants'
  9.  
  10. # Seating Sections
  11. PRIORITY = 'Priority'
  12. LIMITED_VIEW = 'Limited View'
  13. SCREEN_ONLY = 'Screen Only'
  14.  
  15. # Locations Listing
  16. LOCATIONS = { PRIORITY, LIMITED_VIEW, SCREEN_ONLY }
  17.  
  18. # The number of just-in-case seats reserved in each section.
  19. RESERVED = {
  20. PRIORITY: 0,
  21. LIMITED_VIEW: 50,
  22. SCREEN_ONLY: 0
  23. }
  24.  
  25. # The total number of seats that can be allocated in each section.
  26. AVAILABLE = {
  27. PRIORITY: 7000 - RESERVED[PRIORITY],
  28. LIMITED_VIEW: 1800 - RESERVED[LIMITED_VIEW],
  29. SCREEN_ONLY: 5000 - RESERVED[SCREEN_ONLY]
  30. }
  31.  
  32. # The number of seats guaranteed to each person in priority seating.
  33. GUARANTEED_PRIORITY = 5
  34.  
  35.  
  36. 'Classes'
  37.  
  38. class SeatAllocation(object):
  39. '''
  40. This class holds data on a number of allocated seats, and the location
  41. where they are allocated.
  42. '''
  43.  
  44. def __init__(self, seats, location):
  45. '''
  46. Initializes a seat allocation with a seat count, and the location of
  47. the seats.
  48. @param seats The number of seats being allocated.
  49. @param location The location where the seats are allocated.
  50. '''
  51. assert isinstance(seats, int), 'expected @seats to be an int'
  52. assert seats > 0, 'expected @seats to be at least 1'
  53. assert isinstance(location, str), 'expected @location to be a str'
  54. assert location in LOCATIONS, 'unknown location: {}'.format(location)
  55. if location == PRIORITY and seats > GUARANTEED_PRIORITY:
  56. raise Exception('cannot allocate more than {} seats to {} '
  57. ' section.'.format(GUARANTEED_PRIORITY, PRIORITY))
  58. self.seats = seats
  59. self.location = location
  60.  
  61.  
  62. class SeatRequest(object):
  63. '''
  64. This class represents a request for seating, and the seats that are
  65. allocated to fulfill the request.
  66. '''
  67.  
  68. def __init__(self, studentID, regular, extra):
  69. '''
  70. Initializes a seat request with the number of seats being requested.
  71. @param studentID The ID of the student making the request.
  72. @param regular The number of regular seats requested.
  73. @param extra The number of extra seats requested.
  74. '''
  75. assert isinstance(studentID, int), 'expected @studentID to be an int'
  76. assert isinstance(regular, int), 'expected @regular to be an int'
  77. assert 1 <= regular <= GUARANTEED_PRIORITY, 'expected @regular to be '
  78. 'between 1 and {} inclusive'.format(GUARANTEED_PRIORITY)
  79. assert isinstance(extra, int), 'expected @extra to be an int'
  80. self.studentID = studentID
  81. self.regular = regular
  82. self.extra = extra
  83. self.allocations = []
  84.  
  85. def allocate(self, allocation):
  86. '''
  87. Adds a seat allocation to the request.
  88. @param allocation The allocation being added.
  89. '''
  90. assert isinstance(allocation, SeatAllocation), 'expected @allocation '
  91. 'to be a SeatAllocation'
  92. self.allocations.append(allocation)
  93.  
  94.  
  95. 'Runtime'
  96.  
  97. if __name__ == '__main__':
  98.  
  99. # Extract input arguments.
  100. if len(sys.argv) != 3:
  101. print('Usage: python3 <input file> <output file>')
  102. exit()
  103. inputFile = os.path.abspath(sys.argv[1])
  104. outputfile = os.path.abspath(sys.argv[2])
  105.  
  106. # Check that the input file exists.
  107. if not os.path.exists(inputFile):
  108. raise Exception('file not found: {}'.format(inputFile))
  109.  
  110. # Read the CSV into a list of seat requests.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement