From 3c903ddffd8278ae78c3a37cb7a5f7804d61c444 Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Thu, 27 Sep 2012 11:35:56 +0200 Subject: [PATCH] clean up duplicated lua profiles --- features/support/config.rb | 2 +- profile.lua | 212 +----------------------- {test/profiles => profiles}/bicycle.lua | 0 {test/profiles => profiles}/car.lua | 67 +++++--- {test/profiles => profiles}/foot.lua | 0 5 files changed, 44 insertions(+), 237 deletions(-) mode change 100644 => 120000 profile.lua rename {test/profiles => profiles}/bicycle.lua (100%) rename {test/profiles => profiles}/car.lua (81%) rename {test/profiles => profiles}/foot.lua (100%) diff --git a/features/support/config.rb b/features/support/config.rb index 7ed7443b0..a110488e3 100644 --- a/features/support/config.rb +++ b/features/support/config.rb @@ -12,7 +12,7 @@ def read_speedprofile profile end def write_speedprofile - FileUtils.copy_file "profiles/#{@speedprofile}.lua", "profile.lua" + FileUtils.copy_file "../profiles/#{@speedprofile}.lua", "profile.lua" end def write_server_ini diff --git a/profile.lua b/profile.lua deleted file mode 100644 index ce8ff383c..000000000 --- a/profile.lua +++ /dev/null @@ -1,211 +0,0 @@ --- Begin of globals - -bollards_whitelist = { [""] = true, ["cattle_grid"] = true, ["border_control"] = true, ["toll_booth"] = true, ["no"] = true, ["sally_port"] = true, ["gate"] = true} -access_tag_whitelist = { ["yes"] = true, ["motorcar"] = true, ["motor_vehicle"] = true, ["vehicle"] = true, ["permissive"] = true, ["designated"] = true } -access_tag_blacklist = { ["no"] = true, ["private"] = true, ["agricultural"] = true, ["forestery"] = true } -access_tag_restricted = { ["destination"] = true, ["delivery"] = true } -access_tags = { "motorcar", "motor_vehicle", "vehicle" } -service_tag_restricted = { ["parking_aisle"] = true } -ignore_in_grid = { ["ferry"] = true, ["pier"] = true } - -speed_profile = { - ["motorway"] = 90, - ["motorway_link"] = 75, - ["trunk"] = 85, - ["trunk_link"] = 70, - ["primary"] = 65, - ["primary_link"] = 60, - ["secondary"] = 55, - ["secondary_link"] = 50, - ["tertiary"] = 40, - ["tertiary_link"] = 30, - ["unclassified"] = 25, - ["residential"] = 25, - ["living_street"] = 10, - ["service"] = 15, --- ["track"] = 5, - ["ferry"] = 5, - ["pier"] = 5, - ["default"] = 50 -} - -take_minimum_of_speeds = true -obey_oneway = true -obey_bollards = true -use_restrictions = true -ignore_areas = true -- future feature -traffic_signal_penalty = 2 -u_turn_penalty = 20 - --- End of globals - -function node_function (node) - local barrier = node.tags:Find ("barrier") - local access = node.tags:Find ("access") - local traffic_signal = node.tags:Find("highway") - - --flag node if it carries a traffic light - - if traffic_signal == "traffic_signals" then - node.traffic_light = true; - end - - if access_tag_blacklist[barrier] then - node.bollard = true; - end - - if "" ~= barrier then - if obey_bollards then - --flag node as unpassable if it black listed as unpassable - node.bollard = true; - end - --reverse the previous flag if there is an access tag specifying entrance - if node.bollard and bollards_whitelist[barrier] and access_tag_whitelist[barrier] then - node.bollard = false; - return 1 - end - -- Check if our vehicle types are allowd to pass the barrier - for i,v in ipairs(access_tags) do - local mode_value = node.tags:Find(v) - if nil ~= mode_value and "yes" == mode_value then - node.bollard = false - return - end - end - else - -- Check if our vehicle types are forbidden to pass the node - for i,v in ipairs(access_tags) do - local mode_value = node.tags:Find(v) - if nil ~= mode_value and "no" == mode_value then - node.bollard = true - return 1 - end - end - end - return 1 -end - -function way_function (way, numberOfNodesInWay) - - -- A way must have two nodes or more - if(numberOfNodesInWay < 2) then - return 0; - end - - -- First, get the properties of each way that we come across - local highway = way.tags:Find("highway") - local name = way.tags:Find("name") - local ref = way.tags:Find("ref") - local junction = way.tags:Find("junction") - local route = way.tags:Find("route") - local maxspeed = parseMaxspeed(way.tags:Find ( "maxspeed") ) - local man_made = way.tags:Find("man_made") - local barrier = way.tags:Find("barrier") - local oneway = way.tags:Find("oneway") - local cycleway = way.tags:Find("cycleway") - local duration = way.tags:Find("duration") - local service = way.tags:Find("service") - local area = way.tags:Find("area") - local access = way.tags:Find("access") - - -- Second parse the way according to these properties - - if ignore_areas and ("yes" == area) then - return 0 - end - - -- Check if we are allowed to access the way - if access_tag_blacklist[access] ~=nil and access_tag_blacklist[access] then - return 0; - end - - -- Check if our vehicle types are forbidden - for i,v in ipairs(access_tags) do - local mode_value = way.tags:Find(v) - if nil ~= mode_value and "no" == mode_value then - return 0; - end - end - - - -- Set the name that will be used for instructions - if "" ~= ref then - way.name = ref - elseif "" ~= name then - way.name = name - end - - if "roundabout" == junction then - way.roundabout = true; - end - - -- Handling ferries and piers - - if (speed_profile[route] ~= nil and speed_profile[route] > 0) or - (speed_profile[man_made] ~= nil and speed_profile[man_made] > 0) - then - if durationIsValid(duration) then - way.speed = math.max( duration / math.max(1, numberOfNodesInWay-1) ); - way.is_duration_set = true; - end - way.direction = Way.bidirectional; - if speed_profile[route] ~= nil then - highway = route; - elseif speed_profile[man_made] ~= nil then - highway = man_made; - end - if not way.is_duration_set then - way.speed = speed_profile[highway] - end - - end - - -- Set the avg speed on the way if it is accessible by road class - if (speed_profile[highway] ~= nil and way.speed == -1 ) then - if (0 < maxspeed and not take_minimum_of_speeds) or (maxspeed == 0) then - maxspeed = math.huge - end - way.speed = math.min(speed_profile[highway], maxspeed) - end - - -- Set the avg speed on ways that are marked accessible - if access_tag_whitelist[access] and way.speed == -1 then - if (0 < maxspeed and not take_minimum_of_speeds) or maxspeed == 0 then - maxspeed = math.huge - end - way.speed = math.min(speed_profile["default"], maxspeed) - end - - -- Set access restriction flag if access is allowed under certain restrictions only - if access ~= "" and access_tag_restricted[access] then - way.is_access_restricted = true - end - - -- Set access restriction flag if service is allowed under certain restrictions only - if service ~= "" and service_tag_restricted[service] then - way.is_access_restricted = true - end - - -- Set direction according to tags on way - if obey_oneway then - if oneway == "no" or oneway == "0" or oneway == "false" then - way.direction = Way.bidirectional - elseif oneway == "-1" then - way.direction = Way.opposite - elseif oneway == "yes" or oneway == "1" or oneway == "true" or junction == "roundabout" or highway == "motorway_link" or highway == "motorway" then - way.direction = Way.oneway - else - way.direction = Way.bidirectional - end - else - way.direction = Way.bidirectional - end - - -- Override general direction settings of there is a specific one for our mode of travel - - if ignore_in_grid[highway] ~= nil and ignore_in_grid[highway] then - way.ignore_in_grid = true - end - way.type = 1 - return 1 -end diff --git a/profile.lua b/profile.lua new file mode 120000 index 000000000..bad7e6bb5 --- /dev/null +++ b/profile.lua @@ -0,0 +1 @@ +profiles/car.lua \ No newline at end of file diff --git a/test/profiles/bicycle.lua b/profiles/bicycle.lua similarity index 100% rename from test/profiles/bicycle.lua rename to profiles/bicycle.lua diff --git a/test/profiles/car.lua b/profiles/car.lua similarity index 81% rename from test/profiles/car.lua rename to profiles/car.lua index 8e87b43f7..ce8ff383c 100644 --- a/test/profiles/car.lua +++ b/profiles/car.lua @@ -1,5 +1,3 @@ --- Car profile - -- Begin of globals bollards_whitelist = { [""] = true, ["cattle_grid"] = true, ["border_control"] = true, ["toll_booth"] = true, ["no"] = true, ["sally_port"] = true, ["gate"] = true} @@ -11,19 +9,18 @@ service_tag_restricted = { ["parking_aisle"] = true } ignore_in_grid = { ["ferry"] = true, ["pier"] = true } speed_profile = { - ["motorway"] = 100, - ["motorway_link"] = 90, - ["trunk"] = 90, - ["trunk_link"] = 90, - ["primary"] = 70, + ["motorway"] = 90, + ["motorway_link"] = 75, + ["trunk"] = 85, + ["trunk_link"] = 70, + ["primary"] = 65, ["primary_link"] = 60, - ["secondary"] = 60, + ["secondary"] = 55, ["secondary_link"] = 50, - ["tertiary"] = 50, - ["tertiary_link"] = 40, - ["unclassified"] = 30, - ["residential"] = 40, - ["road"] = 40, + ["tertiary"] = 40, + ["tertiary_link"] = 30, + ["unclassified"] = 25, + ["residential"] = 25, ["living_street"] = 10, ["service"] = 15, -- ["track"] = 5, @@ -32,7 +29,6 @@ speed_profile = { ["default"] = 50 } - take_minimum_of_speeds = true obey_oneway = true obey_bollards = true @@ -54,16 +50,37 @@ function node_function (node) node.traffic_light = true; end - if obey_bollards then + if access_tag_blacklist[barrier] then + node.bollard = true; + end + + if "" ~= barrier then + if obey_bollards then --flag node as unpassable if it black listed as unpassable - if access_tag_blacklist[barrier] then - node.bollard = true; - end - - --reverse the previous flag if there is an access tag specifying entrance - if node.bollard and not bollards_whitelist[barrier] and not access_tag_whitelist[barrier] then - node.bollard = false; - end + node.bollard = true; + end + --reverse the previous flag if there is an access tag specifying entrance + if node.bollard and bollards_whitelist[barrier] and access_tag_whitelist[barrier] then + node.bollard = false; + return 1 + end + -- Check if our vehicle types are allowd to pass the barrier + for i,v in ipairs(access_tags) do + local mode_value = node.tags:Find(v) + if nil ~= mode_value and "yes" == mode_value then + node.bollard = false + return + end + end + else + -- Check if our vehicle types are forbidden to pass the node + for i,v in ipairs(access_tags) do + local mode_value = node.tags:Find(v) + if nil ~= mode_value and "no" == mode_value then + node.bollard = true + return 1 + end + end end return 1 end @@ -128,7 +145,7 @@ function way_function (way, numberOfNodesInWay) (speed_profile[man_made] ~= nil and speed_profile[man_made] > 0) then if durationIsValid(duration) then - way.speed = parseDuration / math.max(1, numberOfSegments-1); + way.speed = math.max( duration / math.max(1, numberOfNodesInWay-1) ); way.is_duration_set = true; end way.direction = Way.bidirectional; @@ -191,4 +208,4 @@ function way_function (way, numberOfNodesInWay) end way.type = 1 return 1 -end \ No newline at end of file +end diff --git a/test/profiles/foot.lua b/profiles/foot.lua similarity index 100% rename from test/profiles/foot.lua rename to profiles/foot.lua