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

Added treatment of errors in elevation data and of missing job info in jobs

parent 0c58da39
No related branches found
No related tags found
No related merge requests found
......@@ -30,28 +30,55 @@ function elevation_data_full(ws_host_port::String, selection::Dict)
mean_elevations = Float64[]
std_elevations = Float64[]
median_elevations = Float64[]
entropy_elevations = Float64[]
entropy_elevations = Float64[]
for (id, shape) in zip(geo_id, shape_obj)
# setting starting values to missing
min_elevation = missing
max_elevation = missing
mean_elevation = missing
std_elevation = missing
median_elevation = missing
entropy_elevation = missing
# Construct the JSON payload
json_payload = JSON.json(Dict("polygon_wkt" => shape))
# Construct the URL
url = "$ws_host_port/band_statistics"
# Set headers for JSON content type
headers = Dict("Content-Type" => "application/json")
# Make the POST request
response = HTTP.post(url, headers, json_payload)
# Parse the response
data = JSON.parse(String(response.body))
# Access the nested dictionary for band_0
band_data = data["band_0"]
# extract relevant info
try
# Make the POST request
response = HTTP.post(url, headers, json_payload)
# 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))
# Access the nested dictionary for band_0
band_data = data["band_0"]
# extract relevant info
min_elevation = band_data["min"][1]
max_elevation = band_data["max"][1]
mean_elevation = band_data["mean"][1]
std_elevation = band_data["std"][1]
median_elevation = band_data["median"][1]
entropy_elevation = band_data["entropy"][1]
catch e
println("Error during HTTP request or response parsing: ", e)
end
# update info
push!(geo_ids, id)
push!(min_elevations, band_data["min"][1])
push!(max_elevations, band_data["max"][1])
push!(mean_elevations, band_data["mean"][1])
push!(std_elevations, band_data["std"][1])
push!(median_elevations, band_data["median"][1])
push!(entropy_elevations, band_data["entropy"][1])
push!(min_elevations, min_elevation)
push!(max_elevations, max_elevation)
push!(mean_elevations, mean_elevation)
push!(std_elevations, std_elevation)
push!(median_elevations, median_elevation)
push!(entropy_elevations, entropy_elevation)
end
# object to be returned
dftemp = DataFrame(
......
......@@ -99,6 +99,12 @@ function us_qcew(conn::MySQL.Connection, selection::Dict)
query = "SELECT Naics as industry, (Jan_jobs+Feb_jobs+Mar_jobs+Apr_jobs+May_jobs+Jun_jobs+Jul_jobs+Aug_jobs+Sep_jobs+Oct_jobs+Nov_jobs+Dec_jobs)/12 as jobs FROM QCEW WHERE Year = "*string(year)*" AND GeoID = '"*full_id*"' AND Agglvl_code = "*string(agglvl_code)*";"
# execute
result = query_connection(conn, query)
# Check if the 'industry' column exists
if !(:industry in names(result))
println("No data returned for query with GeoID = $full_id and Year = $year and AND Agglvl_code = $agglvl_code.")
# Initialize `result` with the expected columns but no rows
result = DataFrame(industry = String[], jobs = Float64[], geo_id = String[], agg_level = Int[])
end
# add geo_id col
result[!, :geo_id] = fill(id, nrow(result))
# add agg level
......
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