Esempio n. 1
0
def print_requests_by_status(requests: list, title: str) -> None:
    if len(requests) > 0:
        print_header('REQUESTS ' + title)
        for request in requests:
            request_id = request['id']
            description = request['description']
            weight = request['weight']

            print_sub_header('Request', request_id)
            print('Description: ' + description + '\n')
            print('Weight: ' + str(weight) + '\n')
Esempio n. 2
0
def print_missions_by_status(missions: list, title: str) -> None:
    if len(missions) > 0:
        print_header('MISSIONS ' + title)
        for mission in missions:
            mission_id = mission['id']
            rocket_id = mission['rocketId']
            days_to_arrive_at_station = mission['daysToArriveAtStation']

            print_sub_header('Mission', mission_id)
            print('Rocket id: ' + rocket_id + '\n')
            print('Days to arrive at station: ' +
                  str(days_to_arrive_at_station) + '\n')
Esempio n. 3
0
def menu_save_file():
    from app import save_file

    is_valid = False
    print_header("Save a JSON file")

    while not is_valid:
        try:
            file_name = validate_file_name()
            message = save_file(file_name)
            print_success(message)
            is_valid = True
        except OSError as error:
            print_error(str(error))
Esempio n. 4
0
def menu_add_new_rocket() -> None:
    from app import add_new_rocket
    is_valid = False

    print_header("Add new rocket")
    while not is_valid:
        try:
            # The user introduce the data
            rocket_id = input("rocket id: ")
            rocket_payload = validate_integer("rocket payload")

            # Add the new rocket
            add_new_rocket(rocket_id, rocket_payload)
            is_valid = True
        except ValueError as error:
            print_error(str(error))
Esempio n. 5
0
def menu_assign_requests_missions() -> None:
    from app import assign_requests_missions, validate_assignment_process

    exists_enough_data = validate_assignment_process()

    if exists_enough_data:
        print_header("Assignments")
        try:
            message = assign_requests_missions()
            print_success(message)
        except ValueError as error:
            print_error(str(error))
    else:
        print_error("Should exist at least one rocket,"
                    " one request, and one mission for init"
                    " the assignment process")
Esempio n. 6
0
def menu_add_new_mission() -> None:
    from app import add_new_mission
    is_valid = False

    print_header("Add new mission")
    while not is_valid:
        try:
            # The user introduce the data
            mission_id = input("mission id: ")
            rocket_id = input("rocket id: ")
            mission_days_max = validate_integer("mission days to arrive at station")

            # Add the new mission
            add_new_mission(mission_id, rocket_id, mission_days_max)
            is_valid = True
        except ValueError as error:
            print_error(str(error))
Esempio n. 7
0
def menu_add_new_request() -> None:
    from app import add_new_request
    is_valid = False

    print_header("Add new request")
    while not is_valid:
        try:
            # The user introduce the data
            request_id = input("request id: ")
            request_description = input("request description: ")
            request_weight = validate_float("request weight")
            request_days_max = validate_integer("request days max to deliver ")

            # Add the new request
            add_new_request(request_id, request_description, request_weight, request_days_max)
            is_valid = True
        except ValueError as error:
            print_error(str(error))
Esempio n. 8
0
def print_rockets() -> None:
    from app import get_rockets

    rockets = get_rockets()

    if len(rockets) > 0:
        print_header('ROCKETS')
        for rockets in rockets:
            rocket_id = rockets['id']
            payload = rockets['payload']
            success = rockets['success']

            print_sub_header('Rocket', rocket_id)
            print('Payload: ' + str(payload) + '\n')

            if success:
                print_success('Yes')
    else:
        print_warning('There are no rockets in the system')
Esempio n. 9
0
def print_assignments() -> None:
    from app import get_assignments

    assignments = get_assignments()

    if len(assignments) > 0:
        print_header('ASSIGNMENTS')
        for assignment in assignments:
            mission_id = assignment['missionId']
            days_to_arrive_at_station = assignment['daysToArriveAtStation']
            payload = assignment['payload']
            request_ids = assignment['requestIds']

            print_sub_header('Assignment')
            print('Mission id: ' + mission_id + '\n')
            print('Days to arrive at station: ' +
                  str(days_to_arrive_at_station) + '\n')
            print('Payload: ' + str(payload) + '\n')
            print('Request ids: ' + ' '.join(map(str, request_ids)) + '\n')
    else:
        print_warning('There are no assignments in the system')
Esempio n. 10
0
def menu_simulate_by_days() -> None:
    from app import simulate_by_days, get_assignments

    exists_assignments = len(get_assignments()) > 0

    if exists_assignments:
        is_valid = False
        print_header("Simulation")
        while not is_valid:
            try:
                # The user introduce the data
                days = validate_integer("days")

                # Process the simulation
                simulate_by_days(days)

                is_valid = True
            except ValueError as error:
                print('Error: ', str(error))
    else:
        print_error("Should exist at least one assignment")