def getStore(uuid):
    store = json.load(open("raw_data/raw_" + uuid + ".txt"))['data']
    if store.get("code") == 500:
        print("Error: ", uuid)
        return
    if not store.get("location"):
        print("Error Address: ", uuid)
        return
    code = store["location"].get("postalCode")
    if not code or len(str(code)) < 3:
        loc = store.get("location").get("address")
        code = zipcodetw.find(loc)
    if not code or len(str(code)) < 3:
        loc_strip = re_word.findall(loc)[0]
        loc_strip = loc_strip.replace("台灣", "")
        code = zipcodetw.find(loc_strip)
    if not code or len(str(code)) < 3:
        code = re_word_code.findall(loc)
        if len(code):
            code = code[0]
    if code and len(str(code)) < 3:
        print("Error postcode digit: ", code, loc, uuid)
        return
    if not code:
        print("Error postcode: ", loc, uuid)
        return
    code = int(str(code)[:3])
    # debug
    # return
    rate = 0
    rate_num = 0
    if store["ratingBadge"]:
        rate = store["ratingBadge"][0]["children"][0]["text"]
        rate_num = re.findall(r"\d+", store["ratingBadge"][0]["children"][2]["text"])[0]
        # print("Error rate: ", uuid)
    if len(store["categories"]) != 2:
        print("Error categories number: ", uuid)
        return
    prices = [j["price"] for _, i in store["sectionEntitiesMap"].items() for _, j in i.items()]
    try:
        now_dict = {
            "uuid": uuid,
            "city": store["citySlug"],
            "postcode": code,
            "rate": rate,
            "rate_num": rate_num,
            "food_num": len(prices),
            "food_mean": np.mean(prices),
            "food_q1": np.quantile(prices, 0.25),
            "food_q2": np.quantile(prices, 0.50),
            "food_q3": np.quantile(prices, 0.75),
            "food_var": np.std(prices),
            "category": store["categories"][1],
            "money": store["categories"][0],
        }
    except:
        pprint(store)
        raise
    all_stores.append(now_dict)
Beispiel #2
0
def FillACPAAA016(df):
    #print(df["郵遞區號"])
    indexcol = int(df.columns.get_loc("郵遞區號")) 
    for index,row in df.iterrows():
        if (row.郵遞區號 == '' or row.郵遞區號 == None):
            df.iloc[index,indexcol] = str(zipcodetw.find(row.地址))
    return df
Beispiel #3
0
 def updateZipCode(self, text):
     code = zipcodetw.find(text)
     self.oField.setText(' '.join([code, text]))
Beispiel #4
0
def test_find():

    zipcodetw.find('台北市')
    zipcodetw.find('台北市中正區')
    zipcodetw.find('台北市中正區仁愛路')
    zipcodetw.find('台北市中正區仁愛路2段')
    zipcodetw.find('台北市中正區仁愛路2段45號')

    zipcodetw.find('台中市')
    zipcodetw.find('台中市中區')
    zipcodetw.find('台中市中區台灣大道')
    zipcodetw.find('台中市中區台灣大道1段')
    zipcodetw.find('台中市中區台灣大道1段239號')

    zipcodetw.find('臺南市')
    zipcodetw.find('臺南市中西區')
    zipcodetw.find('臺南市中西區府前路')
    zipcodetw.find('臺南市中西區府前路1段')
    zipcodetw.find('臺南市中西區府前路1段226號')
Beispiel #5
0
def api_find():
    return jsonify(result=zipcodetw.find(request.values.get('address')))
def api_find():
    return jsonify(result=zipcodetw.find(request.values.get('address')))
Beispiel #7
0
import pandas as pd
import zipcodetw
# make sure python3 -m zipcodetw.builder

postcode = pd.read_csv("data/postcode.csv")
data = pd.read_csv("download/NPA_TMA2.csv")
data.insert(2, "postcode", -1, True)

for i in range(len(data)):
    print(i)
    loc = data.iloc[i]["發生地點"]
    if pd.isna(loc):
        continue
    code = zipcodetw.find(loc)
    code = code[:3]
    if 100 <= int(code) < 200:
        data.at[i, "postcode"] = int(code)
data = data[data["postcode"] != -1]
data.to_csv("data/crash.csv", index=False)
print(data)

new_data = []
data = pd.read_csv("data/crash.csv")
codes = set(data["postcode"])
for code in codes:
    if code >= 200 or code < 100:
        continue
    new_data.append({"postcode": code, "num": sum(data["postcode"] == code)})

new_data = pd.DataFrame(new_data)
new_data.to_csv("data/crash_num.csv", index=False)
Beispiel #8
0
def test_find():

    zipcodetw.find('台北市')
    zipcodetw.find('台北市中正區')
    zipcodetw.find('台北市中正區仁愛路')
    zipcodetw.find('台北市中正區仁愛路2段')
    zipcodetw.find('台北市中正區仁愛路2段45號')

    zipcodetw.find('台中市')
    zipcodetw.find('台中市中區')
    zipcodetw.find('台中市中區台灣大道')
    zipcodetw.find('台中市中區台灣大道1段')
    zipcodetw.find('台中市中區台灣大道1段239號')

    zipcodetw.find('臺南市')
    zipcodetw.find('臺南市中西區')
    zipcodetw.find('臺南市中西區府前路')
    zipcodetw.find('臺南市中西區府前路1段')
    zipcodetw.find('臺南市中西區府前路1段226號')
def main():
    return zipcodetw.find(sys.argv[1])