Example #1
0
    def show_available_staff(form_data):
        """ Returns list of staff not flying on departure date."""

        dep_str = form_data["instance"].get_attributes()["departure"][0:10]
        departure_list = Read.departures_on_date(dep_str)

        flightID_list = []
        for departure in departure_list:
            flightID_list.append(departure.get_attributes()["flightID"])

        busy_ssn_list = []
        for flightID in flightID_list:
            crew_list = Read.flight_crew(flightID)

            for crew_row in crew_list:
                busy_ssn_list.append(crew_row.get_attributes()["ssn"])

        all_staff = Read.read_staff("valid", "True")
        data = []
        for employee in all_staff:
            if employee.get_attributes()["ssn"] not in busy_ssn_list:
                data.append(employee)

        form_data["data"] = data
        form_data["page_size"] = 7
        form_data["rtrip"] = False
        return form_data
Example #2
0
    def filter_busy_staff(display_data, busy=False):

        # If no date set, use today as starting point
        if display_data["datetime"] == "":
            today = dt.datetime.today()
            display_data["datetime"] = dt.datetime(today.year, today.month,
                                                   today.day)

        else:
            if display_data["action"] == "next_date":
                display_data["datetime"] = display_data[
                    "datetime"] + dt.timedelta(days=1)
                display_data["action"] = ""

            elif display_data["action"] == "prev_date":
                display_data["datetime"] = display_data[
                    "datetime"] - dt.timedelta(days=1)
                display_data["action"] = ""

        if busy:
            display_data["destinations"] = {}

        departure_list = Read.departures_on_date(
            display_data["datetime"].isoformat()[0:10])
        ssn_list = []
        for departure in departure_list:
            crew_list = Read.flight_crew(
                departure.get_attributes()["flightID"])

            for crew in crew_list:
                ssn_list.append(crew.get_attributes()["ssn"])

                if busy:
                    key = crew.get_attributes()["ssn"]
                    display_data["destinations"][key] = departure

        read_data = Read.read_staff("valid", "True")
        data = []
        if not busy:

            for employee in read_data:

                if employee.get_attributes()["ssn"] not in ssn_list:
                    data.append(employee)

        else:
            for employee in read_data:

                if employee.get_attributes()["ssn"] in ssn_list:
                    data.append(employee)

        return display_data, data
Example #3
0
    def create_schedule(display_data):
        """
		Creates one week from last monday, finds flights in week
		Returns list of flights if an employees ssn is found to match in Crew csv.
		"""

        display_data["data"] = []
        if "week" in display_data:
            last_monday = dt.datetime.today().date(
            ) + display_data["week"] * dt.timedelta(days=7)
        else:
            last_monday = dt.datetime.today().date()
            display_data["week"] = 0

        while last_monday.weekday() != 0:
            last_monday = last_monday - dt.timedelta(days=1)
        current_week = []
        week_day = last_monday

        # Get YYYY-MM-DD strings for each day in week, starting on last monday
        for _ in range(7):
            current_week.append(week_day.isoformat()[0:10])
            week_day = week_day + dt.timedelta(days=1)

        # Find flights on each day in given week, add to week_flights list
        week_flights = []
        for date in current_week:
            departures = Read.departures_on_date(date)
            week_flights.append(departures)

        # If employee's ssn matches one found in crew for a departure, add departure and returning flight to employee's schedule
        staff_schedule = []
        for departure_list in week_flights:
            for departure in departure_list:
                crew_row_list = Read.flight_crew(
                    departure.get_attributes()["flightID"])

                for crew_row in crew_row_list:
                    ssn = crew_row.get_attributes()["ssn"]

                    if ssn == display_data["instance"].get_attributes()["ssn"]:
                        returnflight = BLLayer.create_returnflight(
                            departure, instant_write=False, make_serial=False)
                        rtrip = RTrip(departure, returnflight)
                        staff_schedule.append(rtrip)

        display_data["data"] = staff_schedule
        display_data["datetime"] = last_monday
        display_data["week_end"] = week_day - dt.timedelta(days=1)
        return display_data
Example #4
0
    def create_rtrip_list(attribute_dict_list):
        """
		Creates list of flights for Pager, marks departing flight as manned or unmanned and returns list.
		"""
        rtrip_list = []
        count = 0
        for attribute_dict in attribute_dict_list:

            if attribute_dict["direction"] == "outbound":
                departure = Departure(attribute_dict, from_csv=True)

                manned_status = False
                head_pilot = False
                assistant_pilot = False
                head_steward = False

                crew = Read.flight_crew(attribute_dict["flightID"])

                for member in crew:

                    rank = member.get_rank()
                    if rank == "Yfirflugmaður":
                        head_pilot = True
                    elif rank == "Aðstoðarflugmaður":
                        assistant_pilot = True
                    elif rank == "Yfirflugþjónn":
                        head_steward = True

                    manned_status = head_pilot and assistant_pilot and head_steward
                    if manned_status:
                        break

                departure.set_manned(manned_status)
                count += 1
            elif attribute_dict["direction"] == "inbound":
                returnflight = ReturnFlight(attribute_dict)
                count += 1

            # Collects two rows, creates Departure and ReturnFlight instances in order
            # Creates RTrip instance containing the two connected instances
            if count == 2:
                rtrip = RTrip(departure, returnflight)
                count = 0
                rtrip_list.append(rtrip)

        return rtrip_list
Example #5
0
    def update_crew(departure, employee_list):
        crew_list = BLLayer.create_crew_members(departure,
                                                employee_list,
                                                instant_write=False)

        # ** Remove selected employees from other flights on same day **

        dep_str = departure.get_attributes()["departure"][0:10]

        # Get flights on same day
        departures_on_date = Read.departures_on_date(dep_str)

        # Get ssns for all busy employees on given date and corresponding flightID
        busy_ssn_list = []
        for departure in departures_on_date:

            flightID = departure.get_attributes()["flightID"]
            crew = Read.flight_crew(flightID)

            for member in crew:
                busy_ssn_list.append(member.get_attributes()["ssn"])
                busy_ssn_list.append(member.get_attributes()["flightID"])

        # Get employees which have been selected to man current departure and are also assigned another flight on same day
        busy_employees = []
        for employee in employee_list:
            ssn = employee.get_attributes()["ssn"]

            if ssn in busy_ssn_list:
                flightID = busy_ssn_list[busy_ssn_list.index(ssn) + 1]

                employee_id_tuple = (employee, flightID)

                busy_employees.append(employee_id_tuple)

        # Function changes old flight assignment validity to False
        bool1 = DBLayer.invalidate_crew_members(busy_employees)

        # Replace crew for the current departure instance
        bool2 = Update.replace_crew(departure, crew_list)
        finished = bool1 and bool2

        return finished