Stabilized date in generated profiles
This commit is contained in:
parent
878cfbb48f
commit
b9cb0ef632
6 changed files with 59 additions and 91 deletions
|
@ -1,8 +1,8 @@
|
|||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=46c4a96e_002D61f1_002D4d55_002Da7ff_002D649a683870dc/@EntryIndexedValue"><SessionState ContinuousTestingIsOn="False" ContinuousTestingMode="0" FrameworkVersion="{x:Null}" IsLocked="False" Name="ParseFunction_Duration_TotalMinutes" PlatformMonoPreference="{x:Null}" PlatformType="{x:Null}" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=46c4a96e_002D61f1_002D4d55_002Da7ff_002D649a683870dc/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" Name="ParseFunction_Duration_TotalMinutes" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
|
||||
<Project Location="/home/pietervdvn/werk/AspectedRouting/AspectedRouting.Test" Presentation="&lt;AspectedRouting.Test&gt;" />
|
||||
</SessionState></s:String>
|
||||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=a6a74f48_002D8456_002D43c7_002Dbbee_002Dd3da33a8a4be/@EntryIndexedValue"><SessionState ContinuousTestingIsOn="False" ContinuousTestingMode="0" FrameworkVersion="{x:Null}" IsLocked="False" Name="Integration_TestExamples" PlatformMonoPreference="{x:Null}" PlatformType="{x:Null}" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=a6a74f48_002D8456_002D43c7_002Dbbee_002Dd3da33a8a4be/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" IsActive="True" Name="Integration_TestExamples" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
|
||||
<TestAncestor>
|
||||
<TestId>xUnit::A1309041-8AAE-42D7-A886-94C9FFC6A28C::.NETCoreApp,Version=v3.1::AspectedRouting.Test.ExamplesTest.Integration_TestExamples</TestId>
|
||||
</TestAncestor>
|
||||
|
|
|
@ -48,7 +48,7 @@ namespace AspectedRouting.IO.itinero1
|
|||
|
||||
var header = new List<string>
|
||||
{
|
||||
$"-- Itinero 1.0-profile, generated by AspectedRouting on {DateTime.Now:s}",
|
||||
$"-- Itinero 1.0-profile, generated by AspectedRouting. Last source file change is {_profile.LastChange:s}",
|
||||
$"name = \"{_profile.Name}\"",
|
||||
"normalize = false",
|
||||
"vehicle_type = {" + string.Join(", ", _profile.VehicleTyps.Select(s => "\"" + s + "\"")) + "}",
|
||||
|
|
|
@ -32,6 +32,7 @@ namespace AspectedRouting.IO.itinero2
|
|||
private readonly Context _context;
|
||||
private readonly List<AspectTestSuite> _aspectTests;
|
||||
private readonly IEnumerable<BehaviourTestSuite> _behaviourTestSuite;
|
||||
private readonly DateTime _lastChangeTime;
|
||||
|
||||
private readonly LuaSkeleton.LuaSkeleton _skeleton;
|
||||
private readonly LuaParameterPrinter _parameterPrinter;
|
||||
|
@ -39,7 +40,8 @@ namespace AspectedRouting.IO.itinero2
|
|||
|
||||
public LuaPrinter2(ProfileMetaData profile, string behaviourName,
|
||||
Context context,
|
||||
List<AspectTestSuite> aspectTests, IEnumerable<BehaviourTestSuite> behaviourTestSuite)
|
||||
List<AspectTestSuite> aspectTests, IEnumerable<BehaviourTestSuite> behaviourTestSuite,
|
||||
DateTime lastChangeTime)
|
||||
{
|
||||
_skeleton = new LuaSkeleton.LuaSkeleton(context);
|
||||
_profile = profile;
|
||||
|
@ -47,6 +49,7 @@ namespace AspectedRouting.IO.itinero2
|
|||
_context = context;
|
||||
_aspectTests = aspectTests;
|
||||
_behaviourTestSuite = behaviourTestSuite;
|
||||
_lastChangeTime = lastChangeTime;
|
||||
_parameterPrinter = new LuaParameterPrinter(_profile, _skeleton);
|
||||
}
|
||||
|
||||
|
@ -56,7 +59,7 @@ namespace AspectedRouting.IO.itinero2
|
|||
new List<string>
|
||||
{
|
||||
$"name = \"{_profile.Name}.{_behaviourName}\"",
|
||||
$"generationDate = \"{DateTime.Now:s}\"",
|
||||
$"generationDate = \"{_lastChangeTime:s}\"",
|
||||
$"description = \"{_profile.Description}\""
|
||||
};
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace AspectedRouting.IO.jsonParser
|
|||
}
|
||||
}
|
||||
|
||||
public static ProfileMetaData ProfileFromJson(Context c, string json, FileInfo f)
|
||||
public static ProfileMetaData ProfileFromJson(Context c, string json, FileInfo f, DateTime lastChange)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -45,7 +45,7 @@ namespace AspectedRouting.IO.jsonParser
|
|||
// this is an aspect
|
||||
}
|
||||
|
||||
return ParseProfile(doc.RootElement, c, f);
|
||||
return ParseProfile(doc.RootElement, c, f, lastChange);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -63,7 +63,7 @@ namespace AspectedRouting.IO.jsonParser
|
|||
}
|
||||
|
||||
|
||||
private static ProfileMetaData ParseProfile(this JsonElement e, Context context, FileInfo filepath)
|
||||
private static ProfileMetaData ParseProfile(this JsonElement e, Context context, FileInfo filepath, DateTime lastChange)
|
||||
{
|
||||
if (!e.TryGetProperty("speed", out _))
|
||||
{
|
||||
|
@ -141,6 +141,11 @@ namespace AspectedRouting.IO.jsonParser
|
|||
profiles[profile.Name] = ParseParameters(profile.Value);
|
||||
}
|
||||
|
||||
if (lastChange < filepath.LastWriteTimeUtc)
|
||||
{
|
||||
lastChange = filepath.LastWriteTimeUtc;
|
||||
}
|
||||
|
||||
return new ProfileMetaData(
|
||||
name,
|
||||
e.Get("description"),
|
||||
|
@ -153,7 +158,8 @@ namespace AspectedRouting.IO.jsonParser
|
|||
oneway,
|
||||
speed,
|
||||
weights,
|
||||
metadata
|
||||
metadata,
|
||||
lastChange
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,12 +29,16 @@ namespace AspectedRouting.Language.Expression
|
|||
public IExpression Oneway { get; }
|
||||
public IExpression Speed { get; }
|
||||
public Dictionary<string, IExpression> Priority { get; }
|
||||
/**
|
||||
* Moment of last change of any upstream file
|
||||
*/
|
||||
public DateTime LastChange { get; }
|
||||
|
||||
public ProfileMetaData(string name, string description, string author, string filename,
|
||||
List<string> vehicleTyps, Dictionary<string, IExpression> defaultParameters,
|
||||
Dictionary<string, Dictionary<string, IExpression>> behaviours,
|
||||
IExpression access, IExpression oneway, IExpression speed,
|
||||
Dictionary<string, IExpression> priority, List<string> metadata)
|
||||
Dictionary<string, IExpression> priority, List<string> metadata, DateTime lastChange)
|
||||
{
|
||||
Name = name;
|
||||
Description = description;
|
||||
|
@ -46,6 +50,7 @@ namespace AspectedRouting.Language.Expression
|
|||
Speed = speed.Optimize();
|
||||
Priority = priority;
|
||||
Metadata = metadata;
|
||||
LastChange = lastChange;
|
||||
DefaultParameters = defaultParameters;
|
||||
Behaviours = behaviours;
|
||||
}
|
||||
|
|
|
@ -30,9 +30,7 @@ namespace AspectedRouting
|
|||
var testPath = testFileNames.FindTest(testName);
|
||||
AspectTestSuite tests = null;
|
||||
if (!string.IsNullOrEmpty(testPath) && File.Exists(testPath))
|
||||
{
|
||||
tests = AspectTestSuite.FromString(aspect, File.ReadAllText(testPath));
|
||||
}
|
||||
|
||||
aspects.Add((aspect, tests));
|
||||
}
|
||||
|
@ -44,33 +42,25 @@ namespace AspectedRouting
|
|||
{
|
||||
var testPaths = testFileNames.Where(nm => nm.EndsWith(testName)).ToList();
|
||||
if (testPaths.Count > 1)
|
||||
{
|
||||
Console.WriteLine("[WARNING] Multiple tests found for " + testName + ", using only one arbitrarily");
|
||||
}
|
||||
|
||||
if (testPaths.Count > 0)
|
||||
{
|
||||
return testPaths.First();
|
||||
}
|
||||
if (testPaths.Count > 0) return testPaths.First();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private static List<(ProfileMetaData profile, List<BehaviourTestSuite> profileTests)> ParseProfiles(
|
||||
IEnumerable<string> jsonFiles, IReadOnlyCollection<string> testFiles, Context context)
|
||||
IEnumerable<string> jsonFiles, IReadOnlyCollection<string> testFiles, Context context, DateTime lastChange)
|
||||
{
|
||||
var result = new List<(ProfileMetaData profile, List<BehaviourTestSuite> profileTests)>();
|
||||
foreach (var jsonFile in jsonFiles)
|
||||
{
|
||||
try
|
||||
{
|
||||
var profile =
|
||||
JsonParser.ProfileFromJson(context, File.ReadAllText(jsonFile), new FileInfo(jsonFile));
|
||||
if (profile == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
JsonParser.ProfileFromJson(context, File.ReadAllText(jsonFile), new FileInfo(jsonFile),
|
||||
lastChange);
|
||||
if (profile == null) continue;
|
||||
|
||||
profile.SanityCheckProfile(context);
|
||||
|
||||
|
@ -97,7 +87,6 @@ namespace AspectedRouting
|
|||
// PrintError(jsonFile, e);
|
||||
throw new Exception("In the file " + jsonFile, e);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -110,10 +99,7 @@ namespace AspectedRouting
|
|||
{
|
||||
Console.Write(profile.Name + "." + behaviour + " > ");
|
||||
var read = Console.ReadLine();
|
||||
if (read == null)
|
||||
{
|
||||
return; // End of stream has been reached
|
||||
}
|
||||
if (read == null) return; // End of stream has been reached
|
||||
|
||||
if (read == "")
|
||||
{
|
||||
|
@ -121,17 +107,11 @@ namespace AspectedRouting
|
|||
continue;
|
||||
}
|
||||
|
||||
if (read.Equals("quit"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (read.Equals("quit")) return;
|
||||
|
||||
if (read.Equals("clear"))
|
||||
{
|
||||
for (int i = 0; i < 80; i++)
|
||||
{
|
||||
Console.WriteLine();
|
||||
}
|
||||
for (var i = 0; i < 80; i++) Console.WriteLine();
|
||||
|
||||
continue;
|
||||
}
|
||||
|
@ -171,10 +151,7 @@ namespace AspectedRouting
|
|||
var tags = new Dictionary<string, string>();
|
||||
foreach (var str in tagsRaw)
|
||||
{
|
||||
if (str == "")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (str == "") continue;
|
||||
|
||||
var strSplit = str.Split("=");
|
||||
var k = strSplit[0].Trim();
|
||||
|
@ -213,10 +190,7 @@ namespace AspectedRouting
|
|||
foreach (var (key, values) in profile.AllExpressions(context).PossibleTags())
|
||||
{
|
||||
var vs = "*";
|
||||
if (values.Any())
|
||||
{
|
||||
vs = string.Join(", ", values);
|
||||
}
|
||||
if (values.Any()) vs = string.Join(", ", values);
|
||||
|
||||
Console.WriteLine(key + ": " + vs);
|
||||
}
|
||||
|
@ -224,27 +198,21 @@ namespace AspectedRouting
|
|||
Console.WriteLine("\n\n\n------------------------");
|
||||
}
|
||||
|
||||
static void Main(string[] args)
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
var errMessage = MainWithError(args);
|
||||
if (errMessage != null)
|
||||
{
|
||||
Console.WriteLine(errMessage);
|
||||
}
|
||||
if (errMessage != null) Console.WriteLine(errMessage);
|
||||
}
|
||||
public static string MainWithError(string[] args){
|
||||
if (args.Length < 2)
|
||||
{
|
||||
|
||||
public static string MainWithError(string[] args)
|
||||
{
|
||||
if (args.Length < 2)
|
||||
return "Usage: <directory where all aspects and profiles can be found> <outputdirectory>";
|
||||
}
|
||||
|
||||
var inputDir = args[0];
|
||||
var outputDir = args[1];
|
||||
|
||||
if (!Directory.Exists(outputDir))
|
||||
{
|
||||
Directory.CreateDirectory(outputDir);
|
||||
}
|
||||
if (!Directory.Exists(outputDir)) Directory.CreateDirectory(outputDir);
|
||||
|
||||
MdPrinter.GenerateHelpText(outputDir + "helpText.md");
|
||||
|
||||
|
@ -257,10 +225,7 @@ namespace AspectedRouting
|
|||
|
||||
foreach (var test in tests)
|
||||
{
|
||||
if (test.EndsWith(".test.csv") || test.EndsWith(".behaviour_test.csv"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
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'");
|
||||
|
@ -270,41 +235,35 @@ namespace AspectedRouting
|
|||
|
||||
var aspects = ParseAspects(files, tests, context);
|
||||
|
||||
foreach (var (aspect, _) in aspects)
|
||||
foreach (var (aspect, _) in aspects) context.AddFunction(aspect.Name, aspect);
|
||||
|
||||
var lastChange = DateTime.UnixEpoch;
|
||||
foreach (var file in files)
|
||||
{
|
||||
context.AddFunction(aspect.Name, aspect);
|
||||
var time = new FileInfo(file).LastWriteTimeUtc;
|
||||
if (lastChange < time)
|
||||
{
|
||||
lastChange = time;
|
||||
}
|
||||
}
|
||||
|
||||
var profiles = ParseProfiles(files, tests, context);
|
||||
var profiles = ParseProfiles(files, tests, context, lastChange);
|
||||
|
||||
|
||||
// With everything parsed and typechecked, time for tests
|
||||
var testsOk = true;
|
||||
foreach (var (aspect, t) in aspects)
|
||||
{
|
||||
if (t == null)
|
||||
{
|
||||
Console.WriteLine($"[{aspect.Name}] WARNING: no tests found: please add {aspect.Name}.test.csv");
|
||||
}
|
||||
else
|
||||
{
|
||||
testsOk &= t.Run();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach (var (profile, profileTests) in profiles)
|
||||
{
|
||||
foreach (var test in profileTests)
|
||||
{
|
||||
testsOk &= test.Run(context);
|
||||
}
|
||||
}
|
||||
foreach (var test in profileTests)
|
||||
testsOk &= test.Run(context);
|
||||
|
||||
if (!testsOk)
|
||||
{
|
||||
return "Some tests failed, quitting now without generating output";
|
||||
}
|
||||
if (!testsOk) return "Some tests failed, quitting now without generating output";
|
||||
|
||||
foreach (var (profile, profileTests) in profiles)
|
||||
{
|
||||
|
@ -324,14 +283,13 @@ namespace AspectedRouting
|
|||
behaviourName,
|
||||
context,
|
||||
aspectTests,
|
||||
profileTests.Where(testsSuite => testsSuite.BehaviourName == behaviourName)
|
||||
profileTests.Where(testsSuite => testsSuite.BehaviourName == behaviourName),
|
||||
lastChange
|
||||
).ToLua();
|
||||
if(!Directory.Exists($"{outputDir}/itinero2/"))
|
||||
{
|
||||
if (!Directory.Exists($"{outputDir}/itinero2/"))
|
||||
Directory.CreateDirectory($"{outputDir}/itinero2/");
|
||||
}
|
||||
File.WriteAllText(
|
||||
$"{outputDir}/itinero2/{profile.Name}.{behaviourName}.lua",
|
||||
$"{outputDir}/itinero2/{profile.Name}.{behaviourName}.lua",
|
||||
lua2behaviour);
|
||||
}
|
||||
}
|
||||
|
@ -341,15 +299,11 @@ namespace AspectedRouting
|
|||
);
|
||||
|
||||
if (!args.Contains("--no-repl"))
|
||||
{
|
||||
Repl(context, profiles
|
||||
.Select(p => p.profile)
|
||||
.ToDictionary(p => p.Name, p => p));
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Not starting REPL as --no-repl is specified");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue