Beispiel #1
0
    def __init__(self, tag_name, pkg, node_type=None, name=None, args=None):
        """
        Initializes the Runnable object.

        :param tag_name: Name of XML tag
        :param pkg: Name of package containing the node/test; must be valid
        :param node_type: Type of the node/test (executable); will be set to pkg if None
        :param name: Optional name of the instance within roslaunch; will be set to node_type if None
        :param args: Optional command line arguments
        """
        remapable.Remapable.__init__(self)
        interfaces.Composable.__init__(self)
        interfaces.Composer.__init__(self, [parameter.Parameter, environment.EnvironmentVariable])
        self._pkg = package.Package(pkg) if type(pkg) is str else pkg
        if pkg and not node_type:
            node_type = str(self._pkg)
        if not name:
            name = Runnable.make_valid_base_name(node_type)
        if not pkg:
            raise ValueError("pkg='{}' cannot be empty or None.".format(pkg))
        self._node = node_type  # equals the 'type' attribute in XML
        self.name = Runnable.make_valid_base_name(name)
        self.args = args
        self.clear_params = None
        self.ns = None
        self.prefix = None  # equals the 'launch-prefix' attribute in XML
        self.__tag_name = tag_name
Beispiel #2
0
    def login(self, user, pwd):
        # Package 1
        pk = package.Package()
        pk.set_request_code(defi.HeartbeatRequest)
        pk.set_seq(self.seq.get())
        pk.set_head_checksum()
        self.cli.send(pk.data)

        recv = self.cli.recv(1024)
        package.convert_to_package(recv)

        pk.set_request_code(defi.Login)
        pk.set_seq(self.seq.get())
        pk.set_ack(0)
        pk.set_head_data(package.wrap_login_data(user, pwd))
        pk.set_head_checksum()
        self.cli.send(pk.data)

        recv = self.cli.recv(1024)
        pk = package.convert_to_package(recv)
        if pk.get_request_code() == defi.LoginSuccessful:
            uid, uname, pwd = package.unwrap_user_info(pk.get_head_data())
            return True, uid, uname, pwd
        else:
            return False, 0, pk.get_head_data().decode("utf-8"), ""
Beispiel #3
0
    def LoadTemplate(self,filename):
        self.changed=False
        self.saved=False
        self.elts=list()
        self.CreateTree()
        import cPickle        
        import os
        from os.path import split,isfile,join
        from config import card_folder
        if not isfile(filename):
            #try relpath
            if isfile(join(card_folder,filename)):
                filename=join(card_folder,filename)
        self.dir=split(filename)[0]
        self.file = filename        
        self.Title=os.path.split(self.file)[-1]+"*"
        if filename.endswith('.tmpl'):

            res=cPickle.load(file(filename,'rb'))
        elif filename.endswith('.bgp'):
            import package
            p=package.Package(filename)
            res=cPickle.load(p.template)
        self.LoadElements(res)
        self.statusbar.SetStatusText('Template %s Loaded !'%filename)
