Add pedestrian and pedestrian.slow_roads, and various small additional fixes
This commit is contained in:
parent
531ab5241c
commit
c9a106abfb
7 changed files with 141 additions and 58 deletions
|
@ -26,7 +26,12 @@ namespace AspectedRouting.Language.Functions
|
||||||
public object Evaluate(Context c, params IExpression[] args)
|
public object Evaluate(Context c, params IExpression[] args)
|
||||||
{
|
{
|
||||||
var paramName = ParamName.TrimStart('#'); // context saves paramnames without '#'
|
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)
|
public IExpression Specialize(IEnumerable<Type> allowedTypes)
|
||||||
|
|
|
@ -46,7 +46,14 @@ namespace AspectedRouting.Language
|
||||||
{
|
{
|
||||||
public static object Run(this IExpression e, Context c, Dictionary<string, string> tags)
|
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)
|
public static IExpression Specialize(this IExpression e, Type t)
|
||||||
|
|
|
@ -102,8 +102,10 @@ namespace AspectedRouting
|
||||||
return result;
|
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();
|
var behaviour = profile.Behaviours.Keys.First();
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
@ -124,10 +126,33 @@ namespace AspectedRouting
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (read.Equals("clear"))
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 80; i++)
|
||||||
|
{
|
||||||
|
Console.WriteLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (read.StartsWith("select"))
|
if (read.StartsWith("select"))
|
||||||
{
|
{
|
||||||
var beh = read.Substring("select".Length + 1).Trim();
|
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))
|
if (profile.Behaviours.ContainsKey(beh))
|
||||||
{
|
{
|
||||||
behaviour = beh;
|
behaviour = beh;
|
||||||
|
@ -165,6 +190,7 @@ namespace AspectedRouting
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine(e);
|
||||||
Console.WriteLine(e.Message);
|
Console.WriteLine(e.Message);
|
||||||
}
|
}
|
||||||
} while (true);
|
} 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))
|
Utils.GenerateExplanationJson(profiles.Select(p => p.profile))
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!args.Contains("--no-repl"))
|
if (!args.Contains("--no-repl"))
|
||||||
{
|
{
|
||||||
Repl(context,
|
Repl(context, profiles
|
||||||
profiles.First(p => p.profile.Name.Equals("bicycle")).profile);
|
.Select(p => p.profile)
|
||||||
|
.ToDictionary(p => p.Name, p => p));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -311,4 +338,4 @@ namespace AspectedRouting
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,7 +162,7 @@
|
||||||
"#safety": 3
|
"#safety": 3
|
||||||
},
|
},
|
||||||
"anyways.network": {
|
"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,
|
"#timeNeeded": 1,
|
||||||
"#operatorNetworkScore": 10,
|
"#operatorNetworkScore": 10,
|
||||||
"#networkOperator": [
|
"#networkOperator": [
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
expected,highway,foot,access,anyways:access,cycleway:right,cycleway
|
||||||
|
no,,,,,,
|
||||||
|
yes,residential,
|
||||||
|
designated,pedestrian
|
|
|
@ -179,7 +179,7 @@ s | returns |
|
||||||
string | double |
|
string | double |
|
||||||
string | pdouble |
|
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
|
||||||
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)
|
return tonumber(string)
|
||||||
end
|
end
|
||||||
|
@ -268,7 +277,7 @@ Lua implementation:
|
||||||
|
|
||||||
````lua
|
````lua
|
||||||
function containedIn(list, a)
|
function containedIn(list, a)
|
||||||
for _, value in ipairs(list) do
|
for _, value in pairs(list) do
|
||||||
if (value == a) then
|
if (value == a) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
@ -298,11 +307,13 @@ Lua implementation:
|
||||||
````lua
|
````lua
|
||||||
function min(list)
|
function min(list)
|
||||||
local min
|
local min
|
||||||
for _, value in ipairs(list) do
|
for _, value in pairs(list) do
|
||||||
if (min == nil) then
|
if(value ~= nil) then
|
||||||
min = value
|
if (min == nil) then
|
||||||
elseif (value < min) then
|
min = value
|
||||||
min = value
|
elseif (value < min) then
|
||||||
|
min = value
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -330,11 +341,13 @@ Lua implementation:
|
||||||
````lua
|
````lua
|
||||||
function min(list)
|
function min(list)
|
||||||
local min
|
local min
|
||||||
for _, value in ipairs(list) do
|
for _, value in pairs(list) do
|
||||||
if (min == nil) then
|
if(value ~= nil) then
|
||||||
min = value
|
if (min == nil) then
|
||||||
elseif (value < min) then
|
min = value
|
||||||
min = value
|
elseif (value < min) then
|
||||||
|
min = value
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -362,11 +375,13 @@ Lua implementation:
|
||||||
````lua
|
````lua
|
||||||
function max(list)
|
function max(list)
|
||||||
local max
|
local max
|
||||||
for _, value in ipairs(list) do
|
for _, value in pairs(list) do
|
||||||
if (max == nil) then
|
if (value ~= nil) then
|
||||||
max = value
|
if (max == nil) then
|
||||||
elseif (max < value) then
|
max = value
|
||||||
max = value
|
elseif (max < value) then
|
||||||
|
max = value
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -394,11 +409,13 @@ Lua implementation:
|
||||||
````lua
|
````lua
|
||||||
function max(list)
|
function max(list)
|
||||||
local max
|
local max
|
||||||
for _, value in ipairs(list) do
|
for _, value in pairs(list) do
|
||||||
if (max == nil) then
|
if (value ~= nil) then
|
||||||
max = value
|
if (max == nil) then
|
||||||
elseif (max < value) then
|
max = value
|
||||||
max = value
|
elseif (max < value) then
|
||||||
|
max = value
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -425,12 +442,14 @@ Lua implementation:
|
||||||
|
|
||||||
````lua
|
````lua
|
||||||
function sum(list)
|
function sum(list)
|
||||||
local sum = 1
|
local sum = 0
|
||||||
for _, value in ipairs(list) do
|
for _, value in pairs(list) do
|
||||||
if(value == 'yes' or value == 'true') then
|
if(value ~= nil) then
|
||||||
value = 1
|
if(value == 'yes' or value == 'true') then
|
||||||
|
value = 1
|
||||||
|
end
|
||||||
|
sum = sum + value
|
||||||
end
|
end
|
||||||
sum = sum + value
|
|
||||||
end
|
end
|
||||||
return sum;
|
return sum;
|
||||||
end
|
end
|
||||||
|
@ -455,12 +474,14 @@ Lua implementation:
|
||||||
|
|
||||||
````lua
|
````lua
|
||||||
function sum(list)
|
function sum(list)
|
||||||
local sum = 1
|
local sum = 0
|
||||||
for _, value in ipairs(list) do
|
for _, value in pairs(list) do
|
||||||
if(value == 'yes' or value == 'true') then
|
if(value ~= nil) then
|
||||||
value = 1
|
if(value == 'yes' or value == 'true') then
|
||||||
|
value = 1
|
||||||
|
end
|
||||||
|
sum = sum + value
|
||||||
end
|
end
|
||||||
sum = sum + value
|
|
||||||
end
|
end
|
||||||
return sum;
|
return sum;
|
||||||
end
|
end
|
||||||
|
@ -485,12 +506,14 @@ Lua implementation:
|
||||||
|
|
||||||
````lua
|
````lua
|
||||||
function sum(list)
|
function sum(list)
|
||||||
local sum = 1
|
local sum = 0
|
||||||
for _, value in ipairs(list) do
|
for _, value in pairs(list) do
|
||||||
if(value == 'yes' or value == 'true') then
|
if(value ~= nil) then
|
||||||
value = 1
|
if(value == 'yes' or value == 'true') then
|
||||||
|
value = 1
|
||||||
|
end
|
||||||
|
sum = sum + value
|
||||||
end
|
end
|
||||||
sum = sum + value
|
|
||||||
end
|
end
|
||||||
return sum;
|
return sum;
|
||||||
end
|
end
|
||||||
|
@ -516,8 +539,10 @@ Lua implementation:
|
||||||
````lua
|
````lua
|
||||||
function multiply(list)
|
function multiply(list)
|
||||||
local factor = 1
|
local factor = 1
|
||||||
for _, value in ipairs(list) do
|
for _, value in pairs(list) do
|
||||||
factor = factor * value
|
if (value ~= nil) then
|
||||||
|
factor = factor * value
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return factor;
|
return factor;
|
||||||
end
|
end
|
||||||
|
@ -562,7 +587,7 @@ Lua implementation:
|
||||||
|
|
||||||
````lua
|
````lua
|
||||||
function first_match_of(tags, result, order_of_keys, table)
|
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]
|
local v = tags[key]
|
||||||
if (v ~= nil) then
|
if (v ~= nil) then
|
||||||
|
|
||||||
|
@ -789,9 +814,6 @@ function if_then_else_dotted(conditionf, thnf, elsef, arg)
|
||||||
if (condition) then
|
if (condition) then
|
||||||
return applyIfNeeded(thnf, arg)
|
return applyIfNeeded(thnf, arg)
|
||||||
else
|
else
|
||||||
if(elsef == nil) then
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
return applyIfNeeded(elsef, arg) -- if no third parameter is given, 'els' will be nil
|
return applyIfNeeded(elsef, arg) -- if no third parameter is given, 'els' will be nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -832,9 +854,6 @@ function if_then_else_dotted(conditionf, thnf, elsef, arg)
|
||||||
if (condition) then
|
if (condition) then
|
||||||
return applyIfNeeded(thnf, arg)
|
return applyIfNeeded(thnf, arg)
|
||||||
else
|
else
|
||||||
if(elsef == nil) then
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
return applyIfNeeded(elsef, arg) -- if no third parameter is given, 'els' will be nil
|
return applyIfNeeded(elsef, arg) -- if no third parameter is given, 'els' will be nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -875,9 +894,6 @@ function if_then_else_dotted(conditionf, thnf, elsef, arg)
|
||||||
if (condition) then
|
if (condition) then
|
||||||
return applyIfNeeded(thnf, arg)
|
return applyIfNeeded(thnf, arg)
|
||||||
else
|
else
|
||||||
if(elsef == nil) then
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
return applyIfNeeded(elsef, arg) -- if no third parameter is given, 'els' will be nil
|
return applyIfNeeded(elsef, arg) -- if no third parameter is given, 'els' will be nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1030,7 +1046,7 @@ function head(ls)
|
||||||
if(ls == nil) then
|
if(ls == nil) then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
for _, v in ipairs(ls) do
|
for _, v in pairs(ls) do
|
||||||
if(v ~= nil) then
|
if(v ~= nil) then
|
||||||
return v
|
return v
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue