예제 #1
0
class PlaneLL():
    def __init__(self, ioAPI_in):
        self.__ioAPI_in = ioAPI_in
        self.voyLL = VoyageLL(ioAPI_in)

    def createPlane(self, plane):
        return self.__ioAPI_in.storePlaneToFile(plane)

    def getPlanes(self):
        return self.__ioAPI_in.loadPlanesFromFile()

    def getPlaneType_list(self):
        return self.__ioAPI_in.loadPlaneTypesFromFile()

    def getPlaneType(self, registration):
        plane_list = self.__ioAPI_in.loadPlanesFromFile()
        for plane in plane_list:
            if plane['planeInsignia'] == registration:
                return plane['planeTypeId']

    def getAvailablePlanes(self, departureDateTime, totalTime):
        arrivalDateTime = departureDateTime + totalTime
        plane_list = self.getPlanes(
        )  # Starting with all planes available -> unavailable will be removed
        voyage_list = self.__ioAPI_in.loadVoyagesFromFile()
        available_planes_list = []
        voyages_on_same_time_list = []
        for voyage in voyage_list:
            voyage_departure = datetime.datetime.strptime(
                voyage['Departure'], '%Y-%m-%dT%H:%M:%S')
            voyage_arrival = datetime.datetime.strptime(
                voyage['Arrival'], '%Y-%m-%dT%H:%M:%S')
            if (departureDateTime <= voyage_departure <= arrivalDateTime)\
                or (departureDateTime <= voyage_arrival <= arrivalDateTime):
                voyages_on_same_time_list.append(voyage)
        unavailable_planes = []
        for voyage in voyages_on_same_time_list:
            unavailable_planes.append(voyage['Aircraft'])

        for plane in plane_list:
            if plane['planeInsignia'] not in unavailable_planes:
                available_planes_list.append(plane)

        return available_planes_list

    def getPlaneStatus(self, dateTime):
        planesWorking_list, planesNotWorking_list = self.getPlanesWorking(
            dateTime)
        working_odict = collections.OrderedDict()
        planesNotInAir = []
        allPlanes_status = []
        for plane in planesNotWorking_list:
            working_odict = collections.OrderedDict()
            working_odict['Aircraft ID'] = plane['planeInsignia']
            working_odict['Plane Type'] = plane['planeTypeId']
            working_odict['Current Flight Number'] = 'Not in flight'
            working_odict['Destination'] = 'N/A'
            planesNotInAir.append(working_odict)
        self.getPlaneInfo(planesNotInAir)
        planesInAir = self.getPlaneWorkingState(dateTime, planesWorking_list)
        for plane in planesInAir:
            allPlanes_status.append(plane)
        for plane in planesNotInAir:
            allPlanes_status.append(plane)
        return allPlanes_status

    def getPlaneWorkingState(self, dateTime, planesWorking_list):
        planesInAir = []
        working_odict = collections.OrderedDict()
        flightsOnDay = self.getFlightsOnDay(dateTime)
        for plane in planesWorking_list:
            for flight in flightsOnDay:
                flightDeparture = datetime.datetime.strptime(
                    flight['departure'], "%Y-%m-%dT%H:%M:%S")
                flightArrival = datetime.datetime.strptime(
                    flight['arrival'], "%Y-%m-%dT%H:%M:%S")
                if flight['aircraftID'] == plane['planeInsignia'] and \
                    flightDeparture <= dateTime <= flightArrival:
                    working_odict = collections.OrderedDict()
                    working_odict['Aircraft ID'] = plane['planeInsignia']
                    working_odict['Plane Type'] = plane['planeTypeId']
                    working_odict['Current Flight Number'] = flight[
                        'flightNumber']
                    working_odict['Destination'] = flight['arrivingAt']
                    planesInAir.append(working_odict)
        self.getPlaneInfo(planesInAir)
        return planesInAir

    def getPlaneInfo(self, planesInAir):
        planeTypes = self.__ioAPI_in.loadPlaneTypesFromFile()
        for plane in planesInAir:
            for planeType in planeTypes:
                if plane['Plane Type'] == planeType['planeTypeId']:
                    plane['Seats'] = planeType['capacity']

    def getFlightsOnDay(self, dateTime):
        allFlights = self.__ioAPI_in.loadRoutesFromFile()
        flightsOnDay = []
        for flight in allFlights:
            if flight['departure'][:10] == str(dateTime.date()):
                flightsOnDay.append(flight)
        return flightsOnDay

    def getPlanesWorking(self, dateTime):
        self.voyageOnDay_list = self.voyLL.getVoyagesDay(dateTime)
        plane_list = self.__ioAPI_in.loadPlanesFromFile()
        planesNotWorking_list = []
        planesWorking_list = []
        for plane in plane_list:
            for voyage in self.voyageOnDay_list:
                voy_departure = datetime.datetime.strptime(
                    voyage['Departure'], "%Y-%m-%dT%H:%M:%S")
                voy_arrival = datetime.datetime.strptime(
                    voyage['Arrival'], "%Y-%m-%dT%H:%M:%S")
                if plane['planeInsignia'] == voyage[
                        'Aircraft'] and voy_departure <= dateTime <= voy_arrival:
                    planesWorking_list.append(plane)
                else:
                    planesNotWorking_list.append(plane)
        return planesWorking_list, planesNotWorking_list
