Exemplo n.º 1
0
class AirplaneLL(LogicLayer):
    def __init__(self):
        self.IOAPI = IOAPI()
        super().__init__()

    def get_input_type(self, field_index):
        if field_index in [0, 1, 2]:
            return str
        if field_index == 3:
            return int

    def is_valid_input(self, field_index, new_input):
        if field_index == 0:
            return self.is_only_letters(new_input) and new_input != ""

        elif field_index == 3:
            return new_input.isdigit()

        else:
            return True

    def get_input_specifacation(self, field_index):
        if field_index == 0:
            return "insert the name of the airplane"
        elif field_index == 1:
            return "insert the name of the airplane's manufacturer"
        elif field_index == 2:
            return "insert the type of the airplane"
        elif field_index == 3:
            return "insert the amount of seats in the airplane"

    def get_schedule(self, airplane):
        schedule = []
        for voyage in self.IOAPI.get_voyages():
            if voyage.airplane == airplane.get_id():
                schedule.append((self.str_to_datetime(voyage.departure_time),
                                 self.str_to_datetime(voyage.return_time)))
        return schedule

    def get_all(self):
        return self.IOAPI.get_airplanes()

    def add(self, airplane):
        self.IOAPI.add_airplane(airplane)

    # TODO: make this work and consolidate the get_manufacturer function above
    def set_sorting_method(self, sorting_method):
        self.load_asset_list()
        if sorting_method == AirplaneSortingMethods.ALL_AIRPLANES:
            self.asset_list.sort(key=lambda plane: plane.get_id())
        elif sorting_method == AirplaneSortingMethods.ONLY_IN_USE:
            self.asset_list = list(
                filter(lambda plane: self.in_use(plane), self.asset_list))
        elif sorting_method == AirplaneSortingMethods.ONLY_NOT_IN_USE:
            self.asset_list = list(
                filter(lambda plane: not self.in_use(plane), self.asset_list))
        elif sorting_method == AirplaneSortingMethods.BY_NAME:
            self.asset_list.sort(key=lambda plane: plane.name.lower())
        elif sorting_method == AirplaneSortingMethods.BY_MANUFACTURER:
            self.asset_list.sort(key=lambda plane: plane.manufacturer.lower())
Exemplo n.º 2
0
 def __init__(self):
     self.IOAPI = IOAPI()
     super().__init__()
Exemplo n.º 3
0
class EmployeeLL(LogicLayer):
    def __init__(self):
        self.IOAPI = IOAPI()
        super().__init__()

    def get_pilots(self):
        return self.IOAPI.get_pilots()

    def is_pilot(self, employee):
        return employee.job_type == "Captain" or employee.job_type == "Co Pilot"

    def get_attendants(self):
        return self.IOAPI.get_attendants()

    def get_all(self):
        return self.IOAPI.get_employees()

    def get_by_id(self, item_id):
        return self.IOAPI.get_employee_by_id(item_id)

    def add(self, employee):
        self.IOAPI.add_employee(employee)

    def is_unique_ssn(self, new_ssn):
        employee_list = self.get_all()

        try:
            self.IOAPI.employee.employees[new_ssn]
            return False
        except KeyError:
            return True

    def show_busy_destination(self, departure_str, arrival_str):
        busy_destination = self.get_is_busy_and_free(self.get_all(),
                                                     departure_str,
                                                     arrival_str)[0]

        return_list = []

        for employee in busy_destination:
            return_list.append(str(employee[0]) + " " + str(employee[1].abrev))

        return return_list

    def check_time_table(self, time_table, departure_time, arrival_time):
        DEPARTURE = 0
        ARRIVAL = 1

        if len(time_table) == 0:
            return True
        if time_table[0][DEPARTURE] > arrival_time:
            return True
        if time_table[-1][ARRIVAL] < departure_time:
            return True
        for i in range(len(time_table)):
            if time_table[i + 1][DEPARTURE] > arrival_time:
                if time_table[i][
                        ARRIVAL] < departure_time + datetime.timedelta(day=1):
                    return True
                else:
                    return False

    def is_valid_input(self, field_index, new_input):
        if field_index == 0:
            return self.is_only_letters(new_input) and new_input != ""
        elif field_index == 1:
            return new_input.isdigit() and self.is_unique_ssn(
                new_input) and new_input != ""
        elif field_index in [3, 4]:
            return self.is_only_digits(new_input)
        else:
            return True

    def get_input_type(self, field_index):
        return str

    def get_input_specification(self, field_index):
        if field_index == 0:
            return "insert the name of the new employee"
        elif field_index == 1:
            return "insert the social security number of the new employee"
        elif field_index == 2:
            return "insert the address of the new employee"
        elif field_index == 2:
            return "insert the home phone of the new employee"
        elif field_index == 3:
            return "insert the mobile phone of the new employee"
        elif field_index == 4:
            return "insert the email address of the new employee"
        elif field_index == 5:
            return "insert the plane type the employee is allowed to operate(leave empty if attendant)"
        elif field_index == 6:
            return "insert the title of the new employee's position"

    def set_sorting_method(self, sorting_method):
        self.load_asset_list()
        if sorting_method == EmployeeSortingMethods.ALL_EMPLOYEES:
            self.asset_list.sort(key=lambda e: e.name)
        elif sorting_method == EmployeeSortingMethods.PILOTS:
            self.asset_list = list(
                filter(lambda employee: employee.is_pilot(), self.asset_list))
        elif sorting_method == EmployeeSortingMethods.ATTENDANTS:
            self.asset_list = list(
                filter(lambda employee: employee.is_attendant(),
                       self.asset_list))
        elif sorting_method == EmployeeSortingMethods.IS_WORKING:
            self.asset_list = list(
                filter(lambda employee: self.in_use(employee),
                       self.asset_list))
        elif sorting_method == EmployeeSortingMethods.IS_AVAILABLE:
            self.asset_list = list(
                filter(lambda employee: not self.in_use(employee),
                       self.asset_list))

    def get_week_schedule(self, asset, week_start, week_end):
        schedule = []
        for voyage in asset.time_table:
            voyage = self.IOAPI.get_voyage_by_id(voyage)
            if voyage.departure_time > week_start and voyage.return_time < week_end:
                schedule.append(voyage)
        return voyage

    def get_pilots_ordered_by_plane_type(self):
        total = []
        for plane_type in self.IOAPI.employee.plane_types.values():
            for pilot in plane_type:
                total.append(self.get_by_id(pilot))
        return total
