コード例 #1
0
ファイル: views.py プロジェクト: pxian/careercare
def caldistance(queryset_array, individual):
    results = list()
    dist = pgeocode.GeoDistance('MY')
    for i in queryset_array:
        distance = dist.query_postal_code(i.pcode, individual.pcode)
        results.append(distance)
    return results
コード例 #2
0
    def find_by_dist(self):
        # Dist between locations in km.
        MAX_DIST = 250

        # client_details is object like:
        '''
        {
            "ip": "8.8.8.8",
            "city": "Mountain View",
            "region": "California",
            "country": "US",
            "loc": "37.3860,-122.0838",
            "postal": "94035",
            "timezone": "America/Los_Angeles"
        }
        '''

        client_details = get_client_info(self.request)
        pprint.pprint(client_details.all)
        dist = pgeocode.GeoDistance(client_details.country)
        nearby_list = []

        # pgeocode requires that both zips be in same country
        queryset = self.queryset.filter(
            animal__zoo__country=client_details.country)

        # Add object to nearby_list if it is within max distance
        for w in queryset:
            if dist.query_postal_code(w.animal.zoo.zip,
                                      client_details.postal) < MAX_DIST:
                nearby_list.append(w)

        return nearby_list
コード例 #3
0
def dist():
    dist = pgeocode.GeoDistance('PL')
    nomi = pgeocode.Nominatim('PL')
    output3 = nomi.query_postal_code(entry2.get())
    output4 = nomi.query_postal_code(entry3.get())
    output2 = dist.query_postal_code(str(entry2.get()), str(entry3.get()))
    if ((int(len(entry2.get())!=6)) or (int(len(entry3.get())!=6))):
        messagebox.showwarning('', 'Wrong input lenght, please correct it.')
    else:
        label8.config(font=('Courier 13 bold'), text= str(output3[:-1]) + ('\n') + str(output4[:-1]) + ('\n') + ('\n') + 'The distance between these areas is ~' + str(round(output2, 2)) + ' km')
    return output2, output3[:-1], output4[:-1]
コード例 #4
0
ファイル: views.py プロジェクト: pxian/careercare
def nearyou(request):
    results = list()
    Service = apps.get_model('service', 'Service')
    Individual = apps.get_model('employers', 'Individual')
    individual = Individual.objects.get(user_id=request.user.id)
    dist = pgeocode.GeoDistance('MY')
    for i in Service.objects.all():
        distance = dist.query_postal_code(i.pcode, individual.pcode)
        results.append([i, distance])
    results.sort(key=lambda x: x[1])
    return results
コード例 #5
0
def findSitter(request):
    pincode = request.POST.get('pincode')

    dist = pgeocode.GeoDistance("gb")
    users = {}
    # dist.query_postal_code()
    # print(pincode)
    distance = True
    if pincode == None:
        distance = False

    for user in User.objects.filter(owner="0"):
        address = Address.objects.get(userid=user.userid)
        petsitter = PetSitter.objects.get(petSitterId=user.userid)
        users[user.userid] = dict()
        users[user.userid]["firstname"] = user.firstname
        users[user.userid]["lastname"] = user.lastname
        users[user.userid]["email"] = user.email
        if distance:
            users[user.userid]["distance"] = dist.query_postal_code(pincode, address.pincode)
        else:
            users[user.userid]["distance"] = None

        users[user.userid]["street"] = address.street
        users[user.userid]["landmark"] = address.landmark
        users[user.userid]["pincode"] = address.pincode
        users[user.userid]["country"] = address.country
        users[user.userid]["city"] = address.city

        users[user.userid]["dog"] = petsitter.dog
        users[user.userid]["cat"] = petsitter.cat

        users[user.userid]["boarding"] = petsitter.boarding
        users[user.userid]["house_sitting"] = petsitter.house_sitting
        users[user.userid]["doggy_day_care"] = petsitter.doggy_day_care
        users[user.userid]["dog_walking"] = petsitter.dog_walking

        users[user.userid]["boarding_price"] = petsitter.boarding_price
        users[user.userid]["house_sitting_price"] = petsitter.house_sitting_price
        users[user.userid]["doggy_day_care_price"] = petsitter.doggy_day_care_price
        users[user.userid]["dog_walking_price"] = petsitter.dog_walking_price

        users[user.userid]["contact_info"] = petsitter.contact_info

        users[user.userid]["dog_size1"] = petsitter.dog_size1
        users[user.userid]["dog_size2"] = petsitter.dog_size2
        users[user.userid]["dog_size3"] = petsitter.dog_size3
        users[user.userid]["dog_size4"] = petsitter.dog_size4

        users[user.userid]["description"] = petsitter.description
    
    return HttpResponse(json.dumps(users))
