def __init__(self, name=None): """Initialize a new System object. This must be run before the system can be used. Args: name (str): The name of the system >>> print __init__(name='sysname') """ if name: self._name = name else: self._name = "Untitled" self._v1x = 0.0 self._v2x = 0.0 self._v3x = 0.0 self._v1y = 0.0 self._v2y = 0.0 self._v3y = 0.0 self._v1z = 0.0 self._v2z = 0.0 self._v3z = 0.0 self._nbFunc = 0 self._combinationRule = 0 self._genpairs = True self._ljCorrection = 0 self._coulombCorrection = 0 self._molecules = OrderedDict.OrderedDict() self._atomtypes = HashMap.HashMap() self._forces = OrderedSet.OrderedSet() self._boxVector = []
def main(): path = get_path() if path is None: return 1 os.chdir(path) hash_map = HashMap.HashMap() for filename in os.listdir(os.getcwd()): size = os.path.getsize(filename) hash_map.process(size, filename) return 0
def main(): data = open('dataset.csv') H = HashMap(20) keys = [] passenger = None for line in data: passenger = Passenger(tuple(line.split(',')[1:])) keys.append(passenger.key) H.insert(passenger) for key in keys: try: print(H.search(key).details[5]) except: print(key + ' not found')
def __init__(self, file): '''Mètode constructor''' self._hashMap = HashMap() self.appendText(file)
try: print(m.find(6)) except Exeption.NotFoundException: print("Item not found") try: print(m[7]) except Exeption.NotFoundException: print("Item not found") print("size of map: " + str(len(m))) try: m.remove(5) print("Item removed") except Exeption.NotFoundException: print("Item not found") try: print(m.find(5)) except Exeption.NotFoundException: print("Item not found") print("size of map: " + str(len(m))) if __name__ == "__main__": print("\nTESTING BUCKET") m = Bucket.Bucket() test_map(m) print("\nTESTING HASHMAP") m = HashMap.HashMap() test_map(m)
import datetime import Package import HashMap import Truck #This section creates a blank list and takes the data from the csv file and creates instance of the packages which are put into the package list O(N) packageList = [] with open('PackageSheet.csv', newline='') as csvfile: DataReader = csv.reader(csvfile) for row in DataReader: packageList.append( Package.Package(row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], 'At Hub', '')) #This section creates a Hash table that is populated using the package ID as the key and the package itself as the value O(N) hashTable = HashMap.HashMap() for package in packageList: hashTable.add(int(package.packageID), package) #This is a dictionary of locations for reference O(1) locations = { '4001 South 700 East': 0, '1060 Dalton Ave S': 1, '1330 2100 S': 2, '1488 4800 S': 3, '177 W Price Ave': 4, '195 W Oakland Ave': 5, '2010 W 500 S': 6, '2300 Parkway Blvd': 7, '233 Canyon Rd': 8, '2530 S 500 E': 9,
import HashMap h = HashMap() h.add('Bob', '567-8888') h.add('Ming', '293-6753') h.add('Ming', '333-8233') h.add('Ankit', '293-8625') h.add('Aditya', '852-6551') h.add('Alicia', '632-4123') h.add('Mike', '567-2188') h.add('Aditya', '777-8888') h.print() h.delete('Bob') h.print() print('Ming: ' + h.get('Ming')) print(h.keys())
def __init__(self): self._playerToRating = HashMap()
def atualizaFipe(): carsTree = None carrosList = [] carrosMap = {} fipeMap = dicionario.HashMap() fipeURL = "http://fipeapi.appspot.com/api/1/carros/marcas.json" tknzr = WhitespaceTokenizer() chromeOptions = webdriver.ChromeOptions( ) # seta configs pra nao carregar imagens (aumenta velocidade do crawler) prefs = {"profile.managed_default_content_settings.images": 2} chromeOptions.add_experimental_option("prefs", prefs) chromeOptions.add_argument("--incognito") browser = webdriver.Chrome(chrome_options=chromeOptions) browser.get(fipeURL) page_json = soup(browser.page_source, 'html5lib').find("body").find("pre").text filename = 'fipe.csv' f = open(filename, "w") jsonMarcas = json.loads(page_json) mapMarcas = dicionario.HashMap() mapVeiculos = dicionario.HashMap() for marca in jsonMarcas: browser.get('http://fipeapi.appspot.com/api/1/carros/veiculos/' + str(marca['id']) + '.json') time.sleep(1) modelos = soup(browser.page_source, 'html5lib').find("body").find("pre").text modelos = json.loads(modelos) mapMarcas.put(marca["fipe_name"], modelos) for modelo in modelos: print(modelo) modeloNome = tknzr.tokenize(modelo['name']) if modeloNome[0].upper() == "GRAND" or ( len(modeloNome) > 1 and modeloNome[1].upper() == "LOUNGE") or modeloNome[0].upper() == "XC": modeloNome = str(modeloNome[0] + modeloNome[1]) elif modeloNome[0].upper() == "SANTA": modeloNome = str(modeloNome[0] + modeloNome[1][:2]) else: modeloNome = modeloNome[0] modeloNome = modeloNome.upper() modeloNome = modeloNome.replace("-", "") modeloNome = modeloNome.replace("!", "") if modelo['fipe_marca'].upper() == 'VW - VOLKSWAGEN': modelo['fipe_marca'] = 'VOLKSWAGEN' elif modelo['fipe_marca'].upper() == 'GM - CHEVROLET': modelo['fipe_marca'] = 'CHEVROLET' elif modelo['fipe_marca'] == 'Citro\u00ebn': modelo['fipe_marca'] = 'CITROEN' elif modelo['fipe_marca'].upper() == 'KIA MOTORS': modelo['fipe_marca'] = 'KIA' f.write(modelo["fipe_marca"].upper() + "," + str(marca['id']) + "," + modeloNome + "," + modelo["id"] + "\n") with open('fipe.csv', 'r') as f: reader = csv.reader(f) for row in reader: fipeMap.put( str(row[0]) + str(row[2]), str(row[1]) + " " + str(row[3])) #pair(fipeMarca+fipeNome,marcaID+nomeID) with open('carros.csv', 'r') as f: reader = csv.reader(f) for row in reader: chave = str(row[1]) + str(row[2]) + str( row[3]) #fabricante + modelo + ano objId = fipeMap.getObj( str(row[1]) + str(row[2]) ) #guarda objeto com os varios codigos fip para aquele veículo. (vamos precisar iterar ele depois quando formos acessar os dados via selenium) car1 = { "chave": chave, "fabricante": row[1], "modelo": row[2], "ano": row[3], "objID": objId } #tal iteracao é para driblar falta de informacao dos veículos das revendedoras (fipe usa nome completo com especificacoes e as revendedoras nao) if carrosList.count(car1) == 0: carrosList.append(car1) print(len(carrosList)) print(carrosList) i = 0 filename = "carrosEFipe.csv" #abe arquivo para escrita fw = open(filename, "w") for car1 in carrosList: i += 1 print(i) for j in range(1, 4, 1): for ID in car1['objID'].listValues: ID = tknzr.tokenize(str(ID)) marcaID = ID[0] fipeID = ID[1] print("\t" + fipeID) year = str(car1["ano"]) + "-" + str(j) print("\t" + year) time.sleep( 0.5 ) # servidor da api tem limite de requisicoes por minuto browser.get( "http://fipeapi.appspot.com/api/1/carros/veiculo/" + marcaID + "/" + fipeID + "/" + year + ".json") elem = soup(browser.page_source, "html5lib").find("body").find("h1") if elem is not None and elem.text == '500 Internal Server Error': continue else: break if elem is not None and elem.text == '500 Internal Server Error': continue else: carroFipeInfo = soup(browser.page_source, 'html5lib').find("body").find("pre").text carroFipeInfo = json.loads(carroFipeInfo) preco = tknzr.tokenize(carroFipeInfo["preco"]) preco = preco[1] preco = preco[:len(preco) - 3].replace(".", "") print(car1["chave"]) fw.write(car1["chave"] + "," + preco + "\n") break