Fix tests, add profile metadata output

This commit is contained in:
Pieter Vander Vennet 2020-09-30 13:35:30 +02:00
parent bf560e4c81
commit aa3b669da9
8 changed files with 107 additions and 17 deletions

View file

@ -51,6 +51,11 @@ namespace AspectedRouting.IO.jsonParser
foreach (var obj in e.EnumerateObject())
{
var nm = obj.Name.TrimStart('#');
if (nm == "")
{
// This is a comment - not a parameter!
continue;
}
switch (obj.Value.ValueKind)
{
case JsonValueKind.String:

View file

@ -203,7 +203,8 @@ namespace AspectedRouting.Language
public static void SanityCheckProfile(this ProfileMetaData pmd, Context context)
{
var defaultParameters = pmd.DefaultParameters.Keys.Select(k => k.TrimStart('#'));
var defaultParameters = pmd.DefaultParameters.Keys
.Select(k => k.TrimStart('#')).ToList();
var usedMetadata = pmd.UsedParameters(context);

View file

@ -14,6 +14,12 @@ namespace AspectedRouting.Language.Expression
public string Author { get; }
public string Filename { get; }
public List<string> VehicleTyps { get; }
/*
* Which tags are included in the routerdb but are _not_ used for routeplanning?
* Typically these are tags that are useful for navigation (name of the road, is this a tunnel, ...)
* but not relevant for determining the road
*/
public List<string> Metadata { get; }
public Dictionary<string, IExpression> DefaultParameters { get; }

View file

@ -114,6 +114,12 @@ namespace AspectedRouting
return; // End of stream has been reached
}
if (read == "")
{
Console.WriteLine("looƆ sᴉ dɐWʇǝǝɹʇSuǝdO");
continue;
}
if (read.Equals("quit"))
{
return;
@ -141,6 +147,11 @@ namespace AspectedRouting
var tags = new Dictionary<string, string>();
foreach (var str in tagsRaw)
{
if (str == "")
{
continue;
}
var strSplit = str.Split("=");
var k = strSplit[0].Trim();
var v = strSplit[1].Trim();
@ -206,9 +217,20 @@ namespace AspectedRouting
var files = Directory.EnumerateFiles(inputDir, "*.json", SearchOption.AllDirectories)
.ToList();
var tests = Directory.EnumerateFiles(inputDir, "*test.csv", SearchOption.AllDirectories)
var tests = Directory.EnumerateFiles(inputDir, "*.csv", SearchOption.AllDirectories)
.ToList();
foreach (var test in tests)
{
if (test.EndsWith(".test.csv") || test.EndsWith(".behaviour_test.csv"))
{
continue;
}
throw new ArgumentException(
$"Invalid name for csv file ${test}, should end with either '.behaviour_test.csv' or '.test.csv'");
}
var context = new Context();
var aspects = ParseAspects(files, tests, context);
@ -235,7 +257,7 @@ namespace AspectedRouting
}
}
foreach (var (profile, profileTests) in profiles)
{
foreach (var test in profileTests)
@ -274,8 +296,19 @@ namespace AspectedRouting
}
}
Repl(context,
profiles.First(p => p.profile.Name.Equals("bicycle")).profile);
File.WriteAllText($"{outputDir}/metadata.json",
Utils.GenerateExplanationJson(profiles.Select(p => p.profile))
);
if (!args.Contains("--no-repl"))
{
Repl(context,
profiles.First(p => p.profile.Name.Equals("bicycle")).profile);
}
else
{
Console.WriteLine("Not starting REPL as --no-repl is specified");
}
}
}
}

View file

@ -1,4 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using AspectedRouting.Language;
using AspectedRouting.Language.Expression;
namespace AspectedRouting
{
@ -18,7 +21,7 @@ namespace AspectedRouting
{
return string.Join("\n", lines);
}
public static int Multiply(this IEnumerable<int> ints)
{
var factor = 1;
@ -30,6 +33,48 @@ namespace AspectedRouting
return factor;
}
/// <summary>
/// Generates a JSON file where all the profiles are listed, together with descriptions and other metadata.
/// Useful for other apps, e.g. the routing api to have
/// </summary>
/// <param name="select"></param>
/// <returns></returns>
public static string GenerateExplanationJson(IEnumerable<ProfileMetaData> profiles)
{
var metaItems = new List<string>();
foreach (var profile in profiles)
{
var profileName = profile.Name;
var author = profile.Author;
var profileDescription = profile.Description;
foreach (var behaviour in profile.Behaviours)
{
var behaviourDescription = behaviour.Value["description"].Evaluate(new Context()) as string;
behaviourDescription ??= "";
if (behaviourDescription.ToLower().Contains("[private]"))
{
// This profile is marked as private, we are hiding it
continue;
}
var meta = new Dictionary<string, string>
{
{"name", behaviour.Key},
{"type", profileName},
{"author", author},
{"description", behaviourDescription + " (" + profileDescription + ")"}
};
var json = string.Join(",", meta.Select(d =>
$"\"{d.Key}\": \"{d.Value}\""));
metaItems.Add("{" + json + "}\n");
}
}
return "[" + string.Join(",", metaItems) + "]";
}
}
}

View file

@ -5,10 +5,15 @@
"$mustMatch": {
"type": "route",
"route": "bicycle",
"operator": {
"$containedIn": "#networkOperator"
},
"#": {
"note": "This block is commented out. A lot of networks we want to perform route planning on, are still proposed",
"state": {"$not": "proposed"}},
"operator": {"$containedIn": "#networkOperator"}
"state": {
"$not": "proposed"
}
}
}
}
}

View file

@ -1,6 +1,6 @@
{
"name": "bicycle",
"description": "A simple profile which routes a normal bicycle",
"description": "Profile for a normal bicycle",
"vehicletypes": [
"vehicle",
"bicycle"
@ -122,11 +122,11 @@
},
"genk": {
"description": "A route preferring the cycling network by operator 'Stad Genk'",
"#operatorNetworkScore": 5,
"#operatorNetworkScore": 50,
"#networkOperator": [
"Stad Genk"
],
"#safety": 1
"#safety": 0.1
},
"cycle_highway": {
"description": "A route preferring the 'cycle-highways'. On non-cycleways, fastest is used (with a very low factor) in order to make sure the behaviour there is defined ",
@ -151,7 +151,7 @@
"#safety": 3
},
"b2w": {
"description": "[Custom] Route specifically for Bike2Work. Same as commute at this moment. A route preferring the 'cycle-highways' or the cycling network by operator 'Brussels Mobility'",
"description": "[Custom][Private] Route specifically for Bike2Work. Same as commute at this moment. A route preferring the 'cycle-highways' or the cycling network by operator 'Brussels Mobility'",
"#operatorNetworkScore": 3,
"#networkOperator": [
"Brussels Mobility"

View file

@ -1,5 +0,0 @@
access,oneway,speed,priority,highway,_relation:bicycle.network_by_operator
no,both,0,0,,
yes,both,15,1.9,residential,
yes,both,15,6.9,residential,yes
dismount,both,2.25,0.0195,footway,
1 access oneway speed priority highway _relation:bicycle.network_by_operator
2 no both 0 0
3 yes both 15 1.9 residential
4 yes both 15 6.9 residential yes
5 dismount both 2.25 0.0195 footway