class Main:
    # Main UI when the program starts up
    print('Package Tracking System')
    print('Route was completed in', "{0:.2f}".format(total_distance(), 2),
          'miles.')
    start = input("Type 'package' to look up by package number,or  "
                  "type 'time' to see all package status' at a given time: ")
    # Space-time complexity is O(N)
    while start != 'exit':

        # If user enters 'time' it shows all packages at a certain time frame and the status of packages
        if start == 'time':
            try:
                package_status_time = input(
                    'Please enter a time in the HH:MM:SS format: ')
                (h, m, s) = package_status_time.split(':')
                convert_user_time = datetime.timedelta(hours=int(h),
                                                       minutes=int(m),
                                                       seconds=int(s))
                # Space-time complexity is O(N^2)
                for count in range(1, 41):
                    try:
                        first_time = get_hash_map().get(str(count))[9]
                        second_time = get_hash_map().get(str(count))[10]
                        (h, m, s) = first_time.split(':')
                        convert_first_time = datetime.timedelta(hours=int(h),
                                                                minutes=int(m),
                                                                seconds=int(s))
                        (h, m, s) = second_time.split(':')
                        convert_second_time = datetime.timedelta(
                            hours=int(h), minutes=int(m), seconds=int(s))
                    except ValueError:
                        pass
                    # First checks all packages against the given time determine if they have left the hub yet.
                    if convert_first_time >= convert_user_time:
                        get_hash_map().get(str(count))[10] = 'At Hub'
                        get_hash_map().get(
                            str(count))[9] = 'Leaves at ' + first_time
                        print('Package ID:',
                              get_hash_map().get(str(count))[0],
                              '   Street address:',
                              get_hash_map().get(str(count))[2],
                              get_hash_map().get(str(count))[3],
                              get_hash_map().get(str(count))[4],
                              get_hash_map().get(str(count))[5],
                              '  Required delivery time:',
                              get_hash_map().get(str(count))[6],
                              ' Package weight:',
                              get_hash_map().get(str(count))[7],
                              '  Truck status:',
                              get_hash_map().get(str(count))[9],
                              '  Delivery status:',
                              get_hash_map().get(str(count))[10])
                    elif convert_first_time <= convert_user_time:
                        # Then checks to see which packages have left the hub but have not been delivered yet
                        if convert_user_time < convert_second_time:
                            get_hash_map().get(str(count))[10] = 'In transit'
                            get_hash_map().get(
                                str(count))[9] = 'Left at ' + first_time
                            print('Package ID:',
                                  get_hash_map().get(str(count))[0],
                                  '   Street address:',
                                  get_hash_map().get(str(count))[2],
                                  get_hash_map().get(str(count))[3],
                                  get_hash_map().get(str(count))[4],
                                  get_hash_map().get(str(count))[5],
                                  '  Required delivery time:',
                                  get_hash_map().get(str(count))[6],
                                  ' Package weight:',
                                  get_hash_map().get(str(count))[7],
                                  '  Truck status:',
                                  get_hash_map().get(str(count))[9],
                                  '  Delivery status:',
                                  get_hash_map().get(str(count))[10])
                        # Finally checks all packages that have already been delivered and displays the delivered time
                        else:
                            get_hash_map().get(
                                str(count))[10] = 'Delivered at ' + second_time
                            get_hash_map().get(
                                str(count))[9] = 'Left at ' + first_time
                            print('Package ID:',
                                  get_hash_map().get(str(count))[0],
                                  '   Street address:',
                                  get_hash_map().get(str(count))[2],
                                  get_hash_map().get(str(count))[3],
                                  get_hash_map().get(str(count))[4],
                                  get_hash_map().get(str(count))[5],
                                  '  Required delivery time:',
                                  get_hash_map().get(str(count))[6],
                                  ' Package weight:',
                                  get_hash_map().get(str(count))[7],
                                  '  Truck status:',
                                  get_hash_map().get(str(count))[9],
                                  '  Delivery status:',
                                  get_hash_map().get(str(count))[10])
            except IndexError:
                print(IndexError)
                exit()
            except ValueError:
                print('Invalid entry!')
                exit()
        # If user enters 'package' user is able to check specific package at a specific time
        elif start == 'package':
            try:
                count = input('Please enter a package ID to lookup: ')
                first_time = get_hash_map().get(str(count))[9]
                second_time = get_hash_map().get(str(count))[10]
                package_status_time = input(
                    'Please enter a time in the HH:MM:SS format: ')
                (h, m, s) = package_status_time.split(':')
                convert_user_time = datetime.timedelta(hours=int(h),
                                                       minutes=int(m),
                                                       seconds=int(s))
                (h, m, s) = first_time.split(':')
                convert_first_time = datetime.timedelta(hours=int(h),
                                                        minutes=int(m),
                                                        seconds=int(s))
                (h, m, s) = second_time.split(':')
                convert_second_time = datetime.timedelta(hours=int(h),
                                                         minutes=int(m),
                                                         seconds=int(s))
                # First checks if the package has left the hub yet
                if convert_first_time >= convert_user_time:

                    get_hash_map().get(str(count))[10] = 'At Hub'
                    get_hash_map().get(
                        str(count))[9] = 'Leaves at ' + first_time
                    print('Package ID:',
                          get_hash_map().get(str(count))[0],
                          '   Street address:',
                          get_hash_map().get(str(count))[2],
                          get_hash_map().get(str(count))[3],
                          get_hash_map().get(str(count))[4],
                          get_hash_map().get(str(count))[5],
                          '  Required delivery time:',
                          get_hash_map().get(str(count))[6],
                          ' Package weight:',
                          get_hash_map().get(str(count))[7], '  Truck status:',
                          get_hash_map().get(str(count))[9],
                          '  Delivery status:',
                          get_hash_map().get(str(count))[10])
                elif convert_first_time <= convert_user_time:
                    # Then checks if the package has left the hub but has not been delivered yet
                    if convert_user_time < convert_second_time:
                        get_hash_map().get(str(count))[10] = 'In transit'
                        get_hash_map().get(
                            str(count))[9] = 'Left at ' + first_time
                        print('Package ID:',
                              get_hash_map().get(str(count))[0],
                              '   Street address:',
                              get_hash_map().get(str(count))[2],
                              get_hash_map().get(str(count))[3],
                              get_hash_map().get(str(count))[4],
                              get_hash_map().get(str(count))[5],
                              '  Required delivery time:',
                              get_hash_map().get(str(count))[6],
                              ' Package weight:',
                              get_hash_map().get(str(count))[7],
                              '  Truck status:',
                              get_hash_map().get(str(count))[9],
                              '  Delivery status:',
                              get_hash_map().get(str(count))[10])
                    # If the package has already been delivered than it displays the time
                    else:
                        get_hash_map().get(
                            str(count))[10] = 'Delivered at ' + second_time
                        get_hash_map().get(
                            str(count))[9] = 'Left at ' + first_time
                        print('Package ID:',
                              get_hash_map().get(str(count))[0],
                              '   Street address:',
                              get_hash_map().get(str(count))[2],
                              get_hash_map().get(str(count))[3],
                              get_hash_map().get(str(count))[4],
                              get_hash_map().get(str(count))[5],
                              '  Required delivery time:',
                              get_hash_map().get(str(count))[6],
                              ' Package weight:',
                              get_hash_map().get(str(count))[7],
                              '  Truck status:',
                              get_hash_map().get(str(count))[9],
                              '  Delivery status:',
                              get_hash_map().get(str(count))[10])
            except ValueError:
                print('Invalid entry')
                exit()
        elif start == 'exit':
            exit()
        else:
            print('Invalid entry!')
            exit()
