import requests import urllib3 import json from utils import geoutil import llm_coding def get_geojson(ent, arr, centroid): poly_json = {} poly_json['type'] = 'FeatureCollection' poly_json['features'] = [] coordinates= [] coordinates.append(arr) poly_json['features'].append({ 'type':'Feature', 'id': ent, 'properties': { 'centroid': centroid }, 'geometry': { 'type':'Polygon', 'coordinates': coordinates } }) return poly_json def get_coordinates(ent): request_url = 'https://nominatim.openstreetmap.org/search.php?q= ' +ent +'&polygon_geojson=1&accept-language=en&format=jsonv2' headers = { "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3 Safari/605.1.15" } page = requests.get(request_url, headers=headers, verify=False) json_content = json.loads(page.content) all_coordinates = json_content[0]['geojson']['coordinates'][0] centroid = (float(json_content[0]['lon']), float(json_content[0]['lat'])) for p in all_coordinates: p2 = (p[0], p[1]) angle = geoutil.calculate_bearing(centroid, p2) p.append(angle) geojson = get_geojson(ent, all_coordinates, centroid) return geojson['features'][0]['geometry']['coordinates'][0], geojson['features'][0]['properties']['centroid'] predict_path = 'answer/GPT4o.json' # predict_path = 'dataset/test.json' target_path = 'dataset/dataset_20.json' with open(predict_path, 'r') as f: predit = json.load(f) with open(target_path, 'r') as f: target = json.load(f) result = [] for i in range(len(predit)): # if llm_coding.execute_steps(i['steps']) == print(predit[i]) print(i) try: coord1 = llm_coding.execute_steps(predit[i]['steps']) coord2 = llm_coding.execute_steps(target[i]['steps']) res = coord1[(max(coord1.keys()))][0] == coord2[(max(coord2.keys()))][0] except: res = False result.append(res) print(result) print(result.count(True))