Example #1
0
    def initialize():
        all_voyages = VoyageLogic.get_all_voyages()

        current_date_and_time = datetime.datetime.now()

        for voyage in all_voyages:
            previous_state_of_voyage = voyage.get_state()

            airplane = voyage.get_airplane()

            employees_in_voyage = voyage.get_pilots() + voyage.get_flight_attendants()

            StateLogic.__update_state_of_voyage(voyage, current_date_and_time)

            state_of_voyage = voyage.get_state()

            if airplane:
                #Update the airplanes state
                StateLogic.__update_state_of_entity(airplane, state_of_voyage)

            #Update the states of all the employees
            for employee in employees_in_voyage:
                StateLogic.__update_state_of_entity(employee, state_of_voyage)


            if previous_state_of_voyage != state_of_voyage:
                DataAPI.change_saved_voyage(voyage, voyage)
                DataAPI.change_saved_airplane(airplane, airplane)
 
                __pilot_count = len(voyage.get_pilots())
                for i, employee in enumerate(employees_in_voyage):
                    if i < __pilot_count:
                        DataAPI.change_saved_pilot(employee,employee)
                    else:
                        DataAPI.change_saved_flight_attendant(employee,employee)
    def is_flight_attendant_ssn_avaliable(flight_attendant_ssn):
        all_flight_attendants = DataAPI.get_all_flight_attendants()
        for flight_attendant in all_flight_attendants:
            if flight_attendant.get_ssn() == flight_attendant_ssn:
                return 

        return True
    def is_airplane_name_available(plane_name):
        all_airplanes = DataAPI.get_all_airplanes()
        for airplane in all_airplanes:
            if airplane.get_name() == plane_name:
                return False

        return True
Example #4
0
 def get_licensed_pilots(pilot_license):
     all_pilots = DataAPI.get_all_pilots()
     licensed_pilots = []
     for pilot in all_pilots:
         if pilot.get_license() == pilot_license:
             licensed_pilots.append(pilot)
     return PilotLogic.__sort_list_by_name(licensed_pilots)
Example #5
0
    def get_employee_by_ssn(ssn):
        all_employees = DataAPI.get_all_employees()

        for employee in all_employees:
            if employee.get_ssn() == ssn:
                return [employee]

        return []
    def get_all_available_airplanes(schedule_tuple):  # needs testing
        available_airplanes = set()
        for airplane in DataAPI.get_all_airplanes():
            airplanes_voyages = DataAPI.get_airplane_voyages(airplane)

            # if there are no voyages for a specific airplane then it is available
            if not airplanes_voyages:
                available_airplanes.add(airplane)

            else:
                for voyage in airplanes_voyages:
                    voyage_schedule = voyage.get_schedule()
                    if schedule_tuple[0] > voyage_schedule[
                            1] or schedule_tuple[1] < voyage_schedule[0]:
                        available_airplanes.add(airplane)

        return AirplaneLogic.__sort_list_by_name(list(available_airplanes))
Example #7
0
    def get_voyages_by_date(date):  #needs testing
        all_voyages = DataAPI.get_all_voyages()
        desired_voyages = []

        for voyage in all_voyages:
            if voyage.get_schedule()[0].date() == date:
                desired_voyages.append(voyage)

        return desired_voyages
Example #8
0
    def get_available_flight_number(airport_id,
                                    departure_date_and_time,
                                    offset=0):
        all_flights = DataAPI.get_all_flights()

        highest_flight_number = 0

        for flight in all_flights:
            f_dep_time = flight.get_departure_time()
            if f_dep_time.date == departure_date_and_time.date:
                f_num = flight.get_number()
                if f_num > highest_flight_number:
                    highest_flight_number = f_num
                if f_dep_time > departure_date_and_time:
                    DataAPI.change_saved_flight(flight, Flight(flight.get_departure_location, f_dep_time,\
                         flight.get_arrival_location(), flight.get_arrival_time(), f_num[:-1] + str(int(f_num[-1]) + 2)))

        return "NA" + str(airport_id) + str(highest_flight_number + 1 + offset)
Example #9
0
    def get_employees_off_duty():
        all_employees = DataAPI.get_all_employees()
        not_scheduled_state = State.get_employee_states()[0]
        employees_off_duty = []
        for employee in all_employees:
            if employee.get_state() == not_scheduled_state:
                employees_off_duty.append(employee)

        return EmployeeLogic.__sort_list_by_name(employees_off_duty)
Example #10
0
    def get_airplane_voyages(airplane):  #needs testing
        all_voyages = DataAPI.get_all_voyages()
        airplane_voyages = []

        for voyage in all_voyages:
            if voyage.get_airplane() == airplane:
                airplane_voyages.append(voyage)

        return airplane_voyages
Example #11
0
    def get_voyages_by_destination(destination):  #needs testing
        all_voyages = DataAPI.get_all_voyages()
        desired_voyages = []

        for voyage in all_voyages:
            if destination in voyage.get_flights()[0].get_arrival_location():
                desired_voyages.append(voyage)

        return desired_voyages
