Пример #1
0
    def __get_voyage_list(search, search_filter):
        all_voyage_list = IO_API.get_data("voyage")
        old_voyages = Voyage_LL.voyages_status_checker(all_voyage_list)
        all_voyage_list = [
            voyage for voyage in all_voyage_list if voyage not in old_voyages
        ]
        IO_API.write_data("voyage", all_voyage_list)
        # Search filter
        if search != None:
            search_filtered_voyage_list = []
            for voyage in all_voyage_list:
                if search.lower() in Voyage_LL.get_list_info(voyage).lower():
                    search_filtered_voyage_list += [voyage]
        else:
            search_filtered_voyage_list = all_voyage_list

        # search_filter can be ["all", "not_finished", "finished", "manned", "unmanned"]
        if search_filter == "all":
            search_filter_filtered_voyage_list = search_filtered_voyage_list + Old_Voyage_LL.get_old_voyages_list(
                search)
        elif search_filter == "not finished":
            search_filter_filtered_voyage_list = search_filtered_voyage_list
        elif search_filter == "finished":
            search_filter_filtered_voyage_list = Old_Voyage_LL.get_old_voyages_list(
                search)
        else:
            search_filter_filtered_voyage_list = []
            for voyage in search_filtered_voyage_list:
                ##print(voyage.get_crew_status(), search_filter)
                if voyage.get_crew_status() == search_filter:
                    search_filter_filtered_voyage_list += [voyage]

        return search_filter_filtered_voyage_list
Пример #2
0
    def store_aircraft(new_aircraft_data):
        '''Stores a new aircraft.'''
        new_aircraft = Aircraft(new_aircraft_data[0], new_aircraft_data[1],
                                new_aircraft_data[2], new_aircraft_data[3],
                                Aircraft_LL.get_new_aircraft_id())

        IO_API.append_data("aircraft", [new_aircraft])
Пример #3
0
    def change_voyage(voyage_ID, new_info):
        full_voyage_list = IO_API.get_data("voyage")

        for voyage in full_voyage_list:
            if voyage.get_id() == voyage_ID:
                voyage.set_info(new_info)
                break

        IO_API.write_data("voyage", full_voyage_list)
Пример #4
0
    def change_employee(employee_ID, new_employee_info):
        '''Stores the changes of an employee.'''
        all_employees = IO_API.get_data("employee")

        for employee in all_employees:
            if employee.get_id() == employee_ID:
                employee.set_info(new_employee_info)

        IO_API.write_data("employee", all_employees)
Пример #5
0
    def store_new_voyage(destination_id, departure_time):

        flight_number_1,\
        flight_number_2 = Voyage_LL.__get_voyage_flight_numbers(destination_id,
                                                            departure_time)
        new_voyage = Voyage(None, destination_id, str(departure_time),
                            flight_number_1, flight_number_2, [], False,
                            Voyage_LL.get_new_voyage_id())
        IO_API.append_data("voyage", [new_voyage])
Пример #6
0
    def change_destination(destination_ID, new_destination_info):
        '''Stores the changes of a destination.'''
        
        all_destinations = IO_API.get_data("destination")

        for destination in all_destinations:
            if destination.get_id() == destination_ID:
                destination.set_info(new_destination_info)

        IO_API.write_data("destination", all_destinations)
Пример #7
0
    def store_employee(employee_info):
        new_employee = Employee(employee_info[0],
                                employee_info[1],
                                employee_info[2],
                                employee_info[3],
                                employee_info[4],
                                employee_info[5],
                                employee_info[6])
        '''Stores a new employee.'''

        IO_API.append_data("employee", [new_employee])
Пример #8
0
    def __get_employee_list(search, filter, time):
        '''Private method which gets the employee list according to the filter and search.'''


        employee_list = IO_API.get_data("employee")

        # Checks the filter
        filtered_employee_list = []
        if filter == "pilot" or filter == "cabin_crew":
            for employee in employee_list:
                if employee.get_job() == filter:
                    filtered_employee_list += [employee]

        elif filter == "all":
            filtered_employee_list = employee_list

        else:
            all_voyages = IO_API.get_data("voyage")
            same_day_voyages = []
            for voyage in all_voyages:
                for work_day in Voyage_LL.get_voyage_working_days(voyage):
                    if work_day.year == time.year and work_day.month == time.month and work_day.day == time.day:
                        same_day_voyages += [voyage]

            if filter == "working":
                filtered_employee_list = []
                for voyage in same_day_voyages:
                    for ssn in voyage.get_employee_ids():
                        filtered_employee_list += [Voyage_LL.get_employee_by_id(ssn)]

            elif filter == "not_working":
                working = []
                for voyage in same_day_voyages:
                    for ssn in voyage.get_employee_ids():
                        working += [Voyage_LL.get_employee_by_id(ssn)]


                filtered_employee_list = list(set(employee_list)-set(working))


        employee_list = filtered_employee_list
        # Checks the search
        if search != None:
            search_filtered_employee_list = []
            for employee in employee_list:
                if search.lower() in Employee_LL.get_list_info(employee).lower():
                    search_filtered_employee_list.append(employee)
        else:
            search_filtered_employee_list = employee_list

        return search_filtered_employee_list
