Skip to content
Snippets Groups Projects
Commit e59800a4 authored by Riccardo Boero's avatar Riccardo Boero :innocent:
Browse files

Removed Hawaii fix and added management of missing responses in travel times

parent 27236e60
No related branches found
No related tags found
No related merge requests found
......@@ -28,17 +28,6 @@ function travel_time_in_minutes(ws_host_port::String, selection::Dict)
geo_id = selection["geo_id"]
shape_obj = selection["shape_obj"]
# filter out Hawaii
# Convert geo_id to integers
geo_id_int = parse.(Int, geo_id)
# Apply the range condition
condition = (geo_id_int .>= 15000) .& (geo_id_int .< 16000)
# Overwrite the original arrays with the filtered results
geo_id = geo_id[.!condition]
shape_obj = shape_obj[.!condition]
# Arrays to store column data
o_geo_ids = String[]
d_geo_ids = String[]
......@@ -59,13 +48,23 @@ function travel_time_in_minutes(ws_host_port::String, selection::Dict)
# Construct the request URL
url = "$ws_host_port/route/v1/driving/$(start_longitude),$(start_latitude);$(end_longitude),$(end_latitude)?overview=false"
# Make the request
response = HTTP.get(url)
# Parse the response
data = JSON.parse(String(response.body))
# Extract and calculate travel time in minutes
travel_time_seconds = data["routes"][1]["duration"]
travel_time = travel_time_seconds / 60
try
# Make the request
response = HTTP.get(url)
# Ensure the response status code is 200 (OK)
if response.status != 200
throw(Exception("Request failed with status code $(response.status)"))
end
# Parse the response
data = JSON.parse(String(response.body))
# Extract and calculate travel time in minutes
travel_time_seconds = data["routes"][1]["duration"]
travel_time = travel_time_seconds / 60
catch e
println("Error during HTTP request or response parsing: ", e)
travel_time = nothing # Use `nothing` to represent null in Julia
end
# Populate the columns
push!(o_geo_ids, geo_id[i])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment