Beispiel #1
0
def getCost(sourceZip, destinationZip):
    filename = os.path.join(DataPath, 'coordinates.dat')
    with open(filename) as f:
        lines = f.read().splitlines()
    #print(lines)
    i = 1
    while i < len(lines):
        #print(lines[i].split('"')[5],lines[i].split('"')[7],lines[i].split('"')[9])
        zipcode = lines[i].split('"')[1]
        #print(zipcode)
        #print((lines[i].split(' ')[3].split('"')[0]))
        #print(lines[i].split(' ')[4].split('"')[1])
        if zipcode == sourceZip:
            sourceLati = float(lines[i].split('"')[5])
            #print(i,lines[i].split(' "')[3].split('"')[1])
            sourceLongti = float(lines[i].split('"')[7])
            #print(1,sourceLati,sourceLongti)
        if zipcode == destinationZip:
            destLati = float(lines[i].split('"')[5])
            destLongti = float(lines[i].split('"')[7])
            #print(2,destLati,destLongti)
        i += 1
    #distance = (sourceLati-destLati)**2.0+(sourceLongti-destLongti)**2.0
    #cost=distance**0.5
    #print(sourcelongti)
    cost = calculateDistance(tuple([sourceLati, sourceLongti]),
                             tuple([destLati, destLongti]))
    return round(cost * 0.01, 2)
def getCost(sourceZip, destinationZip):
    with open(file, 'r') as fcoord:
        next(fcoord)
        for line in fcoord:
            output = re.search('\"(?P<zip>[0-9A-Z]{5})\"', line)
            #print((output["zip"]))
            #print(type(sourceZip))
            if output["zip"] == sourceZip:
                #print(line)
                #print(output)
                sourcelang = re.search('\"\s?(?P<lang>[0-9]{2}\.[0-9]{6})',
                                       line)
                sourcelat = re.search('\"\s?(?P<lat>[-][0-9]{2,}\.[0-9]{5})\"',
                                      line)
                # print(sourcelang["lang"])
                #print(sourcelat["lat"])
                source1 = tuple(
                    (float(sourcelang["lang"]), float(sourcelat["lat"])))
            #else: source1 = (0,0)
            if output["zip"] == destinationZip:
                #print(line)
                destlang = re.search('\"\s?(?P<lang>[0-9]{2}\.[0-9]{6})', line)
                destlat = re.search('\"\s?(?P<lat>[-][0-9]{2,}\.[0-9]{5})\"',
                                    line)
                dest = tuple((float(destlang["lang"]), float(destlat["lat"])))

        #print(calculateDistance(source, dest))
        #print(sourcelang)
    # if dest != None or source1 != None:
    result = calculateDistance(source1, dest) * 0.01
    print(round(result, 2))
    if dest == None or source1 == None:
        return 0
    return round(result, 2)
Beispiel #3
0
    def __init__(self, company, source, destination):
        self.company = company
        self.source = source
        self.destination = destination
        #print(float(source),float(destination))
        source1 = source.split(',')[0].split("(")[1]
        #print(source1)
        source2 = source.split(',')[1].split(")")[0].split(' ')[1]
        #print(source2)
        source3 = tuple([float(source1), float(source2)])

        destination1 = destination.split(',')[0].split("(")[1]
        #print(source1)
        destination2 = destination.split(',')[1].split(")")[0].split(' ')[1]
        #print(source2)
        destination3 = tuple([float(destination1), float(destination2)])

        self.cost = round(calculateDistance(source3, destination3), 2)
Beispiel #4
0
def getCost(sourceZip: str, destinationZip:str):
    DataText = os.path.join(DataPath, 'coordinates.dat')
    with open(DataText, "r") as f:
        data = [line.split(',') for line in f.read().splitlines()]
    lat1 = 0.0
    lat2 = 0.0
    lon1 = 0.0
    lon2 = 0.0
    for item in data[1:]:
        if sourceZip in item[0]:
            lat1  = item[2].strip().replace(' ', '').replace('"', '')
            lon1 = item[3].strip().replace(' ', '').replace('"', '')
        elif destinationZip in item[0]:
            lat2 = item[2].strip().replace(' ', '').replace('"', '')
            lon2 = item[3].strip().replace(' ', '').replace('"', '')

    dist = calculateDistance((float(lat1),float(lon1)), (float(lat2), float(lon2)))
    cost = dist * 0.01
    return round(cost, 2)
Beispiel #5
0
def getCost(sourceZip, destinationZip):
    szip = sourceZip
    dzip = destinationZip
    coord_path = 'coordinates.dat'
    coord_path = os.path.join(DataPath, coord_path)
    with open(coord_path) as file:
        reader = csv.DictReader(file, delimiter=',')
        la = [row[' "latitude"'] for row in reader]
    with open(coord_path) as file:
        reader = csv.DictReader(file, delimiter=',')
        lo = [row[' "longitude"'] for row in reader]
    with open(coord_path) as file:
        reader = csv.DictReader(file, delimiter=',')
        zip = [row['zip code'] for row in reader]
    with open(coord_path) as file:
        reader = csv.DictReader(file, delimiter=',')
        stateab = [row[' "state abbreviation"'] for row in reader]
    with open(coord_path) as file:
        reader = csv.DictReader(file, delimiter=',')
        city = [row[' "city"'] for row in reader]
    with open(coord_path) as file:
        reader = csv.DictReader(file, delimiter=',')
        state = [row[' "state"'] for row in reader]

    if sourceZip not in zip:
        return 0.00
    if destinationZip not in zip:
        return 0.00
    splace = zip.index(sourceZip)
    dplace = zip.index(destinationZip)
    szip = (float(la[splace][2:len(la[splace]) - 1]),
            float(lo[splace][2:len(lo[splace]) - 1]))
    dzip = (float(la[dplace][2:len(la[dplace]) - 1]),
            float(lo[dplace][2:len(lo[dplace]) - 1]))
    cost = measurement.calculateDistance(szip, dzip)
    cost = round(cost / 100, 2)
    return cost
    def __init__(self, source, destination):
        self.source = str(source)
        self.destination = str(destination)

        self.cost = round(calculateDistance(source, destination), 2)
 def calculateLength(self, locationMap):
     totalDis = 0
     for leg in self.legs:
         totalDis += calculateDistance(locationMap[leg.szip],
                                       locationMap[leg.dzip])
     return round(totalDis, 2)
 def calculateLength(self, locationMap):
     return round(
         calculateDistance(locationMap[self.szip], locationMap[self.dzip]),
         2)