Esempio n. 2
0
class Main:
    # This is the display message that is shown when the user runs the program. The interface is accessible from here
    print('Welcome to the WGUPS package tracking system!')
    print('Current route was completed in', "{0:.2f}".format(total_distance(), 2), 'miles.')
    start = input("To begin, please type 'lookup' to search for an individual package or "
                  "type 'timestamp' to view delivery status at a give time: ")
    # Space-time complexity is O(N)
    while start is not 'exit':
        # if user types 'timestamp' then they are prompted for a time to display. Once a time is provided it will
        # display all packages at that timestamp. Runtime of this process is O(N)
        if start == 'timestamp':
            try:
                package_status_time = input('Please enter a time in the HH:MM:SS format: ')
                (h, m, s) = package_status_time.split(':')
                convert_user_time = datetime.timedelta(hours=int(h), minutes=int(m), seconds=int(s))
                # Space-time complexity is O(N^2)
                for count in range(1,41):
                    try:
                        first_time = get_hash_map().get(str(count))[9]
                        second_time = get_hash_map().get(str(count))[10]
                        (h, m, s) = first_time.split(':')
                        convert_first_time = datetime.timedelta(hours=int(h), minutes=int(m), seconds=int(s))
                        (h, m, s) = second_time.split(':')
                        convert_second_time = datetime.timedelta(hours=int(h), minutes=int(m), seconds=int(s))
                    except ValueError:
                        pass
                    # First checks all packages against the given time determine if they have left the hub yet.
                    if convert_first_time >= convert_user_time:
                        get_hash_map().get(str(count))[10] = 'At Hub'
                        get_hash_map().get(str(count))[9] = 'Leaves at ' + first_time
                        print('Package ID:', get_hash_map().get(str(count))[0], '   Street address:',
                              get_hash_map().get(str(count))[2], get_hash_map().get(str(count))[3],
                              get_hash_map().get(str(count))[4], get_hash_map().get(str(count))[5],
                              '  Required delivery time:', get_hash_map().get(str(count))[6],
                              ' Package weight:', get_hash_map().get(str(count))[7], '  Truck status:',
                              get_hash_map().get(str(count))[9], '  Delivery status:',
                              get_hash_map().get(str(count))[10])
                    elif convert_first_time <= convert_user_time:
                        # Then checks to see which packages have left the hub but have not been delivered yet
                        if convert_user_time < convert_second_time:
                            get_hash_map().get(str(count))[10] = 'In transit'
                            get_hash_map().get(str(count))[9] = 'Left at ' + first_time
                            print('Package ID:', get_hash_map().get(str(count))[0], '   Street address:',
                                  get_hash_map().get(str(count))[2], get_hash_map().get(str(count))[3],
                                  get_hash_map().get(str(count))[4], get_hash_map().get(str(count))[5],
                                  '  Required delivery time:', get_hash_map().get(str(count))[6],
                                  ' Package weight:', get_hash_map().get(str(count))[7], '  Truck status:',
                                  get_hash_map().get(str(count))[9], '  Delivery status:',
                                  get_hash_map().get(str(count))[10])
                        # Finally checks all packages that have already been delivered and displays the delivered time
                        else:
                            get_hash_map().get(str(count))[10] = 'Delivered at ' + second_time
                            get_hash_map().get(str(count))[9] = 'Left at ' + first_time
                            print('Package ID:', get_hash_map().get(str(count))[0], '   Street address:',
                                  get_hash_map().get(str(count))[2], get_hash_map().get(str(count))[3],
                                  get_hash_map().get(str(count))[4], get_hash_map().get(str(count))[5],
                                  '  Required delivery time:', get_hash_map().get(str(count))[6],
                                  ' Package weight:', get_hash_map().get(str(count))[7],'  Truck status:',
                                  get_hash_map().get(str(count))[9],'  Delivery status:',
                                  get_hash_map().get(str(count))[10])
            except IndexError:
                print(IndexError)
                exit()
            except ValueError:
                print('Invalid entry!')
                exit()
        # If 'lookup' is selected than the user is prompted for a package ID followed by a timestamp
        # Once that information is entered then the user will be shown a particular package at a given time
        elif start == 'lookup':
            try:
                count = input('Please enter a package ID to lookup: ')
                first_time = get_hash_map().get(str(count))[9]
                second_time = get_hash_map().get(str(count))[10]
                package_status_time = input('Please enter a time in the HH:MM:SS format: ')
                (h, m, s) = package_status_time.split(':')
                convert_user_time = datetime.timedelta(hours=int(h), minutes=int(m), seconds=int(s))
                (h, m, s) = first_time.split(':')
                convert_first_time = datetime.timedelta(hours=int(h), minutes=int(m), seconds=int(s))
                (h, m, s) = second_time.split(':')
                convert_second_time = datetime.timedelta(hours=int(h), minutes=int(m), seconds=int(s))
                # First checks if the package has left the hub yet
                if convert_first_time >= convert_user_time:

                    get_hash_map().get(str(count))[10] = 'At Hub'
                    get_hash_map().get(str(count))[9] = 'Leaves at ' + first_time
                    print('Package ID:', get_hash_map().get(str(count))[0], '   Street address:',
                          get_hash_map().get(str(count))[2], get_hash_map().get(str(count))[3],
                          get_hash_map().get(str(count))[4], get_hash_map().get(str(count))[5],
                          '  Required delivery time:', get_hash_map().get(str(count))[6],
                          ' Package weight:', get_hash_map().get(str(count))[7], '  Truck status:',
                          get_hash_map().get(str(count))[9], '  Delivery status:',
                          get_hash_map().get(str(count))[10])
                elif convert_first_time <= convert_user_time:
                    # Then checks if the package has left the hub but has not been delivered yet
                    if convert_user_time < convert_second_time:
                        get_hash_map().get(str(count))[10] = 'In transit'
                        get_hash_map().get(str(count))[9] = 'Left at ' + first_time
                        print('Package ID:', get_hash_map().get(str(count))[0], '   Street address:',
                              get_hash_map().get(str(count))[2], get_hash_map().get(str(count))[3],
                              get_hash_map().get(str(count))[4], get_hash_map().get(str(count))[5],
                              '  Required delivery time:', get_hash_map().get(str(count))[6],
                              ' Package weight:', get_hash_map().get(str(count))[7], '  Truck status:',
                              get_hash_map().get(str(count))[9], '  Delivery status:',
                              get_hash_map().get(str(count))[10])
                    # If the package has already been delivered than it displays the time
                    else:
                        get_hash_map().get(str(count))[10] = 'Delivered at ' + second_time
                        get_hash_map().get(str(count))[9] = 'Left at ' + first_time
                        print('Package ID:', get_hash_map().get(str(count))[0], '   Street address:',
                              get_hash_map().get(str(count))[2], get_hash_map().get(str(count))[3],
                              get_hash_map().get(str(count))[4], get_hash_map().get(str(count))[5],
                              '  Required delivery time:', get_hash_map().get(str(count))[6],
                              ' Package weight:', get_hash_map().get(str(count))[7], '  Truck status:',
                              get_hash_map().get(str(count))[9], '  Delivery status:',
                              get_hash_map().get(str(count))[10])
            except ValueError:
                print('Invalid entry')
                exit()
        elif start == 'exit':
            exit()
        else:
            print('Invalid entry!')
            exit()
