public State(IEnumerable <Operator> operators, OtherModeBuilder otherModeBuilder, RouterDb routerDb, FileLogger logger) { Operators = new OperatorManager(operators); if (!Operators.All.Any()) { throw new ArgumentException( "No databases loaded. Is the internet connected? Is the configuration correct?"); } OtherModeBuilder = otherModeBuilder; RouterDb = routerDb; Logger = logger; BootTime = DateTime.Now; }
public void TestRegressingRoute() { Startup.ConfigureLogging(); var omb = new OtherModeBuilder("rt-cache"); var cacher = (OtherModeCache) omb.Create("osm&profile=pedestrian&maxDistance=5000", null, null); var osm = (OsmTransferGenerator)cacher.Fallback; var route = osm.CreateRoute( (50.865205, 4.35096799999999), // Herman teirlinck (50.86034, 4.36170), // Brussel Noord... out var isEmpty, out _); Assert.NotNull(route); Assert.False(isEmpty); }
public void TestOtherModeBuilderSimple() { var omb = new OtherModeBuilder(); var empty = new List <StopId>(); var crow = omb.Create("crowsflight&speed=1.4&maxDistance=500", empty, empty); var cf = crow as CrowsFlightTransferGenerator; Assert.NotNull(cf); Assert.Equal((uint)500, cf.Range()); var crow0 = omb.Create("crowsflight&speed=1&maxDistance=1500", empty, empty); var cf0 = crow0 as CrowsFlightTransferGenerator; Assert.NotNull(cf0); Assert.Equal((uint)1500, cf0.Range()); }
public void TestOtherModeBuilderFirstLast() { var omb = new OtherModeBuilder(); var empty = new List <StopId>(); var desc = "firstLastMile" + "&firstMile=" + Uri.EscapeDataString( "osm&profile=pedestrian&maxDistance=1000") + "&default=" + Uri.EscapeDataString("crowsflight&maxDistance=1500") + "&lastMile=" + Uri.EscapeDataString("osm&profile=pedestrian&maxDistance=5000"); var gen = omb.Create(desc, empty, empty); var flm = gen as FirstLastMilePolicy; Assert.NotNull(flm); Assert.Equal((uint)5000, flm.Range()); var exp = "firstLastMile" + "&default=crowsflight&maxDistance=1500&speed=1.4" + "&firstMile=osm&maxDistance=1000&profile=pedestrian" + "&lastMile=osm&maxDistance=5000&profile=pedestrian"; Assert.Equal(exp, flm.OtherModeIdentifier()); // Oops, we forgot to escape! desc = "firstLastMile" + "&firstMile=" + "osm&profile=pedestrian&maxDistance=1001" + "&default=" + "crowsflight" + "&lastMile=" + "osm"; try { gen = omb.Create(desc, empty, empty); Assert.True(false); } catch (ArgumentException) { // Expected behaviour } }
public void BuilderTest() { var builder = new OtherModeBuilder(); builder.SupportedUrls(); }
private void StartLoadingTransitDbs() { OtherModeBuilder otherModeBuilder; string routableTileCache = null; if (Configuration["RoutableTilesCache"] != null) { routableTileCache = Configuration.GetValue <string>("RoutableTilesCache"); } try { otherModeBuilder = new OtherModeBuilder(routableTileCache, Configuration.GetSection("OsmProfiles")); } catch (Exception e) { Log.Error("Could not create all the other profiles: " + e); otherModeBuilder = new OtherModeBuilder(); } var fileLogger = new FileLogger("logs"); var operators = Configuration.LoadOperators(); var state = new State( operators, otherModeBuilder, otherModeBuilder.RouterDb, fileLogger ) { FreeMessage = "Loading transitdbs" }; Log.Information("Loaded configuration"); State.GlobalState = state; Log.Information("Loaded tdbs are " + string.Join(", ", state.Operators.GetFullView().Operators .Select(kvp => kvp.Name))); state.NameIndex = new NameIndexBuilder(new List <string> { "name:nl", "name", "name:fr" }) .Build(state.Operators.GetFullView().GetStopsReader()); Log.Information("Performing initial runs"); state.FreeMessage = "Running initial data syncs"; var allOperators = state.Operators.GetFullView(); foreach (var provider in allOperators.Operators) { try { Log.Information($"Starting initial run of {provider.Name}"); provider.Synchronizer.InitialRun(); } catch (Exception e) { Log.Error($"Caught exception while running initial data sync: {e.Message}\n{e}"); } } foreach (var provider in allOperators.Operators) { try { Log.Information($"Starting synchronizer for {provider.Name}"); provider.Synchronizer.Start(); } catch (Exception e) { Log.Error($"Caught exception while running initial data sync: {e.Message}\n{e}"); } } state.FreeMessage = "Fully operational"; }