Add pedestrian and pedestrian.slow_roads, and various small additional fixes

This commit is contained in:
Pieter Vander Vennet 2020-10-15 20:14:57 +02:00
parent 531ab5241c
commit c9a106abfb
7 changed files with 141 additions and 58 deletions

View file

@ -26,7 +26,12 @@ namespace AspectedRouting.Language.Functions
public object Evaluate(Context c, params IExpression[] args)
{
var paramName = ParamName.TrimStart('#'); // context saves paramnames without '#'
return c?.Parameters?.GetValueOrDefault(paramName, null);
var value = c?.Parameters?.GetValueOrDefault(paramName, null);
if(value is Constant constant)
{
return constant.Evaluate(c);
}
return value;
}
public IExpression Specialize(IEnumerable<Type> allowedTypes)

View file

@ -46,7 +46,14 @@ namespace AspectedRouting.Language
{
public static object Run(this IExpression e, Context c, Dictionary<string, string> tags)
{
return e.Apply(new[] {new Constant(tags)}).Evaluate(c);
try
{
return e.Apply(new[] {new Constant(tags)}).Evaluate(c);
}
catch (Exception err)
{
throw new Exception($"While evaluating the expression {e} with arguments a list of tags", err);
}
}
public static IExpression Specialize(this IExpression e, Type t)

View file

@ -102,8 +102,10 @@ namespace AspectedRouting
return result;
}
private static void Repl(Context c, ProfileMetaData profile)
private static void Repl(Context c, Dictionary<string, ProfileMetaData> profiles)
{
var profile = profiles["bicycle"];
var behaviour = profile.Behaviours.Keys.First();
do
{
@ -124,10 +126,33 @@ namespace AspectedRouting
{
return;
}
if (read.Equals("clear"))
{
for (int i = 0; i < 80; i++)
{
Console.WriteLine();
}
continue;
}
if (read.StartsWith("select"))
{
var beh = read.Substring("select".Length + 1).Trim();
if (beh.Contains("."))
{
var profileName = beh.Split(".")[0];
if (!profiles.TryGetValue(profileName, out profile))
{
Console.Error.WriteLine("Profile " + profileName + " not found, ignoring");
continue;
}
beh = beh.Substring(beh.IndexOf(".")+1);
}
if (profile.Behaviours.ContainsKey(beh))
{
behaviour = beh;
@ -165,6 +190,7 @@ namespace AspectedRouting
}
catch (Exception e)
{
Console.WriteLine(e);
Console.WriteLine(e.Message);
}
} while (true);
@ -296,14 +322,15 @@ namespace AspectedRouting
}
}
File.WriteAllText($"{outputDir}/metadata.json",
File.WriteAllText($"{outputDir}/ProfileMetadata.json",
Utils.GenerateExplanationJson(profiles.Select(p => p.profile))
);
if (!args.Contains("--no-repl"))
{
Repl(context,
profiles.First(p => p.profile.Name.Equals("bicycle")).profile);
Repl(context, profiles
.Select(p => p.profile)
.ToDictionary(p => p.Name, p => p));
}
else
{
@ -311,4 +338,4 @@ namespace AspectedRouting
}
}
}
}
}

View file