コード例 #6
0
def get_distance(zipcode1, zipcode2):
    """Get geodesic distance between 2 given zipcodes
    https://pgeocode.readthedocs.io/en/latest/overview.html

    Args:
        zipcode1 (str): sender 5-digit zipcode
        zipcode2 (str): recipient 5-digit zipcode

    Returns:
            float: distance between zipcodes in miles
    """
    dist = pgeocode.GeoDistance('us')
    return dist.query_postal_code(zipcode1, zipcode2)
コード例 #7
0
def send():
    if request.method == 'POST':
        zipcode = request.form['zipcode']
        dist = pgeocode.GeoDistance('us')
        distance = dist.query_postal_code(str(zipcode), "07747")
        if distance > 55:
            tier = "TIER 3"
        elif distance < 30:
            tier = "TIER 1"
        else:
            tier = "TIER 2"

        return render_template('zipcode.html', zipcode=tier)

    return render_template('index.html')
コード例 #8
0
def match_all(inquiries, helpers):
    # initial setup for GeoDistance
    dist = pgeocode.GeoDistance('DE')

    # in order to distribute the helpers best, we sort them by skill level, so that hospitals with only basic needs
    # get basic helpers first
    helpers.sort(key=lambda x: x.skill_level)

    # output dictionary which will be returned by the method
    # keys are hospitals, values are lists of helpers that are within range
    matching_results = {}

    # list of helpers that are already assigned to a hospital
    assigned_helpers = []

    # the method is triggered when a hospital poses an inquiry
    # this is why we can do it from the perspective of each hospital individually
    for inquiry in inquiries:
        # adding an empty list for the hospital
        hospital = inquiry.hospital
        matching_results[inquiry.id] = []

        # going through all of the helpers
        for helper in helpers:

            # if the helper is already assigned, he shall not get assigned to a second hospital
            if helper.id in assigned_helpers:
                continue

            # if we have enough helpers for the inquiry, we can jump to the next one
            if len(matching_results[inquiry.id]) == inquiry.number_of_helpers:
                break

            # obtaining the distance between the hospital and the helper
            distance = dist.query_postal_code(hospital.post_code,
                                              helper.post_code)

            # if the helper is within distance, he gets added to the list
            # we are also checking if the level of the helper is equal or above what the inquiries needs
            if distance < helper.radius and inquiry.skill_level <= helper.skill_level:
                matching_results[inquiry.id].append(helper.id)
                assigned_helpers.append(helper.id)

    return matching_results
コード例 #9
0
def find_code(postcode1, code_list):
    dist = pgeocode.GeoDistance('AU')
    #postcode1 = '4208'
    #postcode2 = ['4209','3350','3355','3550','3175']
    distance_list = []
    for tempcode in code_list:
        distance = dist.query_postal_code(postcode1, tempcode)
        print(distance)
        distance_list.append(distance)
    m = min(distance_list)
    print(distance_list)

    dis = []
    for i in range(len(distance_list)):
        if distance_list[i] != m:
            dis.append(distance_list[i])

    print("Distance_first", distance_list)
    print("second : ", dis)
    m_second = min(dis)
    print("m_sec", m_second)

    i = 0
    n = 0
    for temp in code_list:
        if dist.query_postal_code(postcode1, temp) == m:
            n = i
            resultcode = temp
            print(i, temp)
            distance = round(distance_list[n], 2)
        i += 1
    i = 0
    n_second = 0
    for temp in code_list:
        if dist.query_postal_code(postcode1, temp) == m_second:
            n_second = i
            result_code_second = temp
            distance_second = round(distance_list[n_second], 2)
            print(i, temp)
        i += 1
    print(n, resultcode, distance, n_second, result_code_second,
          distance_second)
    return n, resultcode, distance, n_second, result_code_second, distance_second