Example #12
0
    def get_ongoing_voyages():  #needs testing
        all_voyages = DataAPI.get_all_voyages()
        ongoing_voyages = []
        completed_state = State.get_voyage_states()[4]

        for voyage in all_voyages:
            if voyage.get_state() != completed_state:
                ongoing_voyages.append(voyage)

        return ongoing_voyages
Example #13
0
    def get_all_pilot_voyages(pilot):
        all_voyages = DataAPI.get_all_voyages()

        pilot_voyages_list = []

        for voyage in all_voyages:
            if pilot in voyage.get_pilots():
                pilot_voyages_list.append(voyage)

        return pilot_voyages_list
Example #14
0
    def get_employee_by_name(name):
        all_employees = DataAPI.get_all_employees()

        employees_with_name = []

        for employee in all_employees:
            if name in employee.get_name():
                employees_with_name.append(employee)

        return employees_with_name
    def get_all_flight_attendant_voyages(flight_attendant):
        all_voyages = DataAPI.get_all_voyages()

        flight_attendant_voyages_list = []

        for voyage in all_voyages:
            if flight_attendant in voyage.get_flight_attendants():
                flight_attendant_voyages_list.append(voyage)

        return flight_attendant_voyages_list
Example #16
0
    def get_completed_voyages():  #needs testing
        all_voyages = DataAPI.get_all_voyages()
        completed_voyages = []
        completed_state = State.get_voyage_states()[4]

        for voyage in all_voyages:
            if voyage.get_state() == completed_state:
                completed_voyages.append(voyage)

        return completed_voyages
    def get_flight_attendant(ssn):
        '''Returns a flight_attendant with the given ssn,
           if no flight_attendant has the given ssn None is returned'''

        all_flight_attendants = DataAPI.get_all_flight_attendants()

        for flight_attendant in all_flight_attendants:
            if flight_attendant.get_ssn() == ssn:
                return flight_attendant

        return None
Example #18
0
    def get_pilot(ssn):
        '''Returns a pilot with the given ssn,
           if no pilot has the given ssn None is returned'''

        all_pilots = DataAPI.get_all_pilots()

        for pilot in all_pilots:
            if pilot.get_ssn() == ssn:
                return pilot

        return None
Example #19
0
    def get_voyages_by_week(week):  #needs testing
        all_voyages = DataAPI.get_all_voyages()
        desired_voyages = []

        for voyage in all_voyages:

            #Get which week in the year each voyage is scheduled
            voyage_week_in_year_int = voyage.get_schedule()[0].date(
            ).isocalendar()[1]
            if voyage_week_in_year_int == week:
                desired_voyages.append(voyage)

        return desired_voyages
    def get_available_flight_attendants(schedule_tuple):
        all_flight_attendants = DataAPI.get_all_flight_attendants()

        available_flight_attendants = set()

        for flight_attendant in all_flight_attendants:
            voyages = FlightAttendantLogic.get_all_flight_attendant_voyages(flight_attendant)

            if not voyages:
                available_flight_attendants.add(flight_attendant)
            else:

                for voyage in voyages:
                    voyage_schedule = voyage.get_schedule()
                    if schedule_tuple[0] > voyage_schedule[1] or schedule_tuple[1] < voyage_schedule[0]:
                        available_flight_attendants.add(flight_attendant)

        return FlightAttendantLogic.__sort_list_by_name(list(available_flight_attendants))
Example #21
0
    def get_available_pilots(schedule_tuple):
        all_pilots = DataAPI.get_all_pilots()

        available_pilots = set()

        for pilot in all_pilots:
            voyages = PilotLogic.get_all_pilot_voyages(pilot)

            if not voyages:
                available_pilots.add(pilot)
            else:

                for voyage in voyages:
                    voyage_schedule = voyage.get_schedule()
                    if schedule_tuple[0] > voyage_schedule[
                            1] or schedule_tuple[1] < voyage_schedule[0]:
                        available_pilots.add(pilot)

        return PilotLogic.__sort_list_by_name(list(available_pilots))
Example #22
0
 def change_saved_pilot(saved_pilot, changed_pilot):
     DataAPI.change_saved_pilot(saved_pilot, changed_pilot)
 def get_airplane(name):
     return DataAPI.get_airplane(name)
 def get_all_airplanes_in_use():  #needs testing
     return AirplaneLogic.__sort_list_by_name(
         DataAPI.get_all_airplanes_in_use())
 def change_saved_airplane(saved_airplane, changed_airplane):
     DataAPI.change_saved_airplane(saved_airplane, changed_airplane)
 def save_new_airplane(airplane):
     DataAPI.save_new_airplane(airplane)
 def change_saved_flight_attendant(saved_flight_attendant, changed_flight_attendant):
     DataAPI.change_saved_flight_attendant(saved_flight_attendant, changed_flight_attendant)
 def save_new_flight_attendant(flight_attendant):
     DataAPI.save_new_flight_attendant(flight_attendant)
 def get_all_flight_attendants():
     return FlightAttendantLogic.__sort_list_by_name(DataAPI.get_all_flight_attendants())
Example #30
0
 def save_new_pilot(pilot):
     DataAPI.save_new_pilot(pilot)