Fix tests, add profile metadata output
This commit is contained in:
parent
bf560e4c81
commit
aa3b669da9
8 changed files with 107 additions and 17 deletions
|
@ -51,6 +51,11 @@ namespace AspectedRouting.IO.jsonParser
|
||||||
foreach (var obj in e.EnumerateObject())
|
foreach (var obj in e.EnumerateObject())
|
||||||
{
|
{
|
||||||
var nm = obj.Name.TrimStart('#');
|
var nm = obj.Name.TrimStart('#');
|
||||||
|
if (nm == "")
|
||||||
|
{
|
||||||
|
// This is a comment - not a parameter!
|
||||||
|
continue;
|
||||||
|
}
|
||||||
switch (obj.Value.ValueKind)
|
switch (obj.Value.ValueKind)
|
||||||
{
|
{
|
||||||
case JsonValueKind.String:
|
case JsonValueKind.String:
|
||||||
|
|
|
@ -203,7 +203,8 @@ namespace AspectedRouting.Language
|
||||||
|
|
||||||
public static void SanityCheckProfile(this ProfileMetaData pmd, Context context)
|
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);
|
var usedMetadata = pmd.UsedParameters(context);
|
||||||
|
|
|
@ -14,6 +14,12 @@ namespace AspectedRouting.Language.Expression
|
||||||
public string Author { get; }
|
public string Author { get; }
|
||||||
public string Filename { get; }
|
public string Filename { get; }
|
||||||
public List<string> VehicleTyps { 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 List<string> Metadata { get; }
|
||||||
|
|
||||||
public Dictionary<string, IExpression> DefaultParameters { get; }
|
public Dictionary<string, IExpression> DefaultParameters { get; }
|
||||||
|
|
|
@ -114,6 +114,12 @@ namespace AspectedRouting
|
||||||
return; // End of stream has been reached
|
return; // End of stream has been reached
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (read == "")
|
||||||
|
{
|
||||||
|
Console.WriteLine("looƆ sᴉ dɐWʇǝǝɹʇSuǝdO");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (read.Equals("quit"))
|
if (read.Equals("quit"))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -141,6 +147,11 @@ namespace AspectedRouting
|
||||||
var tags = new Dictionary<string, string>();
|
var tags = new Dictionary<string, string>();
|
||||||
foreach (var str in tagsRaw)
|
foreach (var str in tagsRaw)
|
||||||
{
|
{
|
||||||
|
if (str == "")
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var strSplit = str.Split("=");
|
var strSplit = str.Split("=");
|
||||||
var k = strSplit[0].Trim();
|
var k = strSplit[0].Trim();
|
||||||
var v = strSplit[1].Trim();
|
var v = strSplit[1].Trim();
|
||||||
|
@ -206,9 +217,20 @@ namespace AspectedRouting
|
||||||
var files = Directory.EnumerateFiles(inputDir, "*.json", SearchOption.AllDirectories)
|
var files = Directory.EnumerateFiles(inputDir, "*.json", SearchOption.AllDirectories)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
var tests = Directory.EnumerateFiles(inputDir, "*test.csv", SearchOption.AllDirectories)
|
var tests = Directory.EnumerateFiles(inputDir, "*.csv", SearchOption.AllDirectories)
|
||||||
.ToList();
|
.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 context = new Context();
|
||||||
|
|
||||||
var aspects = ParseAspects(files, tests, context);
|
var aspects = ParseAspects(files, tests, context);
|
||||||
|
@ -235,7 +257,7 @@ namespace AspectedRouting
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
foreach (var (profile, profileTests) in profiles)
|
foreach (var (profile, profileTests) in profiles)
|
||||||
{
|
{
|
||||||
foreach (var test in profileTests)
|
foreach (var test in profileTests)
|
||||||
|
@ -274,8 +296,19 @@ namespace AspectedRouting
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Repl(context,
|
File.WriteAllText($"{outputDir}/metadata.json",
|
||||||
profiles.First(p => p.profile.Name.Equals("bicycle")).profile);
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using AspectedRouting.Language;
|
||||||
|
using AspectedRouting.Language.Expression;
|
||||||
|
|
||||||
namespace AspectedRouting
|
namespace AspectedRouting
|
||||||
{
|
{
|
||||||
|
@ -18,7 +21,7 @@ namespace AspectedRouting
|
||||||
{
|
{
|
||||||
return string.Join("\n", lines);
|
return string.Join("\n", lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int Multiply(this IEnumerable<int> ints)
|
public static int Multiply(this IEnumerable<int> ints)
|
||||||
{
|
{
|
||||||
var factor = 1;
|
var factor = 1;
|
||||||
|
@ -30,6 +33,48 @@ namespace AspectedRouting
|
||||||
return factor;
|
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) + "]";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,10 +5,15 @@
|
||||||
"$mustMatch": {
|
"$mustMatch": {
|
||||||
"type": "route",
|
"type": "route",
|
||||||
"route": "bicycle",
|
"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",
|
"note": "This block is commented out. A lot of networks we want to perform route planning on, are still proposed",
|
||||||
"state": {"$not": "proposed"}},
|
"state": {
|
||||||
"operator": {"$containedIn": "#networkOperator"}
|
"$not": "proposed"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "bicycle",
|
"name": "bicycle",
|
||||||
"description": "A simple profile which routes a normal bicycle",
|
"description": "Profile for a normal bicycle",
|
||||||
"vehicletypes": [
|
"vehicletypes": [
|
||||||
"vehicle",
|
"vehicle",
|
||||||
"bicycle"
|
"bicycle"
|
||||||
|
@ -122,11 +122,11 @@
|
||||||
},
|
},
|
||||||
"genk": {
|
"genk": {
|
||||||
"description": "A route preferring the cycling network by operator 'Stad Genk'",
|
"description": "A route preferring the cycling network by operator 'Stad Genk'",
|
||||||
"#operatorNetworkScore": 5,
|
"#operatorNetworkScore": 50,
|
||||||
"#networkOperator": [
|
"#networkOperator": [
|
||||||
"Stad Genk"
|
"Stad Genk"
|
||||||
],
|
],
|
||||||
"#safety": 1
|
"#safety": 0.1
|
||||||
},
|
},
|
||||||
"cycle_highway": {
|
"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 ",
|
"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
|
"#safety": 3
|
||||||
},
|
},
|
||||||
"b2w": {
|
"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,
|
"#operatorNetworkScore": 3,
|
||||||
"#networkOperator": [
|
"#networkOperator": [
|
||||||
"Brussels Mobility"
|
"Brussels Mobility"
|
||||||
|
|
|
@ -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,
|
|
|
Loading…
Add table
Add a link
Reference in a new issue