Пример #9
0
    def store_destination(destination_info):
        '''Stores a new destination.'''


        new_destination = Destination(destination_info[1],
                                      destination_info[2],
                                      destination_info[3],
                                      destination_info[4],
                                      destination_info[5],
                                      destination_info[6],
                                      Destination_LL.get_new_destination_id(),
                                      destination_info[0]
                                      )

        IO_API.append_data("destination", [new_destination])
Пример #10
0
 def get_new_aircraft_id():
     aircraft_list = IO_API.get_data("aircraft")
     max_id = 0
     for aircraft in aircraft_list:
         if aircraft.get_id() > max_id:
             max_id = aircraft.get_id()
     return max_id + 1
Пример #11
0
    def get_voyages_time(search, list_filter, time_filter):
        voyages = IO_API.get_data("voyage")
        search_filtered_voyage_list = []
        if search is not None:
            for v in voyages:
                if search in LL_API.get_list_info(v):
                    search_filtered_voyage_list += [v]
        else:
            search_filtered_voyage_list = voyages

        search_filter = list_filter
        if search_filter == "all":
            search_filter_filtered_voyage_list = search_filtered_voyage_list + Old_Voyage_LL.get_old_voyages_list(
                search)
        elif search_filter == "not finished":
            search_filter_filtered_voyage_list = search_filtered_voyage_list
        elif search_filter == "finished":
            search_filter_filtered_voyage_list = Old_Voyage_LL.get_old_voyages_list(
                search)
        else:
            search_filter_filtered_voyage_list = []

        time_filtered_voyage_list = []
        if time_filter is not None:
            for voyage in search_filter_filtered_voyage_list:
                if time_filter[0] <= voyage.get_departure_time(
                ) <= time_filter[1]:
                    time_filtered_voyage_list += [voyage]
        else:
            time_filtered_voyage_list = search_filter_filtered_voyage_list

        return time_filtered_voyage_list
Пример #12
0
 def get_new_destination_id():
     destination_list = IO_API.get_data("destination")
     max_id = 0
     for destination in destination_list:
         if destination.get_id() > max_id:
             max_id = destination.get_id()
     return max_id + 1
Пример #13
0
    def get_available_employees(time):
        all_voyages = IO_API.get_data("voyage")
        same_day_voyages = []
        for voyage in all_voyages:
            for work_day in Voyage_LL.get_voyage_working_days(voyage):
                if work_day.year == time.year and work_day.month == time.month and work_day.day == time.day:
                    same_day_voyages += [voyage]

        available_employee_list = IO_API.get_data("employee")
        for voyage in same_day_voyages:
            for ssn in voyage.get_employee_ids():
                for employee in available_employee_list:
                    if employee.get_id() == ssn:
                        available_employee_list.remove(employee)

        return available_employee_list
Пример #14
0
 def get_new_id(old_voyage):
     old_voyages_list = IO_API.get_data("old_voyage")
     max_id = 0
     for old in old_voyages_list:
         if old.get_id() > max_id:
             max_id = old.get_id()
     return max_id + 1
Пример #15
0
 def get_new_voyage_id():
     all_voyages = IO_API.get_data("voyage")
     max_id = 0
     for voyage in all_voyages:
         if max_id < voyage.get_id():
             max_id = voyage.get_id()
     return max_id + 1
Пример #16
0
    def get_voyages(aircraft_id):
        """ Takes in an aircraft id and returns a list of all the future voyages the aircraft is assigned to """

        voyages_list = IO_API.get_data("voyage")
        aircraft_voyages_list = []
        for voyage in voyages_list:
            if voyage.aircraft_id == aircraft_id:
                aircraft_voyages_list.append(voyage)
        return aircraft_voyages_list
Пример #17
0
    def get_working_employees(time):
        all_voyages = IO_API.get_data("voyage")
        same_day_voyages = []
        for voyage in all_voyages:
            for work_day in Voyage_LL.get_voyage_working_days(voyage):
                if work_day.year == time.year and work_day.month == time.month and work_day.day == time.day:
                    same_day_voyages += [voyage]

        working_employee_list = []
        for voyage in same_day_voyages:
            for ssn in voyage.get_employee_ids():
                working_employee_list += [Voyage_LL.get_employee_by_id(ssn)]
        return working_employee_list
Пример #18
0
    def __get_destination_list(search):
        '''Private method which gets the destination list according to the filter and search.'''

        destination_list = IO_API.get_data("destination")
        search_filtered_destination_list = []
        if search != None:
            for destination in destination_list:
                if search.lower() in Destination_LL.get_list_info(destination).lower():
                    search_filtered_destination_list += [destination]
        else:
            search_filtered_destination_list = destination_list

        return search_filtered_destination_list