Beispiel #4
0
def import_packages(package_hash):
    package_reader = csv.reader(open('WGUPS Package File.csv'),
                                delimiter=',',
                                skipinitialspace=True)

    package_reader.__next__()

    # iterate through each row to load packages
    for row in package_reader:
        package_id = int(row[0])
        address = row[1]
        city = row[2]
        state = row[3]
        postal_code = row[4]
        deadline = row[5]
        weight = row[6]
        truck = row[7]
        depart = row[8]

        # create package object
        new_package = package.Package(package_id, address, deadline, city,
                                      state, postal_code, weight, truck,
                                      depart)

        # add package to hash table
        package_hash.add(new_package)
    def networkReceive(self, pkg, nos):
        logging.info("Pacote["+str(pkg.id)+"]["+str(pkg.type)+"] dado:["+str(pkg.data)+"] originario do nó "+str(pkg.dl_header[0])+" recebido pelo nó "+str(pkg.rec_node))
        if(pkg.type == "DATA"):
            if(pkg.rec_node == pkg.net_header[1]):
                logging.info("Pacote["+str(pkg.id)+"]["+str(pkg.type)+"]chegou ao destino final "+str(pkg.rec_node))
                pass                                                                              #pacote de dado chegou ao destino final
            else:
                nos[pkg.rec_node].networkSend(pkg, nos)

        if((pkg.type == "RREQ") and not(pkg.id in nos[pkg.rec_node].rreq_buffer)):
            nos[pkg.rec_node].rreq_buffer.append(pkg.id)
            pkg_cpy = copy.deepcopy(pkg)
            pkg_cpy.data.append(pkg.rec_node)
            data_cpy = copy.deepcopy(pkg_cpy.data)
            nos[pkg.rec_node].fillTable(nos, pkg_cpy)
            if(pkg.rec_node == pkg.net_header[1]):  
                data_cpy.reverse()
                rrep = pk.Package(pkg.id, pkg.net_header[1], pkg.net_header[0], data_cpy, "RREP")
                rrep.dsr = copy.deepcopy(data_cpy)
                nos[pkg.rec_node].networkSend(rrep, nos)                                          #envia rrep
            else:
                pkg_cpy.dl_header = [pkg.rec_node, -1]
                nos[pkg.rec_node].rreq_buffer.append(pkg.id)
                super().mediumAccessControl(pkg_cpy, nos)                                         #reenvia rreq
                
        if(pkg.type == "RREP" and not(pkg.id in nos[pkg.rec_node].rrep_buffer)):
            nos[pkg.rec_node].fillTable(nos, pkg)
            nos[pkg.rec_node].rrep_buffer.append(pkg.id)
            if(pkg.rec_node == pkg.net_header[1]):
                pass                                                                              #apos a execuçao do dsr, eniva o pacote inicial que está no buffer
            else:
                nos[pkg.rec_node].networkSend(pkg, nos)                                           #reenvia rrep
        pass
 def routeRequest(self, nos, pkg):    
     dado = [pkg.net_header[0]]
     pk.Package.id_rreq = pk.Package.id_rreq + 1
     rreq = pk.Package(pk.Package.id_rreq, pkg.net_header[0], pkg.net_header[1], dado, "RREQ")    
     nos[pkg.net_header[0]].rreq_buffer.append(rreq.id)                                    
     super().mediumAccessControl(rreq, nos)                                                                                               #envia rreq
     pass
Beispiel #7
0
 def generate_packages(self, number, packages=None):
     # give pack package a name and add dropoff to list
     # if list was given, use that
     if packages is not None:
         self.packages = [Pkg.Package() for i in range(len(packages))]
         for package in self.packages:
             newpos = packages.pop()
             package.pickup = newpos[0]
             package.dropoff = newpos[1]
     else:
         #don't fully get python yet....
         self.packages = [Pkg.Package(self.size) for i in range(number)]
     for p in range(len(self.packages)):
         self.packages[p].name = str(p)
         self.dropoffs.append(self.packages[p].dropoff)
         self.pickups.append(self.packages[p].pickup)
Beispiel #8
0
    def do_log_in(self, headers, cookies):
        username = headers.get("username")
        password = headers.get("password")

        if username is None or password is None:
            raise AuthorizationError

        current_user = db.DataBase.session.query(db.User).filter_by(username=username).one_or_none()
        if current_user is None:
            raise UserNotExistError

        if hashlib.md5(password.encode()).hexdigest() != current_user.password:
            raise PasswordError

        session_token = str(uuid.uuid4())
        current_user.session_token = session_token

        session_start = datetime.datetime.now()
        current_user.session_start = session_start

        db.DataBase.session.add(current_user)
        db.DataBase.session.commit()

        return package.Package(status=200,
                               content=f"Authorization is successful!\nWelcome, {username}",
                               cookies={
                                   **cookies,
                                   "session-token": session_token,
                                   "session-start": session_start.strftime("%H:%M:%S - %m.%d.%Y")
                               })
Beispiel #9
0
    def __generate__(self, path):
        """
        create the proof sheet
        """

        logger = logging.getLogger(sys._getframe().f_code.co_name)

        real_path = validate_path(path, 'directory')
        # get a list of all the directories at path and determine which are image packages
        directories = [
            o for o in os.listdir(real_path)
            if os.path.isdir(os.path.join(real_path, o))
        ]
        self.packages = []
        self.other_directories = []
        for d in directories:
            pkg = package.Package()
            try:
                pkg.open(os.path.join(path, d))
            except IOError, e:
                logger.warning(
                    "failed trying to open directory '{0}' as a package: {1}".
                    format(d, e))
                self.other_directories.append(d)
            else:
                if pkg.validate():
                    self.packages.append(pkg)
                else:
                    logger.warning(
                        "successfully opened directory '{0}' as a package, but it failed to validate"
                        .format(d))
                    self.other_directories.append(d)
Beispiel #10
0
 def pkg(self, value):
     """
     Allows to change the package, this Runnable belongs to.
     :param value: package.Package instance or ROS package name
     """
     if not value:
         raise ValueError("pkg='{}' cannot be empty or None.".format(value))
     self._pkg = package.Package(value) if type(value) is str else value
