Exemplo n.º 1
0
        private static void PrintUsedTags(ProfileMetaData profile, Context context)
        {
            Console.WriteLine("\n\n\n---------- " + profile.Name + " --------------");
            foreach (var(key, values) in profile.AllExpressions(context).PossibleTags())
            {
                var vs = "*";
                if (values.Any())
                {
                    vs = string.Join(", ", values);
                }

                Console.WriteLine(key + ": " + vs);
            }

            Console.WriteLine("\n\n\n------------------------");
        }
Exemplo n.º 2
0
        public string ToLua()
        {
            _skeleton.AddDep("spoken_instructions");

            var(membershipFunction, extraKeys)       = GenerateMembershipPreprocessor();
            var(profileOverview, behaviourFunctions) = GenerateProfileFunctions();
            var mainFunction = GenerateMainProfileFunction();
            var tests        = new LuaTestPrinter(_skeleton, new List <string> {
                "unitTest", "unitTestProfile"
            }).GenerateFullTestSuite(_profileTests, _aspectTestSuites);


            var keys = _profile.AllExpressions(_context).PossibleTags().Keys
                       .Concat(extraKeys)
                       .Select(key => "\"" + key + "\"")
                       .ToHashSet();

            var header = new List <string>
            {
                $"-- Itinero 1.0-profile, generated by AspectedRouting.",
                $"name = \"{_profile.Name}\"",
                "normalize = false",
                "vehicle_types = {" + string.Join(", ", _profile.VehicleTyps.Select(s => "\"" + s + "\"")) + "}",
                // meta_whitelist is defined in the profile file, these are tags that are included in the generated route, but are not relevant for determining weights
                "meta_whitelist = {\n"
                + string.Join("\n    , ", _profile.Metadata.Select(s => "\"" + s + "\""))
                + " }",
                "profile_whitelist = {\n      " + string.Join("\n    , ", keys) + "\n    }",
                "",
                "",
                "",
                profileOverview,
                "",
                _parameterPrinter.GenerateDefaultParameters()
            };


            // Add the aspect functions to the skeleton
            var usedFunctions = _profile.CalledFunctionsRecursive(_context).Values.SelectMany(v => v).ToHashSet();

            foreach (var functionName in usedFunctions)
            {
                _skeleton.AddFunction(_context.GetAspect(functionName));
            }


            // The dependencies should be generated after all the other functions are generated, to make sure all are added
            var dependencies = _skeleton.GenerateDependencies();
            var functions    = _skeleton.GenerateFunctions();

            var allCode = new List <List <string> >
            {
                header,
                behaviourFunctions,
                mainFunction.InList(),
                membershipFunction.InList(),
                "---------------------- ASPECTS ----------------------".InList(),
                functions,
                "---------------------- UTILS ------------------------".InList(),
                dependencies,
                _skeleton.GenerateConstants().ToList(),
                "----------------------- TESTS ------------------------".InList(),
                tests.InList(),
                GenerateLegacyTail().InList()
            };


            return(string.Join("\n\n\n", allCode.Select(code => string.Join("\n", code))));
        }