Esempio n. 3
0
for index in range(len(first_optimized_truck_index())):
    try:
        # calculate the total distance of the truck
        first_truck_total_distance = check_distance(
            int(first_optimized_truck_index()[index]),
            int(first_optimized_truck_index()[index + 1]),
            first_truck_total_distance)
        # calculate the distance of each package along the route
        deliver_package = check_time_first_truck(
            check_current_distance(
                int(first_optimized_truck_index()[index]),
                int(first_optimized_truck_index()[index + 1])))
        first_optimized_truck_list()[first_truck_package_id][10] = (
            str(deliver_package))
        get_hash_map().update(
            int(first_optimized_truck_list()[first_truck_package_id][0]),
            first_delivery)
        first_truck_package_id += 1
    except IndexError:
        pass
# for loop updates the delivery status of all packages in truck 2 to when they leave the station
i = 0  # counter to iterate through for loop
# space-time complexity is O(N)
for value in check_second_truck_first_trip():
    check_second_truck_first_trip()[i][9] = second_time
    second_delivery.append(check_second_truck_first_trip()[i])
    i += 1
# this for loop compares the addresses on truck two to the list of addresses and adds the address index to the list
# space-time complexity is O(N^2)
try:
    second_variable_count = 0
first_truck_package_id = 0
for index in range(len(first_truck_final_index())):
    try:

        first_truck_total_distance = check_distances(
            int(first_truck_final_index()[index]),
            int(first_truck_final_index()[index + 1]),
            first_truck_total_distance)

        deliver_package = check_first_truck_time(
            check_current_distances(int(first_truck_final_index()[index]),
                                    int(first_truck_final_index()[index + 1])))
        first_truck_final_list()[first_truck_package_id][10] = (
            str(deliver_package))
        get_hash_map().update(
            int(first_truck_final_list()[first_truck_package_id][0]),
            first_truck_delivery_list)
        first_truck_package_id += 1
    except IndexError:
        pass