Beispiel #11
0
    def set_package(self, pkg):
        """
        Sets the ROS package path this path is referring to.

        :param pkg: ROS package name, the path relates to
        :return: None
        """
        if not self.pkg:  # retain pkg initialized in ctor if already set (no overwrites)
            self.pkg = package.Package(pkg) if type(pkg) is str else pkg
Beispiel #12
0
    def __init__(self, path, pkg=None):
        """
        Initializes the resolvable path.

        :param path: Entire path or partial (ROS package related) path
        :param pkg: ROS package name, the path relates to
        """
        Resolvable.__init__(self, path)
        self.pkg = package.Package(pkg) if type(pkg) is str else pkg
Beispiel #13
0
 def send_message(self, uid, message):
     if len(message) == 0:
         return
     pkg = package.Package()
     pkg.set_seq(self.seq.get())
     pkg.set_time()
     pkg.set_request_code(defi.Message)
     pkg.set_head_data(package.wrap_message(uid, message))
     pkg.set_head_checksum()
     self.cli.send(pkg.data)
Beispiel #14
0
 def on_packButton_clicked(self):
     """
     pack nuke project ro target dir
     :return:
     """
     target_dir = self.mainWidget.filelineEdit.text()
     if target_dir:
         package.Package(target_dir, self,
                         self.show_Progress()).packed_file()
     else:
         self.show_msgBox()
def indexpackages():
    """
    Iterates over Packages in Resource Folder and saves the Information in a Dict
    """
    files = os.listdir('resources')
    for file in files:
        details = file.split('.z')
        pkgdetail = details[0].split('_')
        pkg = package.Package(pkgdetail[0], pkgdetail[1],
                              "localhost:8443/resources/{}".format(file),
                              "resources/{}".format(file))
        packages[pkg.name] = pkg
Beispiel #16
0
def package_hashmap():
    """This returns the package hashmap

    Space Complexity: O(n)

    Time Complexity: O(n)
        
    Returns:
       hash_table.HashTable: packages hashtable
       
    """
    package_hash = hash_table.HashTable()
    packages = parse_packages()
    for i in packages:
        
        package_hash[i[0]] = package.Package(*i)

    return package_hash
Beispiel #17
0
 def p_package_depencency(self, t):
     """dep : ID LT ID
            | ID LE ID
            | ID EQ ID
            | ID GE ID
            | ID GT ID
     """
     op  = t[2]
     reqPkg = package.Package (name=t[1], version=t[3], displayname="virtual package")
     pkg = self.inventory.get(t[1])
     if pkg:
         r = pkg.compareVersion(reqPkg)
         evalStr = "%s %s 0" % (r, op)
         if not eval(evalStr):
             self.reason = "Failed for rule: requires %s %s %s" % (t[1], t[2], t[3])
             self.depPass = 0
     else:
         self.reason = "Repository package doesn't exist in system inventory."
         self.depPass = 0
Beispiel #18
0
    def test_simple_stufff(self):
        self.startup()
        path = os.path.join(self.temp_packages, "package1.json")
        p = package.Package(path)
        p.read()
        self.assertEqual(p.id, "1")
        self.assertEqual(p.name, "Package")
        dirs = p.dirs
        self.assertEqual(dirs[0].name, 'FOLDER 1')
        files = p.files
        self.assertEqual(len(files), 0)
        files = dirs[0].files
        self.assertEqual(len(files), 2)
        files = p.all_files
        self.assertEqual(len(files), 5)
        print(files[0].path)

        bag = p.bag_me("test/bag1", overwrite=True, testmode=True)
        #Test validity

        p.zipped_bag("test/package1")
Beispiel #19
0
    def do_log_in(self, headers, cookies):
        username = headers.get("username")
        password = headers.get("password")

        if username is None or password is None:
            raise exc.AuthorizationError(
                message="The user is not logged in. "
                "Headers with parameters are required: "
                "'username', 'password'",
                status=403)

        current_user = db.DataBase.session.query(
            db.User).filter_by(username=username).one_or_none()
        if current_user is None:
            raise exc.UserNotExistError

        if hashlib.md5(password.encode()).hexdigest() != current_user.password:
            raise exc.PasswordError

        session_token = str(uuid.uuid4())
        current_user.session_token = session_token

        session_start = datetime.datetime.now()
        current_user.session_start = session_start

        with db.DataBase.session.begin() as transaction:
            try:
                db.DataBase.session.add(current_user)
            except Exception as e:
                logging.info(f"Error: {e}")
                transaction.rollback()

        return package.Package(
            status=200,
            content=f"Authorization is successful!\nWelcome, {username}",
            headers={**headers},
            cookies={
                **cookies, "session-token": session_token,
                "session-start": session_start.strftime("%H:%M:%S - %m.%d.%Y")
            })
