<jupyter_start><jupyter_text>Time Matrix Processing<jupyter_code>import requests
import math
import pprint
import time
import numpy as np
import pandas as pd<jupyter_output><empty_output><jupyter_text>Station to Station<jupyter_code>headers = {
    'Accept': 'application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8',
    #'Authorization': '5b3ce3597851110001cf624884518d9d4075408e95e3401165976247',
    'Authorization': '5b3ce3597851110001cf62485eef3a0ab19d4b3e8ad2d8c88dca3d19',
    'Content-Type': 'application/json; charset=utf-8'
}
stations = pd.read_csv('ems_stations.csv')  
print(stations.head())
station_coords = [[x,y] for x,y in zip(stations['longitude'], stations['latitude'])]
pprint.pprint(station_coords)
body = {"locations": station_coords}
call = requests.post('https://api.openrouteservice.org/v2/matrix/driving-car', json=body, headers=headers)
#print(call.json())
durations = call.json()['durations']
#pprint.pprint(durations)
np.savetxt("s2s_time_matrix.csv", np.array(durations), delimiter=",", fmt="%s")
# Build output csv from time matrix
result = pd.read_csv('s2s_time_matrix.csv', header=None)
#print(result.head())

_, num_rows = result.shape

headers = ["stn{}_min".format(i) for i in range(1, num_rows+1)]
#print(headers)

result.columns = headers
#print(result.head())

# Add columns
result['STATION_NAME'] = stations['station_name']
result['LONGITUDE'] = stations['longitude']
result['LATITUDE'] = stations['latitude']
result['OBJECTID_1'] = list(range(1, num_rows+1))

print(result.head())
# Export result to csv
result.to_csv("s2s_formatted.csv", index=False)<jupyter_output><empty_output><jupyter_text>Hospital to Station<jupyter_code>hospitals = pd.read_csv("ems_hospitals.csv")
print(hospitals.head())
hospital_coords = [[x,y] for x,y in zip(hospitals['longitude'], hospitals['latitude'])]
pprint.pprint(station_coords)
# Prep for API call
locations = hospital_coords + station_coords
#print(locations)

num_hospitals = len(hospital_coords)
num_stations = len(station_coords)

sources = [i for i in range(num_hospitals)]
destinations = [i + num_hospitals for i in range(num_stations)]

#print(sources)
#print(destinations)
body = {"locations": locations, "sources": sources, "destinations": destinations}
call = requests.post('https://api.openrouteservice.org/v2/matrix/driving-car', json=body, headers=headers)
#print(call.json())
durations = call.json()['durations']
#pprint.pprint(durations)
np.savetxt("h2s_time_matrix.csv", np.array(durations), delimiter=",", fmt="%s")
# Build output csv from time matrix
result = pd.read_csv('h2s_time_matrix.csv', header=None)
#print(result.head())

_, num_rows = result.shape

headers = ["stn{}_min".format(i) for i in range(1, num_stations+1)]
#print(headers)

result.columns = headers
print(result)

# Add columns
result['HOSPITAL_NAME'] = hospitals['hospital_name']
result['LONGITUDE'] = hospitals['longitude']
result['LATITUDE'] = hospitals['latitude']
result['OBJECTID_1'] = list(range(1, num_hospitals+1))

print(result.head())
# Export result to csv
result.to_csv("h2s_formatted.csv", index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15573248407643311, 'fraction_numerical': 0.0321656050955414, 'mean_word_length': 8.238235294117647, 'pattern_counts': {'":': 4, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '522939', 'license': 'MIT', 'n_tokens_mistral': 1205, 'n_tokens_neox': 1145, 'n_words': 199, 'path': 'Open_Street_Map/data-prep/Time Matrix Processing.ipynb', 'repo_name': 'michaelhilborn/AmbulanceDeployement', 'size': '3140'}