#Updating Delivery Status *****************************************************************
#This updates the delivery status for each package
#Truck 2 ***********
i = 0
for value in check_second_truck():
    check_second_truck()[i][9] = second_time
    second_truck_delivery_list.append(check_second_truck()[i])
    i += 1
#Adding Address to List **************************************************************
# Adds the address to the list
#Truck 2 ***********
Esempio n. 5
0
class Main:
    #User Interface *****************************************************************************************
    #when the program is first ran, the user will see this message, and be given different options
    print('Welcome to the WGUPS Package Tracking System! ')
    print('The current route was done in',
          "{0:.2f}".format(total_distances(), 2), 'miles.')
    #Options ************************************************************************************************
    #Space Time Complexity      O(N)
    choice = input("Here are your options:"
                   "\n 1 - Track an Individual Package"
                   "\n 2 - Veiw Delivery Status at a Given Time "
                   "\n 3 - Exit the program"
                   "\n Type the number you selected: ")
    while choice is not '3':
        #Options -  2 - Time ***********************************************************************************
        #If the user selects option 2 , they will be promted to provide a time. The program will output all the packages
        #during the time given.
        if choice == '2':
            try:
                time_entered = input('Please enter a time (HH:MM:SS) : ')
                (h, m, s) = time_entered.split(':')
                convert_time_options = datetime.timedelta(hours=int(h),
                                                          minutes=int(m),
                                                          seconds=int(s))
                for count in range(1, 41):
                    try:
                        time_one = get_hash_map().get(str(count))[9]
                        time_two = get_hash_map().get(str(count))[10]
                        (h, m, s) = time_one.split(':')
                        convert_time_one = datetime.timedelta(hours=int(h),
                                                              minutes=int(m),
                                                              seconds=int(s))
                        (h, m, s) = time_two.split(':')
                        convert_time_two = datetime.timedelta(hours=int(h),
                                                              minutes=int(m),
                                                              seconds=int(s))
                    except ValueError:
                        pass
        #Check which packages are at the hub
                    if convert_time_one >= convert_time_options:
                        get_hash_map().get(str(count))[10] = 'At Hub'
                        get_hash_map().get(
                            str(count))[9] = '\nLeaves at ' + time_one
                        print(' Package ID:',
                              get_hash_map().get(str(count))[0], '\nAddress:',
                              get_hash_map().get(str(count))[2],
                              get_hash_map().get(str(count))[3],
                              get_hash_map().get(str(count))[4],
                              get_hash_map().get(str(count))[5],
                              '  Delivery Deadline:',
                              get_hash_map().get(str(count))[6],
                              '\nPackage Weight (kilos):',
                              get_hash_map().get(str(count))[7],
                              '\nTruck status:',
                              get_hash_map().get(str(count))[9],
                              '\nDelivery status:',
                              get_hash_map().get(str(count))[10])
        #Check which packages are out but not delivered
                    elif convert_time_one <= convert_time_options:
                        if convert_time_options < convert_time_two:
                            get_hash_map().get(str(count))[10] = 'En Route'
                            get_hash_map().get(
                                str(count))[9] = '\nLeft at ' + time_one
                            print(' Package ID:',
                                  get_hash_map().get(str(count))[0],
                                  '\nAddress:',
                                  get_hash_map().get(str(count))[2],
                                  get_hash_map().get(str(count))[3],
                                  get_hash_map().get(str(count))[4],
                                  get_hash_map().get(str(count))[5],
                                  '  Delivery Deadline:',
                                  get_hash_map().get(str(count))[6],
                                  '\nPackage Weight (kilos):',
                                  get_hash_map().get(str(count))[7],
                                  '  Truck status:',
                                  get_hash_map().get(str(count))[9],
                                  '\nDelivery status:',
                                  get_hash_map().get(str(count))[10])
        #Check packages that have been delivered and give the delivery info
                        else:
                            get_hash_map().get(
                                str(count))[10] = 'Delivered at ' + time_two
                            get_hash_map().get(
                                str(count))[9] = 'Left at ' + time_one
                            print(' Package ID:',
                                  get_hash_map().get(str(count))[0],
                                  '\n   Address:',
                                  get_hash_map().get(str(count))[2],
                                  get_hash_map().get(str(count))[3],
                                  get_hash_map().get(str(count))[4],
                                  get_hash_map().get(str(count))[5],
                                  '  Delivery Deadline:',
                                  get_hash_map().get(str(count))[6],
                                  '\n Package Weight (kilos):',
                                  get_hash_map().get(str(count))[7],
                                  '\nTruck status:',
                                  get_hash_map().get(str(count))[9],
                                  '\n  Delivery status:',
                                  get_hash_map().get(str(count))[10])
            except IndexError:
                print(IndexError)
                exit()
        #If the user inputs an incorrect value
            except ValueError:
                print('Invalid Time')
                exit()

#Options -  1 - Track *********************************************************************************
#If the user selects option 1 , they will be promted to provide the package ID, and a time. The program will
#output the information for that package at that time
        elif choice == '1':
            try:
                count = input('Please enter a package ID to lookup: ')
                first_time = get_hash_map().get(str(count))[9]
                second_time = get_hash_map().get(str(count))[10]
                package_status_time = input(
                    'Please enter a time in the HH:MM:SS format: ')
                (h, m, s) = package_status_time.split(':')
                convert_user_time = datetime.timedelta(hours=int(h),
                                                       minutes=int(m),
                                                       seconds=int(s))
                (h, m, s) = first_time.split(':')
                convert_first_time = datetime.timedelta(hours=int(h),
                                                        minutes=int(m),
                                                        seconds=int(s))
                (h, m, s) = second_time.split(':')
                convert_second_time = datetime.timedelta(hours=int(h),
                                                         minutes=int(m),
                                                         seconds=int(s))
                # First checks if the package has left the hub yet
                if convert_first_time >= convert_user_time:

                    get_hash_map().get(str(count))[10] = 'At Hub'
                    get_hash_map().get(
                        str(count))[9] = '\nLeaves at ' + first_time
                    print('Package ID:',
                          get_hash_map().get(str(count))[0],
                          '\nStreet address:',
                          get_hash_map().get(str(count))[2],
                          get_hash_map().get(str(count))[3],
                          get_hash_map().get(str(count))[4],
                          get_hash_map().get(str(count))[5],
                          '  Required delivery time:',
                          get_hash_map().get(str(count))[6],
                          '\nPackage weight:',
                          get_hash_map().get(str(count))[7], '\nTruck status:',
                          get_hash_map().get(str(count))[9],
                          '\nDelivery status:',
                          get_hash_map().get(str(count))[10])
                elif convert_first_time <= convert_user_time:
                    # Then checks if the package has left the hub but has not been delivered yet
                    if convert_user_time < convert_second_time:
                        get_hash_map().get(str(count))[10] = 'In transit'
                        get_hash_map().get(
                            str(count))[9] = '\nLeft at ' + first_time
                        print('Package ID:',
                              get_hash_map().get(str(count))[0],
                              '\nStreet address:',
                              get_hash_map().get(str(count))[2],
                              get_hash_map().get(str(count))[3],
                              get_hash_map().get(str(count))[4],
                              get_hash_map().get(str(count))[5],
                              ' Required delivery time:',
                              get_hash_map().get(str(count))[6],
                              '\nPackage weight:',
                              get_hash_map().get(str(count))[7],
                              '\nTruck status:',
                              get_hash_map().get(str(count))[9],
                              '  Delivery status:',
                              get_hash_map().get(str(count))[10])
                    # If the package has already been delivered than it displays the time
                    else:
                        get_hash_map().get(
                            str(count))[10] = 'Delivered at ' + second_time
                        get_hash_map().get(
                            str(count))[9] = '\nLeft at ' + first_time
                        print('Package ID:',
                              get_hash_map().get(str(count))[0],
                              '\nStreet address:',
                              get_hash_map().get(str(count))[2],
                              get_hash_map().get(str(count))[3],
                              get_hash_map().get(str(count))[4],
                              get_hash_map().get(str(count))[5],
                              '  Required delivery time:',
                              get_hash_map().get(str(count))[6],
                              '\nPackage weight:',
                              get_hash_map().get(str(count))[7],
                              '\nTruck status:',
                              get_hash_map().get(str(count))[9],
                              '\nDelivery status:',
                              get_hash_map().get(str(count))[10])
            except ValueError:
                print('Invalid Look Up Entry')
                exit()
#Options - 3 - Exit Program ********************************************************************
        if choice == '3':
            exit()
        else:
            exit()