예제 #2
0
class LLAPI():
    def __init__(self):
        self.__ioAPI = IOAPI()
        self.destLL = DestinationLL(self.__ioAPI)
        self.voyLL = VoyageLL(self.__ioAPI)
        self.plaLL = PlaneLL(self.__ioAPI)
        self.empLL = EmployeeLL(self.__ioAPI)

    def getDestinationHeader(self, list_of_destination):
        return self.destLL.getDestinationHeader(list_of_destination)

    def getDestinationValue(self, list_of_destination):
        return self.destLL.getDestinationValue(list_of_destination)

    def getDestinations(self):
        return self.destLL.getDestination()

    def createDestination(self, dest):
        return self.destLL.storeDestinationToFile(dest)

    def getDestinationsContactInfo(self):
        return self.destLL.getDestinationsContactInfo()

    def updateContactInfo(self, line_index, row_index, updated_info):
        return self.destLL.updateContactInfo(line_index, row_index,
                                             updated_info)

    def createVoyage(self, voyage):
        return self.voyLL.createVoyage(voyage)

    def getVoyages(self):
        return self.voyLL.getVoyages()

    def getFullyStaffedVoyages(self):
        return self.voyLL.getFullyStaffedVoyages()

    def getVoyagesWeek(self, first_day_of_week):
        return self.voyLL.getVoyagesWeek(first_day_of_week)

    def getVoyagesDay(self, date):
        return self.voyLL.getVoyagesDay(date)

    def getVoyageHeader(self, voyage_list):
        return self.voyLL.getVoyageHeader(voyage_list)

    def getVoyageValue(self, voyage_list):
        return self.voyLL.getVoyageValue(voyage_list)

    def createPlane(self, plane):
        return self.plaLL.createPlane(plane)

    def getPlanes(self):
        return self.plaLL.getPlanes()

    def getPlaneType(self, registration):
        return self.plaLL.getPlaneType(registration)

    def getPlaneType_list(self):
        return self.plaLL.getPlaneType_list()

    def getAvailablePlanes(self, date, totalTime):
        return self.plaLL.getAvailablePlanes(date, totalTime)

    def createEmployee(self, employee):
        return self.empLL.createEmployee(employee)

    def getEmployees(self):
        return self.empLL.getEmployees()

    def updateEmployee(self, line_index, row_index, updated_info):
        return self.empLL.updateEmployee(line_index, row_index, updated_info)

    def getEmployeeHeader(self, employee_list):
        return self.empLL.getEmployeeHeader(employee_list)

    def getEmployeeValue(self, employee_list):
        return self.empLL.getEmployeeValue(employee_list)

    def getPilotsOrFAs(self, empType):
        return self.empLL.getPilotsOrFAs(empType)

    def getSpecificEmployee(self, emp_id=''):
        return self.empLL.getSpecificEmployee(emp_id)

    def getAvailabilityOfPilots(self, date, listType):
        return self.empLL.getAvailabiltyOfPilots(date, listType)

    def getAvailabiltyOfFAs(self, date, listType):
        return self.empLL.getAvailabiltyOfFAs(date, listType)

    def getAvailabilityOfAll(self, date, listType):
        return self.empLL.getAvailabilityOfAll(date, listType)

    def getChosenEmployee(self, id_list, emp_id):
        return self.empLL.getChosenEmployee(id_list, emp_id)

    def getUnmannedVoyages(self):
        return self.voyLL.getUnmannedVoyages()

    def availablePilotsWithSpecificLicense(self, time, aircraftType):
        return self.empLL.availablePilotsWithSpecificLicense(
            time, aircraftType)

    def storeCrewToFile(self, voyage):
        self.voyLL.storeCrewToFile(voyage)

    def getPlaneStatus(self, dateTime):
        return self.plaLL.getPlaneStatus(dateTime)

    def createDestinationObject(self, destination_str):
        return self.destLL.createDestinationObject(destination_str)

    def checkDateTime(self, dateTime):
        return self.voyLL.checkDateTime(dateTime)