コード例 #10
0
def find_code(postcode1):
    dist = pgeocode.GeoDistance('AU')
    #postcode1 = '4208'
    postcode2 = ['4209', '3350', '3355', '3550', '3175']
    distance_list = []
    for tempcode in postcode2:
        distance = dist.query_postal_code(postcode1, tempcode)
        print(distance)
        distance_list.append(distance)
    m = min(distance_list)

    i = 0
    for temp in postcode2:
        if dist.query_postal_code(postcode1, temp) == m:
            n = i
            resultcode = temp
            print(i, temp)
        i += 1
    return n, resultcode
コード例 #11
0
def zip(zipcode, units, output):
    with open('store-locations.csv') as store_locations:
        reader = csv.DictReader(store_locations)
        distdict = {}
        minrow = {}
        min_list = []
        for row in reader:
            dist = pgeocode.GeoDistance('US')
            distdict[row['Zip Code']] = dist.query_postal_code(
                zipcode, row['Zip Code'][0:5])
        min_value = min(distdict.values())
        min_list = [
            key for key, value in distdict.items() if value == min_value
        ]
        store_locations.seek(0)
        print(min_list[0])
        for row in reader:
            if min_list[0] == row['Zip Code']:
                minrow = row
                break
        printclosest(minrow, output)
コード例 #12
0
def match_indiviual(inquiries, helper):
    # initial setup for GeoDistance
    dist = pgeocode.GeoDistance('DE')
    # checking if the helper is already assigned
    assigned_inquiry = None

    # the method is triggered when a hospital poses an inquiry
    # this is why we can do it from the perspective of each hospital individually
    for inquiry in inquiries:
        hospital = inquiry.hospital

        # obtaining the distance between the hospital and the helper
        distance = dist.query_postal_code(hospital.post_code, helper.post_code)

        # if the helper is within distance, he gets added to the list
        # we are also checking if the level of the helper is equal or above what the inquiries needs
        if distance < helper.radius and inquiry.skill_level <= helper.skill_level:
            assigned_inquiry = inquiry

        # if the helper is already assigned, he shall not get assigned to a second hospital
        if assigned_inquiry:
            return assigned_inquiry

    return None
コード例 #13
0
ファイル: Main.py プロジェクト: kevinrmatheson/ZipCodes
import numpy as np
import uszipcode
import csv
from uszipcode import SearchEngine

ogcodes = pd.read_csv(
    r"C:\Users\Kevin\Downloads\ZipCodeList2020.csv"
)  ###I just grabbed the zipcodes from the wrestlers and output as a list, then paste to the same excel file. Change to your path tho
#ogcodes = ogcodes[0:171]
### CHange it so that zip codes which dont exist spit out 99999 or something###
codes = ogcodes.iloc[:,
                     1]  ###Make sure to make list of all numbers, no blanks (blanks replaced with 00000)
codes = [row.replace("'", "")[0:5] for row in codes]
ogcodes = ogcodes.iloc[:, 0:3]

dist = pgeocode.GeoDistance('us')
zipcodes = pd.DataFrame(columns=['Dist'])
temp = []
for code in codes:
    temp.append(dist.query_postal_code("52001", code))

zipcodes.Dist = temp
zipcodes = 0.621371 * zipcodes.fillna(
    16091.835)  ###Makes it so that NA's give max dist 9999
zipcodes = zipcodes.round(0)
distances = zipcodes.values.tolist()
distance = sum(distances, [])

ogcodes['Distance'] = distance

###Next we find median income per zipcode
コード例 #14
0
ファイル: zipcodes.py プロジェクト: Kcook5400/PythonClassWork
    '2753', '2754', '2755', '2756', '2757', '2758', '2759', '2760', '2761',
    '2762', '2763', '2764', '2765', '2766', '2767', '2768', '2769', '2770',
    '2771', '2772', '2773', '2774', '2775', '2776', '2777', '2778', '2779',
    '2780', '2781', '2782', '2783', '2784', '2785', '2786', '2787', '2788',
    '2789', '2790', '2791', '2792', '2793', '2794', '2795', '2796', '2797',
    '2798', '2799', '2800', '2801', '2802', '2803', '2804', '2805', '2806',
    '2807', '2808', '2809', '2810', '2811', '2812', '2813', '2814', '2815',
    '2816', '2817', '2818', '2819', '2820', '2821', '2922', '2923', '2924',
    '2925', '2926', '4379', '4533', '4800', '4833', '7391', '7392', '7393',
    '7404', '7405', '7406', '7407', '7408', '7409', '7410', '7411', '7412',
    '7413', '7414', '7415', '7416', '7417', '7418', '7419', '7420', '7421',
    '7422', '7423', '7424', '7425', '7426', '7427', '7428', '7429', '7430',
    '7431', '7432', '7433', '7434', '7435', '7436', '7437', '7438', '7439',
    '7440', '7441', '7442', '7443', '7444', '7445', '7446', '7447', '7448',
    '7449', '7450', '7451', '7452', '7453', '7454', '7455', '7456', '7457',
    '7458', '7459', '7461', '7462', '7463', '7464', '7465', '7466', '7468',
    '7470', '7471', '7472', '7473', '7474', '7475', '7476', '7477', '7478',
    '7479'
]
miles_list = []
dist = pgeocode.GeoDistance('US')
i = ""

for x in zips_list:
    miles_list.append((int(dist.query_postal_code('50028', x))))
print(len(net_id_list))
print(len(miles_list))
for i in range(len(net_id_list)):
    print(
        str(net_id_list[i]) + '\t ' + str(miles_list[i]) + '\t' +
        str(zips_list[i]))
コード例 #15
0
df.to_stata(' ')

"""
This part of the code defines the minimum distance of the Swiss Bern Canton from all the zip codes
of the other cantons in Switzerland. 
"""

# the swiss zip codes could be downloaded from the official website https://opendata.swiss/de/dataset/plz_verzeichnis
df = pd.read_excel('plz_verzeichnis_v2.xlsx')

# divide the sample between the Bern canton and the others
be = df[df['kanton'] == "BE"]
nbe = df[df['kanton'] != "BE"]

# prepare the values and empty arrays for the loop
dist = pgeocode.GeoDistance('CH')
zc = be['postleitzahl'].reset_index(drop=True)
zc = list(dict.fromkeys(zc))
nzc = nbe['postleitzahl'].reset_index(drop=True)
nzc = list(dict.fromkeys(nzc))
numbers = np.linspace(0, len(zc), len(zc), endpoint = False).astype(int)
values = np.linspace(0, 0, len(nzc), endpoint = False)
vec=np.linspace(0, 0, len(zc), endpoint = False)

# for every zip code in the non-Bern cantons calculate the distance from every zip code in the Bern canton
# and choose the minimum value
for m in range(len(nzc)):
    num = nzc[m]
    for i in range(len(zc)):
        z = zc[i]
        n = numbers[i]
コード例 #16
0
def zip_code_dist(zip1, zip2):
    """Get distance between two zip codes"""
    dist = pgeocode.GeoDistance('us')
    return dist.query_postal_code(zip1, zip2)
コード例 #17
0
def distance(x, y):
    dist = pgeocode.GeoDistance('US')
    return dist.query_postal_code(str(x), y)
コード例 #18
0
 def __init__(self, df_code, base_code):
     self.df = df_code
     self.dist = pgeocode.GeoDistance('PL')
     self.nomi = pgeocode.Nominatim('PL')
     self.base = base_code
コード例 #19
0
 def get_distance_between_postcodes(org_code, opp_code):
     country = pgeocode.GeoDistance('gb')
     return country.query_postal_code(org_code[:-3], opp_code[:-3])
コード例 #20
0
ファイル: views.py プロジェクト: williamrx05/Sh-reNet
def pdistance(key, postal_code1, postal_code2):
    d = pgeocode.GeoDistance(key)
    return d.query_postal_code(postal_code1, postal_code2)