@ -162,7 +162,7 @@
"#safety": 3
},
"anyways.network": {
"description": "[Internal use] A route using the Anyways branded network; mainly used in ShortCut/Impact",
"description": "[Private][Internal use] A route using the Anyways branded network; mainly used in ShortCut/Impact",
"#timeNeeded": 1,
"#operatorNetworkScore": 10,
"#networkOperator": [

View file

@ -0,0 +1,24 @@
{
"name": "pedestrian.slow_road_preference",
"description": "Gives a value between 0 and 2, indicating how lovely a path or track is to walk over. It'll prefer roads with less car-pressure",
"unit": "0: absolutely horrible to walk, 2: absolutely lovely",
"$default": 1,
"value": {
"$multiply": [
{
"highway": {
"pedestrian": 2,
"living_street": 1.5,
"footway": 1.8,
"path": 1.2
}
},
{
"access": {
"destination": 1.5,
"no": 1.5
}
}
]
}
}

View file

@ -0,0 +1,4 @@
expected,highway,foot,access,anyways:access,cycleway:right,cycleway
no,,,,,,
yes,residential,
designated,pedestrian
1 expected,highway,foot,access,anyways:access,cycleway:right,cycleway
2 no,,,,,,
3 yes,residential,
4 designated,pedestrian

View file

@ -179,7 +179,7 @@ s | returns |
string | double |
string | pdouble |
Parses a string into a numerical value. Returns 'null' if parsing fails or no input is given
Parses a string into a numerical value. Returns 'null' if parsing fails or no input is given. If a duration is given (e.g. `01:15`), then the number of minutes (75) is returned
@ -210,6 +210,15 @@ function parse(string)
end
end
if(string:match("%d+:%d+")) then
-- duration in minute
local duration = 0
for part in string:gmatch "%d+" do
duration = duration * 60 + tonumber(part)
end
return duration
end
return tonumber(string)
end
@ -268,7 +277,7 @@ Lua implementation:
````lua
function containedIn(list, a)
for _, value in ipairs(list) do
for _, value in pairs(list) do
if (value == a) then
return true
end
@ -298,11 +307,13 @@ Lua implementation:
````lua
function min(list)
local min
for _, value in ipairs(list) do
if (min == nil) then
min = value
elseif (value < min) then
min = value
for _, value in pairs(list) do
if(value ~= nil) then
if (min == nil) then
min = value
elseif (value < min) then
min = value
end
end
end
@ -330,11 +341,13 @@ Lua implementation:
````lua
function min(list)
local min
for _, value in ipairs(list) do
if (min == nil) then
min = value
elseif (value < min) then
min = value
for _, value in pairs(list) do
if(value ~= nil) then
if (min == nil) then
min = value
elseif (value < min) then
min = value
end
end
end
@ -362,11 +375,13 @@ Lua implementation:
````lua
function max(list)
local max
for _, value in ipairs(list) do
if (max == nil) then
max = value
elseif (max < value) then
max = value
for _, value in pairs(list) do
if (value ~= nil) then
if (max == nil) then
max = value
elseif (max < value) then
max = value
end
end
end
@ -394,11 +409,13 @@ Lua implementation:
````lua
function max(list)
local max
for _, value in ipairs(list) do
if (max == nil) then
max = value
elseif (max < value) then
max = value
for _, value in pairs(list) do
if (value ~= nil) then
if (max == nil) then
max = value
elseif (max < value) then
max = value
end
end
end
@ -425,12 +442,14 @@ Lua implementation:
````lua
function sum(list)
local sum = 1
for _, value in ipairs(list) do
if(value == 'yes' or value == 'true') then
value = 1
local sum = 0
for _, value in pairs(list) do
if(value ~= nil) then
if(value == 'yes' or value == 'true') then
value = 1
end
sum = sum + value
end
sum = sum + value
end
return sum;
end
@ -455,12 +474,14 @@ Lua implementation:
````lua
function sum(list)
local sum = 1
for _, value in ipairs(list) do
if(value == 'yes' or value == 'true') then
value = 1
local sum = 0
for _, value in pairs(list) do
if(value ~= nil) then
if(value == 'yes' or value == 'true') then
value = 1
end
sum = sum + value
end
sum = sum + value
end
return sum;
end
@ -485,12 +506,14 @@ Lua implementation:
````lua
function sum(list)
local sum = 1
for _, value in ipairs(list) do
if(value == 'yes' or value == 'true') then
value = 1
local sum = 0
for _, value in pairs(list) do
if(value ~= nil) then
if(value == 'yes' or value == 'true') then
value = 1
end
sum = sum + value
end
sum = sum + value
end
return sum;
end
@ -516,8 +539,10 @@ Lua implementation:
````lua
function multiply(list)
local factor = 1
for _, value in ipairs(list) do
factor = factor * value
for _, value in pairs(list) do
if (value ~= nil) then
factor = factor * value
end
end
return factor;
end
@ -562,7 +587,7 @@ Lua implementation:
````lua
function first_match_of(tags, result, order_of_keys, table)
for _, key in ipairs(order_of_keys) do
for _, key in pairs(order_of_keys) do
local v = tags[key]
if (v ~= nil) then
@ -789,9 +814,6 @@ function if_then_else_dotted(conditionf, thnf, elsef, arg)
if (condition) then
return applyIfNeeded(thnf, arg)
else
if(elsef == nil) then
return nil
end
return applyIfNeeded(elsef, arg) -- if no third parameter is given, 'els' will be nil
end
end
@ -832,9 +854,6 @@ function if_then_else_dotted(conditionf, thnf, elsef, arg)
if (condition) then
return applyIfNeeded(thnf, arg)
else
if(elsef == nil) then
return nil
end
return applyIfNeeded(elsef, arg) -- if no third parameter is given, 'els' will be nil
end
end
@ -875,9 +894,6 @@ function if_then_else_dotted(conditionf, thnf, elsef, arg)
if (condition) then
return applyIfNeeded(thnf, arg)
else
if(elsef == nil) then
return nil
end
return applyIfNeeded(elsef, arg) -- if no third parameter is given, 'els' will be nil
end
end
@ -1030,7 +1046,7 @@ function head(ls)
if(ls == nil) then
return nil
end
for _, v in ipairs(ls) do
for _, v in pairs(ls) do
if(v ~= nil) then
return v
end