Delete tools/googleDistanceMatrix/build_database.py
Browse files
tools/googleDistanceMatrix/build_database.py
DELETED
@@ -1,75 +0,0 @@
|
|
1 |
-
from apis import GoogleDistanceMatrix
|
2 |
-
import os
|
3 |
-
import json
|
4 |
-
from tqdm import tqdm
|
5 |
-
import csv
|
6 |
-
|
7 |
-
os.environ["http_proxy"] = "http://127.0.0.1:7890"
|
8 |
-
os.environ["https_proxy"] = "http://127.0.0.1:7890"
|
9 |
-
gdm = GoogleDistanceMatrix()
|
10 |
-
|
11 |
-
# print(gdm.run_for_build_database("New York","Seattle"))
|
12 |
-
|
13 |
-
|
14 |
-
def load_line_json_data(filename):
|
15 |
-
data = []
|
16 |
-
with open(filename, 'r', encoding='utf-8') as f:
|
17 |
-
for line in f.read().strip().split('\n'):
|
18 |
-
unit = json.loads(line)
|
19 |
-
data.append(unit)
|
20 |
-
return data
|
21 |
-
|
22 |
-
|
23 |
-
def get_city_list(days, deparure_city, destination):
|
24 |
-
city_list = []
|
25 |
-
city_list.append(deparure_city)
|
26 |
-
if days == 3:
|
27 |
-
city_list.append(destination)
|
28 |
-
else:
|
29 |
-
city_set = open('/home/xj/toolAugEnv/code/toolConstraint/database/background/citySet_with_states.txt').read().split('\n')
|
30 |
-
state_city_map = {}
|
31 |
-
for unit in city_set:
|
32 |
-
city, state = unit.split('\t')
|
33 |
-
if state not in state_city_map:
|
34 |
-
state_city_map[state] = []
|
35 |
-
state_city_map[state].append(city)
|
36 |
-
for city in state_city_map[destination]:
|
37 |
-
if city != deparure_city:
|
38 |
-
city_list.append(city + f"({destination})")
|
39 |
-
return city_list
|
40 |
-
|
41 |
-
if __name__ == '__main__':
|
42 |
-
|
43 |
-
org_dest_list = []
|
44 |
-
query_list =load_line_json_data('/home/xj/toolAugEnv/code/toolConstraint/data/query/all.jsonl')
|
45 |
-
info_list = []
|
46 |
-
|
47 |
-
for query in tqdm(query_list):
|
48 |
-
|
49 |
-
destination_city_list = get_city_list(query['days'],query['org'],query['dest'])
|
50 |
-
|
51 |
-
# for city in destination_city_list:
|
52 |
-
# if [query['org'],city] not in org_dest_list:
|
53 |
-
# org_dest_list.append([query['org'],city])
|
54 |
-
# info_list.append(gdm.run_for_build_database(query['org'],city))
|
55 |
-
# if [city,query['org']] not in org_dest_list:
|
56 |
-
# org_dest_list.append([city,query['org']])
|
57 |
-
# info_list.append(gdm.run_for_build_database(city,query['org']))
|
58 |
-
|
59 |
-
|
60 |
-
for city_1 in tqdm(destination_city_list):
|
61 |
-
for city_2 in destination_city_list:
|
62 |
-
if city_1 != city_2 and [city_1,city_2] not in org_dest_list:
|
63 |
-
org_dest_list.append([city_1,city_2])
|
64 |
-
info_list.append(gdm.run_for_build_database(city_1,city_2))
|
65 |
-
|
66 |
-
# # write to csv file
|
67 |
-
# # example:{'origin': 'New York', 'destination': 'Seattle', 'cost': None, 'duration': '1 day 18 hours', 'distance': '4,589 km'}
|
68 |
-
with open('/home/xj/toolAugEnv/code/toolConstraint/database/background/distance.csv', 'w', newline='') as csvfile:
|
69 |
-
fieldnames = ['origin', 'destination', 'cost', 'duration', 'distance']
|
70 |
-
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
|
71 |
-
writer.writeheader()
|
72 |
-
for unit in info_list:
|
73 |
-
writer.writerow(unit)
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|