Пример #19
0
    def __get_voyage_flight_numbers(destination_id, departure_time):
        all_voyages = IO_API.get_data("voyage")
        departure_day = datetime.datetime(departure_time.year,
                                          departure_time.month,
                                          departure_time.day)
        number_of_voyages_with_same_departure_day_and_destination = 0
        for voyage in all_voyages:
            if Voyage_LL.__get_departure_day_of_voyage(voyage) == departure_day \
                    and voyage.get_destination_id() == destination_id:
                number_of_voyages_with_same_departure_day_and_destination += 1

        destination_id_str = str(destination_id)
        if len(destination_id_str) == 1:
            destination_id_str = "0" + destination_id_str

        return "NA{}{}".format(destination_id_str, number_of_voyages_with_same_departure_day_and_destination * 2), \
               "NA{}{}".format(destination_id_str, number_of_voyages_with_same_departure_day_and_destination * 2 + 1)
Пример #20
0
    def get_old_voyages_list(search):
        """ Gets a list of voyages from file and returns it. Applies search or search filter if they are not None """
        all_old_voyages_list = IO_API.get_data("old_voyage")

        # Search
        if search != None:
            search_filtered_old_voyages_list = []
            for old_voyage in all_old_voyages_list:
                if search.lower() in Old_Voyage_LL.get_list_info(
                        old_voyage).lower(
                        ):  # Check if search is in voyage string
                    search_filtered_old_voyages_list.append(old_voyage)
        # If no search is applied
        else:
            search_filtered_old_voyages_list = all_old_voyages_list

        return search_filtered_old_voyages_list
Пример #21
0
    def get_work_week(item, time):
        work_week_days = []
        for i in range(7):
            work_week_days += [time + datetime.timedelta(i)]
        voyages = IO_API.get_data("voyage")

        info_list = []
        for voyage in voyages:
            for workday in Voyage_LL.get_voyage_working_days(voyage):
                for i in range(len(work_week_days)):
                    if workday == work_week_days[i]:
                        if item.get_id() in voyage.get_employee_ids():
                            destination = Voyage_LL.get_destination_by_id(
                                voyage.get_destination_id())
                            work_week_days[i] = (workday, destination)

        for i in range(len(work_week_days)):
            if not isinstance(work_week_days[i], datetime.datetime):
                work_week_days[i] = (work_week_days[i][0],
                                     work_week_days[i][1].get_country())
            else:
                work_week_days[i] = (work_week_days[i], None)
        return work_week_days
Пример #22
0
    def __get_aircraft_list(search, pilot):
        '''Private method which gets the aircraft list according to the filter and search.'''

        aircraft_list = IO_API.get_data("aircraft")

        # Checks the filter (pilot)
        if pilot != None:
            for aircraft in aircraft_list:
                if pilot[5:] != aircraft.get_model():
                    aircraft_list.remove(aircraft)

        # Checks the search

        search_filtered_aircraft_list = []
        if search != None:
            for aircraft in aircraft_list:
                if search.lower() in Aircraft_LL.get_list_info(
                        aircraft).lower():
                    search_filtered_aircraft_list += [aircraft]
        else:
            search_filtered_aircraft_list = aircraft_list

        return search_filtered_aircraft_list
Пример #23
0
 def store_old_voyage(old_voyage):
     """ Take in an a Old Voyage object, gives it a new id and writes it to file """
     old_voyage.set_id(Old_Voyage_LL.get_new_id(old_voyage))
     IO_API.append_data("old_voyage", [old_voyage])
Пример #24
0
 def append_aircraft_list(aircraft_list):
     IO_API.append_data(Aircraft_LL.AIRCRAFT_ID, aircraft_list)
Пример #25
0
 def get_available_aircraft(time):
     aircraft = IO_API.get_data("aircraft")
     return aircraft
Пример #26
0
 def get_available_destinations():
     all_destinations = IO_API.get_data("destination")
     return all_destinations
Пример #27
0
 def get_destination_by_id(destination_id):
     all_destinations = IO_API.get_data("destination")
     for destination in all_destinations:
         if destination.get_id() == destination_id:
             return destination
     return "ERROR NO DESTINATION WITH THAT ID"
Пример #28
0
 def get_voyages_on_day(day):
     voyages = IO_API.get_data("voyage")
     for voyage in voyages:
         pass
Пример #29
0
 def get_employee_by_id(employee_id):
     all_employees = IO_API.get_data("employee")
     for employee in all_employees:
         if employee.get_id() == employee_id:
             return employee
     return "ERROR NO EMPLOYEE WITH THAT ID"
Пример #30
0
 def get_aircraft_by_id(aircraft_id):
     all_aircraft = IO_API.get_data("aircraft")
     for aircraft in all_aircraft:
         if aircraft.get_id() == aircraft_id:
             return aircraft
     return "ERROR NO AIRCRAFT WITH THAT ID"