Beispiel #20
0
def job(item):
    import package
    if (arglist['verbose']):
        print(item.strip(local))
    pk = package.Package(item, arglist["destination"])
    pk.make()
Beispiel #21
0
 def handle_error(self, e, status=400):
     status = e.status or status
     return package.Package(status=status, content=e.message)
Beispiel #22
0
def main_one():
    with open('WGUPSPackageFile1.csv', 'r') as csvfile:
        csv_file = csv.reader(csvfile, delimiter=',')  # reads the CSV package file
        list_of_packages = list(csv_file)
        # print(list_of_packages[0][0])
        packageHashTable = HashTable()  # 15 - creates a hashtable object by calling the HashTable class

        distances = Distances()
        trucks = Trucks()  # creates truck object by calling Trucks class

        # creates lists of each package attribute

        Package_IDs = []
        Addresses = []
        Cities = []
        States = []
        Zips = []
        Delivery_Deadlines = []
        Weight = []
        Notes = []
        Status = []
        Departure_time = []

        # reads the package csv and creates attributes for each package
        for row in list_of_packages:  # space time complexity is O(N)
            pid = row[0].strip()
            address = row[1]
            city = row[2]
            state = row[3]
            zipcode = row[4]
            deadline = row[5]
            weight = row[6]
            note = row[7]
            status = row[8]
            departure_time = row[9]

            # appends each value to respective lists
            Package_IDs.append(pid)
            Addresses.append(address)
            Cities.append(city)
            States.append(state)
            Zips.append(zipcode)
            Delivery_Deadlines.append(deadline)
            Weight.append(weight)
            Notes.append(note)
            Status.append(status)
            Departure_time.append(departure_time)

            p = package.Package(pid, address, city, state, zipcode, deadline,
                                weight, note)  # creates the package object using the package class

            packageHashTable.get(pid)  # look up the package by the id
            packageHashTable.insert(pid, p)  # inserts the packages into the hashtable

        # gets the package object using the ids using the hashtable and creates package objects for each
        p1 = packageHashTable.get('1')
        p5 = packageHashTable.get('5')
        p7 = packageHashTable.get('7')
        p8 = packageHashTable.get('8')
        p10 = packageHashTable.get('10')
        p11 = packageHashTable.get('11')
        p12 = packageHashTable.get('12')
        p13 = packageHashTable.get('13')
        p14 = packageHashTable.get('14')
        p15 = packageHashTable.get('15')
        p16 = packageHashTable.get('16')
        p19 = packageHashTable.get('19')
        p20 = packageHashTable.get('20')
        p29 = packageHashTable.get('29')
        p30 = packageHashTable.get('30')
        p34 = packageHashTable.get('34')
        p37 = packageHashTable.get('37')
        p3 = packageHashTable.get('3')
        p6 = packageHashTable.get('6')
        p18 = packageHashTable.get('18')
        p25 = packageHashTable.get('25')
        p26 = packageHashTable.get('26')
        p31 = packageHashTable.get('31')
        p36 = packageHashTable.get('36')
        p38 = packageHashTable.get('38')
        p40 = packageHashTable.get('40')
        p2 = packageHashTable.get('2')
        p4 = packageHashTable.get('4')
        p9 = packageHashTable.get('9')
        p17 = packageHashTable.get('17')
        p21 = packageHashTable.get('21')
        p22 = packageHashTable.get('22')
        p23 = packageHashTable.get('23')
        p24 = packageHashTable.get('24')
        p27 = packageHashTable.get('27')
        p28 = packageHashTable.get('28')
        p32 = packageHashTable.get('32')
        p33 = packageHashTable.get('33')
        p35 = packageHashTable.get('35')
        p39 = packageHashTable.get('39')
        # p37.status = 'At Hub'
        # print(p37)
        firstTruckTripPackages = [p1, p7, p8, p10, p11, p12, p13, p14, p15, p16, p19, p20, p29, p30, p34, p37]
        # print(p1.pid)
        # puts the packages into the first truck
        # print(packageHashTable.update_status('1', 'At HUB'))

        firstTruckTripPAddresses = []
        for item in firstTruckTripPackages:
            firstTruckTripPackageA = item.address
            firstTruckTripPAddresses.append(firstTruckTripPackageA)
            # creates a list of addresses of each package in the first truck
            # space time complexity of O(N)

        secondTruckTripPackages = [p3, p6, p18, p25, p26, p31, p36, p38, p40]
        # puts the package object into the second truck

        secondTruckTripPAddresses = []
        for item in secondTruckTripPackages:
            secondTruckTripPackageA = item.address
            secondTruckTripPAddresses.append(secondTruckTripPackageA)
            # creates a list of addresses of each package in the second truck
            # space time complexity of O(N)

        thirdTruckTripPackages = [p2, p4, p5, p9, p17, p21, p22, p23, p24, p27, p28, p32, p33, p35, p39]
        # puts the package object into the third truck

        thirdTruckTripPAddresses = []
        for item in thirdTruckTripPackages:
            firstTruckSecondTripPackageA = item.address
            thirdTruckTripPAddresses.append(firstTruckSecondTripPackageA)
            # creates a list of addresses of each package in the second truck
            # space time complexity of O(N)

        first_location = 'HUB'

        # creates list of addresses from the optimized list of addresses from truck 1
        first_truck_delivery = trucks.shortest_distance_calculation_truck1_addresses(
            firstTruckTripPAddresses, firstTruckTripPackages, first_location)

        # creates list of addresses from the optimized list of addresses from truck 2
        second_truck_delivery = trucks.shortest_distance_calculation_truck2_addresses(
            secondTruckTripPAddresses, secondTruckTripPackages, first_location)

        # creates list of addresses from the optimized list of addresses from truck 3
        third_truck_delivery = trucks.shortest_distance_calculation_truck3_addresses(
            thirdTruckTripPAddresses, thirdTruckTripPackages, first_location)

    # lines 166-168 update each package departure time
    trucks.update_package_departure_from_hub_time_first_truck(firstTruckTripPackages)
    trucks.update_package_departure_from_hub_time_second_truck(secondTruckTripPackages)
    trucks.update_package_departure_from_hub_time_third_truck(thirdTruckTripPackages)

    # lines 167-169 update each package delivery time to the time they are delivered
    trucks.update_package_delivery_time_first_truck(first_truck_delivery, firstTruckTripPackages, 'HUB')
    trucks.update_package_delivery_time_second_truck(second_truck_delivery, secondTruckTripPackages, 'HUB')
    trucks.update_package_delivery_time_third_truck(third_truck_delivery, thirdTruckTripPackages, 'HUB')

    # for item in firstTruckTripPackages:
    #     print(item.pid)
    #     print(item.departure_time)
    #     print(item.delivery_time)
    # print('\n')
    #
    #
    # for item2 in secondTruckTripPackages:
    #     print(item2.pid)
    #     print(item2.departure_time)
    #     print(item2.delivery_time)
    # print('\n')
    #
    # for item3 in thirdTruckTripPackages:
    #     print(item3.pid)
    #     print(item3.departure_time)
    #     print(item3.delivery_time)
    # print('\n')

    print('Hello, welcome to the portal of the Western Governors University Parcel Service!')
    print('Below is the total miles traveled in by each truck delivery:')
    first_truck_miles = trucks.calculate_total_distance_traveled_per_truck(first_truck_delivery, 'HUB')
    print('First truck miles: ', first_truck_miles)
    second_truck_miles = trucks.calculate_total_distance_traveled_per_truck(second_truck_delivery, 'HUB')
    print('Second truck miles: ', second_truck_miles)
    third_truck_miles = trucks.calculate_total_distance_traveled_per_truck(third_truck_delivery, 'HUB')
    print('Third truck miles: ', third_truck_miles)
    print('Total miles: ', first_truck_miles + second_truck_miles + third_truck_miles)


    first_input = input("Please enter 'get' or 'status' to get started. 'Get' will return package information and "
                        "'status' will return status information for a certain time: ")
    # space time complexity O(N^2)
    while first_input is not 'exit':
        if first_input == 'get':
            p = input("Please enter package ID: ")
            for package_id_input in firstTruckTripPackages:  # gets package information from each package in truck 1
                if package_id_input.pid == p:
                    departure_time = package_id_input.departure_time
                    delivery_time = package_id_input.delivery_time
                    user_input_time = input("please enter a time in the 'HH:MM:SS' format: ")
                    convert_user_input_time = datetime.strptime(user_input_time, '%H:%M:%S')
                    if departure_time >= convert_user_input_time:  # checks if package is at hub and then sets
                        # value in hashtable
                        package_id_input.status = 'At HUB'
                        print('Package ID: ', package_id_input.pid, 'Address: ', package_id_input.address, 'City: ',
                              package_id_input.city, 'State: ', package_id_input.state, 'Zipcode: ',
                              package_id_input.zip_code,
                              'Deadline: ', package_id_input.deadline, 'Weight: ', package_id_input.weight, 'Notes: ',
                              package_id_input.note, 'Status: ', package_id_input.status, 'Departure Time: ',
                              package_id_input.departure_time, 'Delivery Time: ', package_id_input.delivery_time)
                    elif departure_time <= convert_user_input_time:  # checks if package is in transit
                        # then sets in hashtable
                        if convert_user_input_time < delivery_time:
                            package_id_input.status = 'In transit'
                            print('Package ID: ', package_id_input.pid, 'Address: ', package_id_input.address, 'City: ',
                                  package_id_input.city, 'State: ', package_id_input.state, 'Zipcode: ',
                                  package_id_input.zip_code,
                                  'Deadline: ', package_id_input.deadline, 'Weight: ', package_id_input.weight,
                                  'Notes: ',
                                  package_id_input.note, 'Status: ', package_id_input.status, 'Departure Time: ',
                                  package_id_input.departure_time, 'Delivery Time: ', package_id_input.delivery_time)
                        else:  # checks if package is delivered and then sets value in hashtable
                            package_id_input.status = 'Delivered'
                            print('Package ID: ', package_id_input.pid, 'Address: ', package_id_input.address, 'City: ',
                                  package_id_input.city, 'State: ', package_id_input.state, 'Zipcode: ',
                                  package_id_input.zip_code,
                                  'Deadline: ', package_id_input.deadline, 'Weight: ', package_id_input.weight,
                                  'Notes: ',
                                  package_id_input.note, 'Status: ', package_id_input.status, 'Departure Time: ',
                                  package_id_input.departure_time, 'Delivery Time: ', package_id_input.delivery_time)
            for package_id_input in secondTruckTripPackages:  # gets package information from each package in truck 2
                if package_id_input.pid == p:
                    departure_time = package_id_input.departure_time
                    delivery_time = package_id_input.delivery_time
                    user_input_time = input("please enter a time in the 'HH:MM:SS' format: ")
                    convert_user_input_time = datetime.strptime(user_input_time, '%H:%M:%S')
                    if departure_time >= convert_user_input_time:
                        package_id_input.status = 'At HUB'
                        print('Package ID: ', package_id_input.pid, 'Address: ', package_id_input.address, 'City: ',
                              package_id_input.city, 'State: ', package_id_input.state, 'Zipcode: ',
                              package_id_input.zip_code,
                              'Deadline: ', package_id_input.deadline, 'Weight: ', package_id_input.weight, 'Notes: ',
                              package_id_input.note, 'Status: ', package_id_input.status, 'Departure Time: ',
                              package_id_input.departure_time, 'Delivery Time: ', package_id_input.delivery_time)
                    elif departure_time <= convert_user_input_time:
                        if convert_user_input_time < delivery_time:
                            package_id_input.status = 'In transit'
                            print('Package ID: ', package_id_input.pid, 'Address: ', package_id_input.address, 'City: ',
                                  package_id_input.city, 'State: ', package_id_input.state, 'Zipcode: ',
                                  package_id_input.zip_code,
                                  'Deadline: ', package_id_input.deadline, 'Weight: ', package_id_input.weight,
                                  'Notes: ',
                                  package_id_input.note, 'Status: ', package_id_input.status, 'Departure Time: ',
                                  package_id_input.departure_time, 'Delivery Time: ', package_id_input.delivery_time)
                        else:
                            package_id_input.status = 'Delivered'
                            print('Package ID: ', package_id_input.pid, 'Address: ', package_id_input.address, 'City: ',
                                  package_id_input.city, 'State: ', package_id_input.state, 'Zipcode: ',
                                  package_id_input.zip_code,
                                  'Deadline: ', package_id_input.deadline, 'Weight: ', package_id_input.weight,
                                  'Notes: ',
                                  package_id_input.note, 'Status: ', package_id_input.status, 'Departure Time: ',
                                  package_id_input.departure_time, 'Delivery Time: ', package_id_input.delivery_time)
            for package_id_input in thirdTruckTripPackages:  # gets package information from each package in truck 3
                if package_id_input.pid == p:
                    departure_time = package_id_input.departure_time
                    delivery_time = package_id_input.delivery_time
                    user_input_time = input("please enter a time in the 'HH:MM:SS' format: ")
                    convert_user_input_time = datetime.strptime(user_input_time, '%H:%M:%S')
                    if departure_time >= convert_user_input_time:  # checks if package is at the hub
                        package_id_input.status = 'At HUB'
                        print('Package ID: ', package_id_input.pid, 'Address: ', package_id_input.address, 'City: ',
                              package_id_input.city, 'State: ', package_id_input.state, 'Zipcode: ',
                              package_id_input.zip_code,
                              'Deadline: ', package_id_input.deadline, 'Weight: ', package_id_input.weight, 'Notes: ',
                              package_id_input.note, 'Status: ', package_id_input.status, 'Departure Time: ',
                              package_id_input.departure_time, 'Delivery Time: ', package_id_input.delivery_time)
                    elif departure_time <= convert_user_input_time:  # checks if package is in transit or delivered
                        if convert_user_input_time < delivery_time:
                            package_id_input.status = 'In transit'
                            print('Package ID: ', package_id_input.pid, 'Address: ', package_id_input.address, 'City: ',
                                  package_id_input.city, 'State: ', package_id_input.state, 'Zipcode: ',
                                  package_id_input.zip_code,
                                  'Deadline: ', package_id_input.deadline, 'Weight: ', package_id_input.weight,
                                  'Notes: ',
                                  package_id_input.note, 'Status: ', package_id_input.status, 'Departure Time: ',
                                  package_id_input.departure_time, 'Delivery Time: ', package_id_input.delivery_time)
                        else:
                            package_id_input.status = 'Delivered'
                            print('Package ID: ', package_id_input.pid, 'Address: ', package_id_input.address, 'City: ',
                                  package_id_input.city, 'State: ', package_id_input.state, 'Zipcode: ',
                                  package_id_input.zip_code,
                                  'Deadline: ', package_id_input.deadline, 'Weight: ', package_id_input.weight,
                                  'Notes: ',
                                  package_id_input.note, 'Status: ', package_id_input.status, 'Departure Time: ',
                                  package_id_input.departure_time, 'Delivery Time: ', package_id_input.delivery_time)
        # checks the status of each package in all three trucks
        elif first_input == 'status':
            user_input_input_time = input("Please enter starting time in 'HH:MM:SS' format: ")
            convert_user_input_time = datetime.strptime(user_input_input_time,
                                                        '%H:%M:%S')  # converts time inputted to datetime
            for p in firstTruckTripPackages:  # checks status of the first truck
                departure_time = p.departure_time
                delivery_time = p.delivery_time
                if departure_time >= convert_user_input_time:  # checks if package is at the HUB
                    p.status = 'At HUB'
                    print('Package ID: ', p.pid, 'Status: ', p.status)
                elif delivery_time <= convert_user_input_time:  # checks if package has been delivered
                    p.status = 'Delivered'
                    print('Package ID: ', p.pid, 'Status: ', p.status)
                elif departure_time <= convert_user_input_time < delivery_time:  # checks if package is in transit
                    p.status = 'In transit'
                    print('Package ID: ', p.pid, 'Status: ', p.status)
            for p in secondTruckTripPackages:  # checks status of the second truck
                departure_time = p.departure_time
                delivery_time = p.delivery_time
                if departure_time >= convert_user_input_time:  # checks if package is at the hub
                    p.status = 'At HUB'
                    print('Package ID: ', p.pid, 'Status: ', p.status)
                elif delivery_time <= convert_user_input_time:  # checks if package has been delivered
                    p.status = 'Delivered'
                    print('Package ID: ', p.pid, 'Status: ', p.status)
                elif departure_time <= convert_user_input_time < delivery_time:  # checks if package is in transit
                    p.status = 'In transit'
                    print('Package ID: ', p.pid, 'Status: ', p.status)
            for p in thirdTruckTripPackages:  # checks status of third truck
                departure_time = p.departure_time
                delivery_time = p.delivery_time
                if departure_time >= convert_user_input_time:  # checks if package is at the hub
                    p.status = 'At HUB'
                    print('Package ID: ', p.pid, 'Status: ', p.status)
                elif delivery_time <= convert_user_input_time:  # checks if package has been delivered
                    p.status = 'Delivered'
                    print('Package ID: ', p.pid, 'Status: ', p.status)
                elif departure_time <= convert_user_input_time < delivery_time:  # checks if package is in transit
                    p.status = 'In transit'
                    print('Package ID: ', p.pid, 'Status: ', p.status)
        elif first_input == 'exit':
            exit()
