From 08419f91df3a68f119ca80f16ffbdd3f50cca4f0 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Mon, 7 Sep 2020 19:20:52 +0200 Subject: [PATCH] Fix bugs in max.lua, add interval in calculation --- AspectedRouting/IO/lua/max.lua | 2 +- AspectedRouting/IO/lua/unitTest.lua | 2 +- AspectedRouting/Language/Functions/Parse.cs | 2 +- Profiles/bicycle/bicycle.json | 16 ++++++++++------ Profiles/general/ferry_speed.json | 13 ++++++++++++- Profiles/general/ferry_speed.test.csv | 2 ++ 6 files changed, 27 insertions(+), 10 deletions(-) diff --git a/AspectedRouting/IO/lua/max.lua b/AspectedRouting/IO/lua/max.lua index 3c4e4cb..f98674b 100644 --- a/AspectedRouting/IO/lua/max.lua +++ b/AspectedRouting/IO/lua/max.lua @@ -1,7 +1,7 @@ function max(list) local max for _, value in pairs(list) do - if (value == nil) then + if (value ~= nil) then if (max == nil) then max = value elseif (max < value) then diff --git a/AspectedRouting/IO/lua/unitTest.lua b/AspectedRouting/IO/lua/unitTest.lua index bf8cdfd..3112e96 100644 --- a/AspectedRouting/IO/lua/unitTest.lua +++ b/AspectedRouting/IO/lua/unitTest.lua @@ -9,7 +9,7 @@ function unit_test(f, fname, index, expected, parameters, tags) local actual = f(parameters, tags, result) if(expected == "null" and actual == nil) then -- OK! - elseif(tonumber(actual) and tonumber(expected) and tonumber(actual) == tonumber(expected)) then + elseif(tonumber(actual) and tonumber(expected) and math.abs(tonumber(actual) - tonumber(expected)) < 0.1) then -- OK! elseif (tostring(actual) ~= expected) then print("[" .. fname .. "] " .. index .. " failed: expected " .. expected .. " but got " .. tostring(actual)) diff --git a/AspectedRouting/Language/Functions/Parse.cs b/AspectedRouting/Language/Functions/Parse.cs index 3d04574..1a5652a 100644 --- a/AspectedRouting/Language/Functions/Parse.cs +++ b/AspectedRouting/Language/Functions/Parse.cs @@ -48,7 +48,7 @@ namespace AspectedRouting.Language.Functions // This is a duration of the form 'hh:mm' -> we return the total minute count var hours = int.Parse(duration.Groups[1].Value); var minutes = int.Parse(duration.Groups[2].Value); - return hours * 60 + minutes; + arg = (hours * 60 + minutes).ToString(); } try diff --git a/Profiles/bicycle/bicycle.json b/Profiles/bicycle/bicycle.json index 528ca1b..1fbd367 100644 --- a/Profiles/bicycle/bicycle.json +++ b/Profiles/bicycle/bicycle.json @@ -19,14 +19,18 @@ "access": "$bicycle.legal_access", "oneway": "$bicycle.oneway", "speed": { - "$min": [ - "$legal_maxspeed_be", - "#maxspeed", + "$max": [ "$ferry_speed", { - "$multiply": [ - "#defaultSpeed", - "$bicycle.speed_factor" + "$min": [ + "$legal_maxspeed_be", + "#maxspeed", + { + "$multiply": [ + "#defaultSpeed", + "$bicycle.speed_factor" + ] + } ] } ] diff --git a/Profiles/general/ferry_speed.json b/Profiles/general/ferry_speed.json index 0ac23dd..85abd0c 100644 --- a/Profiles/general/ferry_speed.json +++ b/Profiles/general/ferry_speed.json @@ -24,7 +24,18 @@ { "duration": "$parse" }, - 5 + { + "$multiply": [ + { + "#": "Time needed to get on. We assume a continous ferry (pull it your self) which takes a few minutes to be free. If an interval is specified, we take a quarter of the interval as we assume that people will take into account the schedule", + "$default": 20, + "value": { + "interval": "$parse" + } + }, + 0.25 + ] + } ] } }, diff --git a/Profiles/general/ferry_speed.test.csv b/Profiles/general/ferry_speed.test.csv index b4e2d8b..6c6155a 100644 --- a/Profiles/general/ferry_speed.test.csv +++ b/Profiles/general/ferry_speed.test.csv @@ -3,3 +3,5 @@ expected,route,duration,interval,_length,comment 2,ferry,25,,1000,25 minutes duration + 5 minutes to get on is 30 minutes total for one kilometer -> 2 km/h 4,ferry,10,,1000,10 minutes duration + 5 minutes to get on is 15 minutes total for one kilometer -> 4km/h null,,,,Ferry is not set +20.442857142857,ferry,00:16,,7155,Waterbus SintAnna-Zwijndrecht - osm.org/way/632117702 +9.3326086956522,ferry,00:16,2:00,7155,Non-regular waterbus which goes every two hours. Expected time ppl will wait: 30minutes + 16minutes faring duration = 46minutes for 7km = ~9km/h