Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
FACT Data API Reader
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FACT
FACT Utils
FACT Data API Reader
Commits
e59800a4
Commit
e59800a4
authored
1 year ago
by
Riccardo Boero
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/FACT_road.jl
+17
-18
17 additions, 18 deletions
src/FACT_road.jl
with
17 additions
and
18 deletions
src/FACT_road.jl
+
17
−
18
View file @
e59800a4
...
...
@@ -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
])
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment