perfil ja modificat correctament
This commit is contained in:
parent
a3d659e10c
commit
4e999f6ca1
@ -8,7 +8,6 @@ Set = require('lib/set')
|
|||||||
Sequence = require('lib/sequence')
|
Sequence = require('lib/sequence')
|
||||||
Handlers = require("lib/way_handlers")
|
Handlers = require("lib/way_handlers")
|
||||||
find_access_tag = require("lib/access").find_access_tag
|
find_access_tag = require("lib/access").find_access_tag
|
||||||
local pollution = 0
|
|
||||||
|
|
||||||
function fetch_pollution_data(location)
|
function fetch_pollution_data(location)
|
||||||
-- Convert location userdata to a string
|
-- Convert location userdata to a string
|
||||||
@ -30,22 +29,20 @@ function fetch_pollution_data(location)
|
|||||||
return 0 -- Return 0 if the format is invalid
|
return 0 -- Return 0 if the format is invalid
|
||||||
end
|
end
|
||||||
|
|
||||||
if lat > 41.320 and lat < 41.469 and lon > 2.069 and lon < 2.228 then
|
|
||||||
-- Fetch pollution data
|
-- Fetch pollution data
|
||||||
local url = string.format("http://localhost:8008/routes/api/pollution?lat=%f&lon=%f", lat, lon)
|
local url = string.format("http://localhost:8008/routes/api/pollution?lat=%f&lon=%f", lat, lon)
|
||||||
local response, status = http.request(url)
|
local response, status = http.request(url)
|
||||||
|
|
||||||
if status == 200 then
|
if status == 200 then
|
||||||
local data = json.decode(response)
|
local data = json.decode(response)
|
||||||
return data.pollution -- Return the pollution weight from the backend
|
return data.pollution -- Return the pollution weight from the backend
|
||||||
else
|
else
|
||||||
print("Failed to fetch pollution data. HTTP status: " .. tostring(status))
|
print("Failed to fetch pollution data. HTTP status: " .. tostring(status))
|
||||||
return 0 -- Return 0 if the request fails
|
return 0 -- Return 0 if the request fails
|
||||||
end
|
end
|
||||||
end
|
|
||||||
return 0
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function setup()
|
function setup()
|
||||||
local walking_speed = 5
|
local walking_speed = 5
|
||||||
return {
|
return {
|
||||||
@ -195,12 +192,10 @@ function process_node(profile, node, result)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
local location = node:location()
|
local location = node:location()
|
||||||
pollution = fetch_pollution_data(location)
|
local pollution = fetch_pollution_data(location)
|
||||||
if pollution > 50 then
|
if pollution > 100 then
|
||||||
result.barrier = true
|
result.barrier = true
|
||||||
end
|
end
|
||||||
--print(pollution)
|
|
||||||
--result.weight = result.weight + pollution
|
|
||||||
|
|
||||||
|
|
||||||
-- check if node is a traffic light
|
-- check if node is a traffic light
|
||||||
@ -235,8 +230,6 @@ function process_way(profile, way, result)
|
|||||||
print("Error: way is nil.")
|
print("Error: way is nil.")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
print(result.weight)
|
|
||||||
result.weight = result.weight + pollution
|
|
||||||
|
|
||||||
|
|
||||||
-- perform an quick initial check and abort if the way is
|
-- perform an quick initial check and abort if the way is
|
||||||
|
Loading…
Reference in New Issue
Block a user