Fix bugs in max.lua, add interval in calculation

This commit is contained in:
Pieter Vander Vennet 2020-09-07 19:20:52 +02:00
parent 30266e72d2
commit 08419f91df
6 changed files with 27 additions and 10 deletions

View file

@ -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

View file

@ -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))

View file

@ -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

View file

@ -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"
]
}
]
}
]

View file

@ -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
]
}
]
}
},

View file

@ -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

1 expected,route,duration,interval,_length,comment
3 2,ferry,25,,1000,25 minutes duration + 5 minutes to get on is 30 minutes total for one kilometer -> 2 km/h
4 4,ferry,10,,1000,10 minutes duration + 5 minutes to get on is 15 minutes total for one kilometer -> 4km/h
5 null,,,,Ferry is not set
6 20.442857142857,ferry,00:16,,7155,Waterbus SintAnna-Zwijndrecht - osm.org/way/632117702
7 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