Exemplo n.º 4
0
 def __init__(self):
     self.ioAPI = IOAPI()
     self.destLL = DestinationLL(self.ioAPI)
     self.staffLL = StaffMemberLL(self.ioAPI)
     self.voyageLL = VoyageLL(self.ioAPI)
     self.airplaneLL = AirplaneLL(self.ioAPI)
Exemplo n.º 5
0
class DestinationLL(LogicLayer):
    def __init__(self):
        self.IOAPI = IOAPI()
        super().__init__()

    def get_all(self):
        destination_list = self.IOAPI.get_destinations()
        return sorted(destination_list, key=lambda k: k.country)

    def add(self, destination):
        self.IOAPI.add_destination(destination)

    def save(self):
        self.IOAPI.save_destinations()

    def is_unique_abreviation(self, new_abreviation):
        destination_list = self.get_all()
        for destination in destination_list:
            if destination.abrev == new_abreviation:
                return False
        return True

    def get_input_specifacation(self, field_index):
        if field_index == 0:
            return "insert name of the new destination's country"
        elif field_index == 1:
            return "insert the name of the new destination's airport"
        elif field_index == 2:
            return "insert the abreviation for your airport"
        elif field_index == 3:
            return "insert the time it takes to fly to the new destination"
        elif field_index == 4:
            return "insert the distance from Iceland"
        elif field_index == 5:
            return "insert the name of the new destination's contanct"
        elif field_index == 6:
            return "insert the phone number of the new destination's contanct"

    def get_input_type(self, field_index):
        return str

    def is_valid_input(self, field_index, new_input):
        if field_index == 0:  # Country
            return self.is_only_letters(new_input) and new_input != ""
        elif field_index == 1:  # Airport
            return self.is_only_letters(new_input) and new_input != ""
        elif field_index == 2:  # Airport Abbreviation
            return self.is_unique_abreviation(new_input) and new_input != ""
        elif field_index == 3:  # Time
            return self.is_time_format(new_input) and new_input != ""
        elif field_index == 4:  # Distance
            return new_input.isdigit() and new_input != ""
        elif field_index == 5:  # Contact name
            return self.is_only_letters(new_input)
        elif field_index == 6:  # Contact number
            return self.is_only_digits(new_input)
        else:
            return True

    def set_sorting_method(self, sorting_method):
        if sorting_method == DestinationSortingMethods.BY_COUNTRY:
            self.asset_list.sort(key=lambda destination: destination.country)
        elif sorting_method == DestinationSortingMethods.BY_FLIGHT_TIME:
            self.asset_list.sort(
                key=lambda destination: destination.flight_time)
        elif sorting_method == DestinationSortingMethods.BY_FLIGHT_DISTANCE:
            self.asset_list.sort(
                key=lambda destination: destination.flight_dist)