Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Imports'
- import csv
- import os
- import sys
- 'Constants'
- # Seating Sections
- PRIORITY = 'Priority'
- LIMITED_VIEW = 'Limited View'
- SCREEN_ONLY = 'Screen Only'
- # Locations Listing
- LOCATIONS = { PRIORITY, LIMITED_VIEW, SCREEN_ONLY }
- # The number of just-in-case seats reserved in each section.
- RESERVED = {
- PRIORITY: 0,
- LIMITED_VIEW: 50,
- SCREEN_ONLY: 0
- }
- # The total number of seats that can be allocated in each section.
- AVAILABLE = {
- PRIORITY: 7000 - RESERVED[PRIORITY],
- LIMITED_VIEW: 1800 - RESERVED[LIMITED_VIEW],
- SCREEN_ONLY: 5000 - RESERVED[SCREEN_ONLY]
- }
- # The number of seats guaranteed to each person in priority seating.
- GUARANTEED_PRIORITY = 5
- 'Classes'
- class SeatAllocation(object):
- '''
- This class holds data on a number of allocated seats, and the location
- where they are allocated.
- '''
- def __init__(self, seats, location):
- '''
- Initializes a seat allocation with a seat count, and the location of
- the seats.
- @param seats The number of seats being allocated.
- @param location The location where the seats are allocated.
- '''
- assert isinstance(seats, int), 'expected @seats to be an int'
- assert seats > 0, 'expected @seats to be at least 1'
- assert isinstance(location, str), 'expected @location to be a str'
- assert location in LOCATIONS, 'unknown location: {}'.format(location)
- if location == PRIORITY and seats > GUARANTEED_PRIORITY:
- raise Exception('cannot allocate more than {} seats to {} '
- ' section.'.format(GUARANTEED_PRIORITY, PRIORITY))
- self.seats = seats
- self.location = location
- class SeatRequest(object):
- '''
- This class represents a request for seating, and the seats that are
- allocated to fulfill the request.
- '''
- def __init__(self, studentID, regular, extra):
- '''
- Initializes a seat request with the number of seats being requested.
- @param studentID The ID of the student making the request.
- @param regular The number of regular seats requested.
- @param extra The number of extra seats requested.
- '''
- assert isinstance(studentID, int), 'expected @studentID to be an int'
- assert isinstance(regular, int), 'expected @regular to be an int'
- assert 1 <= regular <= GUARANTEED_PRIORITY, 'expected @regular to be '
- 'between 1 and {} inclusive'.format(GUARANTEED_PRIORITY)
- assert isinstance(extra, int), 'expected @extra to be an int'
- self.studentID = studentID
- self.regular = regular
- self.extra = extra
- self.allocations = []
- def allocate(self, allocation):
- '''
- Adds a seat allocation to the request.
- @param allocation The allocation being added.
- '''
- assert isinstance(allocation, SeatAllocation), 'expected @allocation '
- 'to be a SeatAllocation'
- self.allocations.append(allocation)
- 'Runtime'
- if __name__ == '__main__':
- # Extract input arguments.
- if len(sys.argv) != 3:
- print('Usage: python3 <input file> <output file>')
- exit()
- inputFile = os.path.abspath(sys.argv[1])
- outputfile = os.path.abspath(sys.argv[2])
- # Check that the input file exists.
- if not os.path.exists(inputFile):
- raise Exception('file not found: {}'.format(inputFile))
- # Read the CSV into a list of seat requests.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement