From 4e999f6ca14b92851b62729ba6d7a05644ca36c4 Mon Sep 17 00:00:00 2001 From: raulolivar Date: Mon, 16 Dec 2024 01:04:32 +0000 Subject: [PATCH] perfil ja modificat correctament --- profiles/foot.lua | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/profiles/foot.lua b/profiles/foot.lua index 41db52ab9..fd0dc77fb 100644 --- a/profiles/foot.lua +++ b/profiles/foot.lua @@ -8,7 +8,6 @@ Set = require('lib/set') Sequence = require('lib/sequence') Handlers = require("lib/way_handlers") find_access_tag = require("lib/access").find_access_tag -local pollution = 0 function fetch_pollution_data(location) -- Convert location userdata to a string @@ -30,22 +29,20 @@ function fetch_pollution_data(location) return 0 -- Return 0 if the format is invalid end - if lat > 41.320 and lat < 41.469 and lon > 2.069 and lon < 2.228 then -- Fetch pollution data local url = string.format("http://localhost:8008/routes/api/pollution?lat=%f&lon=%f", lat, lon) local response, status = http.request(url) if status == 200 then - local data = json.decode(response) - return data.pollution -- Return the pollution weight from the backend + local data = json.decode(response) + return data.pollution -- Return the pollution weight from the backend else - print("Failed to fetch pollution data. HTTP status: " .. tostring(status)) - return 0 -- Return 0 if the request fails + print("Failed to fetch pollution data. HTTP status: " .. tostring(status)) + return 0 -- Return 0 if the request fails end - end - return 0 end + function setup() local walking_speed = 5 return { @@ -195,12 +192,10 @@ function process_node(profile, node, result) end end local location = node:location() - pollution = fetch_pollution_data(location) - if pollution > 50 then + local pollution = fetch_pollution_data(location) + if pollution > 100 then result.barrier = true end - --print(pollution) - --result.weight = result.weight + pollution -- check if node is a traffic light @@ -235,8 +230,6 @@ function process_way(profile, way, result) print("Error: way is nil.") return end - print(result.weight) - result.weight = result.weight + pollution -- perform an quick initial check and abort if the way is