Beispiel #23
0
import package as pk
import router as node
import numpy as np
from scipy.spatial import distance
import copy
import logging

logging.basicConfig(filename='example.log',level=logging.DEBUG)
    
count = 0
nos = []
for x in range(3):
    for y in range(3):
        nos.append(node.Router(count, x, y))
        count = count +1

nos = np.array(nos)

pkg0 = pk.Package(0, 0, 4, [1,1,1,1,1], "DATA")
pkg1 = pk.Package(10, 3, 8, [1,1,2,2,1], "DATA")

for i in nos:
    i.findNeighbors(i.id, nos)

nos[0].networkSend(pkg0,nos)
nos[3].networkSend(pkg1,nos)
Beispiel #24
0
        departure_time = row[9]

        # appends each value to respective lists
        Package_IDs.append(pid)
        Addresses.append(address)
        Cities.append(city)
        States.append(state)
        Zips.append(zipcode)
        Delivery_Deadlines.append(deadline)
        Weight.append(weight)
        Notes.append(note)
        Status.append(status)
        Departure_time.append(departure_time)

        p = package.Package(
            pid, address, city, state, zipcode, deadline, weight,
            note)  # creates the package object using the package class

        pH.get(pid)  # look up the package by the id
        pH.insert(pid, p)  # inserts the packages into the hashtable

    # gets the package object using the ids using the hashtable and creates package objects for each

    # p37.status = 'At Hub'
    # print(p37)
    firstTruckTripPackages = [
        pH.get('1'),
        pH.get('7'),
        pH.get('8'),
        pH.get('10'),
        pH.get('11'),
Beispiel #25
0
    def load_file(self, path, nameonly=False, decodewrap=False):
        """引数のファイル(wid, wsmファイル)を読み込む。"""
        try:
            f = cwfile.CWFile(path, "rb", decodewrap=decodewrap)

            no = nameonly
            md = self.materialdir
            ie = self.image_export

            if path.lower().endswith(".wsm"):
                data = summary.Summary(None,
                                       f,
                                       nameonly=no,
                                       materialdir=md,
                                       image_export=ie)
                data.skintype = self.skintype
            else:
                filetype = f.byte()
                f.seek(0)
                f.filedata = []

                if filetype == 0:
                    data = area.Area(None,
                                     f,
                                     nameonly=no,
                                     materialdir=md,
                                     image_export=ie)
                elif filetype == 1:
                    data = battle.Battle(None,
                                         f,
                                         nameonly=no,
                                         materialdir=md,
                                         image_export=ie)
                elif filetype == 2:
                    if os.path.basename(path).lower().startswith("battle"):
                        data = battle.Battle(None,
                                             f,
                                             nameonly=no,
                                             materialdir=md,
                                             image_export=ie)
                    else:
                        data = cast.CastCard(None,
                                             f,
                                             nameonly=no,
                                             materialdir=md,
                                             image_export=ie)
                elif filetype == 3:
                    data = item.ItemCard(None,
                                         f,
                                         nameonly=no,
                                         materialdir=md,
                                         image_export=ie)
                elif filetype == 4:
                    lpath = os.path.basename(path).lower()
                    if lpath.startswith("package"):
                        data = package.Package(None,
                                               f,
                                               nameonly=no,
                                               materialdir=md,
                                               image_export=ie)
                    elif lpath.startswith("mate"):
                        data = cast.CastCard(None,
                                             f,
                                             nameonly=no,
                                             materialdir=md,
                                             image_export=ie)
                    else:
                        data = info.InfoCard(None,
                                             f,
                                             nameonly=no,
                                             materialdir=md,
                                             image_export=ie)

                elif filetype == 5:
                    if os.path.basename(path).lower().startswith("item"):
                        data = item.ItemCard(None,
                                             f,
                                             nameonly=no,
                                             materialdir=md,
                                             image_export=ie)
                    else:
                        data = skill.SkillCard(None,
                                               f,
                                               nameonly=no,
                                               materialdir=md,
                                               image_export=ie)
                elif filetype == 6:
                    if os.path.basename(path).lower().startswith("info"):
                        data = info.InfoCard(None,
                                             f,
                                             nameonly=no,
                                             materialdir=md,
                                             image_export=ie)
                    else:
                        data = beast.BeastCard(None,
                                               f,
                                               nameonly=no,
                                               materialdir=md,
                                               image_export=ie)
                elif filetype == 7:
                    data = skill.SkillCard(None,
                                           f,
                                           nameonly=no,
                                           materialdir=md,
                                           image_export=ie)
                elif filetype == 8:
                    data = beast.BeastCard(None,
                                           f,
                                           nameonly=no,
                                           materialdir=md,
                                           image_export=ie)
                else:
                    f.close()
                    raise ValueError(path)

            if not nameonly:
                # 読み残し分を全て読み込む
                f.read()

            f.close()
            return data, "".join(f.filedata)
        except:
            cw.util.print_ex()
            return None, None