public ActionResult <PlannedTour> Get([FromBody] PlanTourParameters planTourParameters) { this.logger.LogDebug($"Planning tour with {planTourParameters.WaypointIdList.Count} waypoints..."); var watch = new Stopwatch(); watch.Start(); try { var result = this.engine.PlanTour(planTourParameters); return(result); } catch (Exception ex) { this.logger.LogError(ex, "Exception while planning tour"); return(this.BadRequest(ex.Message)); } finally { watch.Stop(); this.logger.LogDebug($"Planning tour took {watch.ElapsedMilliseconds} ms."); } }
public void TestPlanTour_TwoPoints() { // set up var engine = new PlanTourEngine(); engine.LoadGraph(GetPlanTourKmlStream()); // run var planTourParameters = new PlanTourParameters { WaypointIdList = new List <string> { "wheretofly-path-bahnhof-neuhaus", "wheretofly-path-rauhkopf", } }; var tour = engine.PlanTour(planTourParameters); // check Assert.IsTrue(tour.Description.Any(), "description must contain text"); Assert.IsTrue(tour.TotalDuration.TotalMinutes > 0, "total duration must contain value"); Assert.IsTrue(tour.TourEntriesList.Any(), "tour entries list must be filled"); Assert.IsTrue(tour.MapPointList.Any(), "map point list must be filled"); }
/// <summary> /// Plans a tour with given waypoints /// </summary> /// <param name="planTourParameters">tour planning parameters</param> /// <returns>planned tour</returns> public PlannedTour PlanTour(PlanTourParameters planTourParameters) { this.CheckTourPlanningArguments(planTourParameters); var vertexList = (from waypointId in planTourParameters.WaypointIdList select this.FindWaypointInfo(waypointId)).ToList(); var tour = new PlannedTour(); var descriptionText = new StringBuilder(); var totalDuration = TimeSpan.Zero; for (int index = 1; index < vertexList.Count; index++) { var source = vertexList[index - 1]; var target = vertexList[index]; this.PlanSingleTourStep(source, target, tour, descriptionText, ref totalDuration); if (index + 1 == vertexList.Count) { descriptionText.Append($"Ende-Wegpunkt: {target.Description}\n"); } } tour.Description = descriptionText.ToString(); tour.TotalDuration = totalDuration; return(tour); }
/// <summary> /// Plans tour using network service and shows activity indicator while planning. When an /// error occured, a message is shown and no tour is returned. /// </summary> /// <param name="planTourParameters">parameters for planning tour</param> /// <returns>planned tour, or null on planning errors</returns> private async Task <Tour> PlanTourAsync(PlanTourParameters planTourParameters) { var networkService = DependencyService.Get <INetworkService>(); try { this.IsPlanningActive = true; var plannedTour = await networkService.PlanTourAsync(planTourParameters, CancellationToken.None); return(plannedTour); } catch (Exception ex) { log.Error("error while planning tour", ex); this.IsPlanningActive = false; MessagingCenter.Send( this, "DisplayAlert", "Error while planning tour!"); } finally { this.IsPlanningActive = false; } return(null); }
/// <summary> /// Creates a new popup page object /// </summary> /// <param name="planTourParameters">tour planning parameters</param> public PlanTourPopupPage(PlanTourParameters planTourParameters) { this.CloseWhenBackgroundIsClicked = true; this.InitializeComponent(); this.BindingContext = new PlanTourPopupViewModel(planTourParameters, this.ClosePopupPage); }
/// <summary> /// Creates a new view model object for "plan tour" view. /// </summary> public PlanTourViewModel() { this.isStartLocationRequiredVisible = false; this.isTourLocationRequiredVisible = false; this.isPlanningActive = false; this.PlanTourParameters = new PlanTourParameters(); this.SetupBindings(); }
/// <summary> /// Plans a tour with given parameters and returns planned tour; may throw exception when /// no tour could be planned with the given parameters. Using demo data, only returning /// tours with parameters that match a pre-planned tour. /// </summary> /// <param name="planTourParams">parameters to plan tour</param> /// <param name="token">token to cancel operation</param> /// <returns>planned tour</returns> public async Task <Tour> PlanTourAsync(PlanTourParameters planTourParams, CancellationToken token) { var prePlannedTourList = DemoData.DataProvider.FindPrePlannedTourList(planTourParams); if (prePlannedTourList != null) { return(await Task.FromResult(prePlannedTourList.Tour)); } throw new System.Exception("Tour couldn't be calculated"); }
public Tour Get([FromBody] PlanTourParameters planTourParams) { var prePlannedTourList = HikingPathFinder.DemoData.DataProvider.FindPrePlannedTourList(planTourParams); if (prePlannedTourList != null) { return(prePlannedTourList.Tour); } throw new System.Exception("Tour couldn't be calculated"); }
/// <summary> /// Plans a tour with given parameters and returns planned tour; may throw exception when /// no tour could be planned with the given parameters. /// </summary> /// <param name="planTourParams">parameters to plan tour</param> /// <param name="cancellationToken">token to cancel operation</param> /// <returns>planned tour</returns> public async Task <Tour> PlanTourAsync(PlanTourParameters planTourParams, CancellationToken cancellationToken) { string parameter = JsonConvert.SerializeObject(planTourParams); Tour result = await this.SendRequestAsync <Tour>( "api/planTour", HttpMethod.Get, parameter, cancellationToken); return(result); }
public PlannedTour Get([FromBody] PlanTourParameters planTourParameters) { this.logger.LogDebug($"Planning tour with {planTourParameters.WaypointIdList.Count} waypoints..."); var watch = new Stopwatch(); watch.Start(); var result = this.engine.PlanTour(planTourParameters); watch.Stop(); this.logger.LogDebug($"Planning tour took {watch.ElapsedMilliseconds} ms."); return(result); }
public void TestPlanTour_GrandTour() { // set up var engine = new PlanTourEngine(); engine.LoadGraph(GetPlanTourKmlStream()); // run var planTourParameters = new PlanTourParameters { WaypointIdList = new List <string> { "wheretofly-path-bahnhof-neuhaus", "wheretofly-path-spitzingsattel", "wheretofly-path-jagerkamp", ////"wheretofly-path-benzingspitz", "wheretofly-path-tanzeck", "wheretofly-path-aiplspitz", "wheretofly-path-rauhkopf", "wheretofly-path-taubensteinhaus", "wheretofly-path-hochmiesing", "wheretofly-path-rotwand", "wheretofly-path-rotwandhaus", "wheretofly-path-lempersberg", "wheretofly-path-taubenstein", ////"wheretofly-path-albert-link-haus", ////"wheretofly-path-stolzenberg", ////"wheretofly-path-rotkopf", ////"wheretofly-path-rosskopf", ////"wheretofly-path-stuempfling", ////"wheretofly-path-bodenschneid", ////"wheretofly-path-brecherspitz", "wheretofly-path-bahnhof-neuhaus", } }; var tour = engine.PlanTour(planTourParameters); // check Assert.IsTrue(tour.Description.Any(), "description must contain text"); Assert.IsTrue(tour.TotalDuration.TotalMinutes > 0, "total duration must contain value"); Assert.IsTrue(tour.TourEntriesList.Any(), "tour entries list must be filled"); Assert.IsTrue(tour.MapPointList.Any(), "map point list must be filled"); }
public void TestPlanTour_OnePoint() { // set up var engine = new PlanTourEngine(); engine.LoadGraph(GetPlanTourKmlStream()); // run var planTourParameters = new PlanTourParameters { WaypointIdList = new List <string> { "wheretofly-path-bahnhof-neuhaus", } }; Assert.ThrowsException <InvalidOperationException>( () => engine.PlanTour(planTourParameters)); }
/// <summary> /// Checks all tour planning arguments for validity /// </summary> /// <param name="planTourParameters">tour planning parameters</param> private void CheckTourPlanningArguments(PlanTourParameters planTourParameters) { if (planTourParameters == null) { throw new ArgumentNullException(nameof(planTourParameters)); } if (planTourParameters.WaypointIdList.Count < 2) { throw new InvalidOperationException("there must be at least two waypoints for tour planning"); } // check if one of the waypoints can't be found string invalidWaypointId = planTourParameters.WaypointIdList.FirstOrDefault( waypointId => this.FindWaypointInfo(waypointId) == null); if (invalidWaypointId != null) { throw new ArgumentException($"invalid waypoint id for tour planning: {invalidWaypointId}"); } }
/// <summary> /// Finds pre-planned tour from given plan tour parameters /// </summary> /// <param name="planTourParams">plan tour params</param> /// <returns>pre-planned tour, or null when no tour was found</returns> public static PrePlannedTour FindPrePlannedTourList(PlanTourParameters planTourParams) { var prePlannedTourList = DemoData.DataProvider.GetPrePlannedTourList(); foreach (var prePlannedTour in prePlannedTourList) { bool startLocationMatches = planTourParams.StartLocation.Id == prePlannedTour.Tour.StartLocation.Id; bool endLocationAvailable = planTourParams.EndLocation != null && prePlannedTour.Tour.EndLocation != null; bool endLocationMatches = endLocationAvailable && planTourParams.EndLocation.Id == prePlannedTour.Tour.EndLocation.Id; if (startLocationMatches && (!endLocationAvailable || endLocationMatches)) { bool hasSameLocations = true; foreach (var locationRef in planTourParams.TourLocationList) { if (prePlannedTour.Tour.LocationList.Find(x => x.Id == locationRef.Id) == null) { hasSameLocations = false; break; } } if (hasSameLocations) { return(prePlannedTour); } } } return(null); }
/// <summary> /// Plans a tour with given tour planning parameters and returns the planned tour. /// </summary> /// <param name="planTourParameters">tour planning parameters</param> /// <returns>planned tour</returns> public async Task <PlannedTour> PlanTourAsync(PlanTourParameters planTourParameters) { return(await this.backendDataService.PlanTourAsync(planTourParameters)); }
/// <summary> /// Plans a tour with given parameters and returns a planned tour, including description /// and a track. /// </summary> /// <param name="planTourParameters">tour planning parameters</param> /// <returns>planned tour</returns> public async Task <PlannedTour> PlanTourAsync(PlanTourParameters planTourParameters) { return(await this.backendWebApi.PlanTourAsync(planTourParameters)); }
/// <summary> /// Creates a new user settings object with default values /// </summary> public UserSettings() { this.ShowMapIn3D = false; this.CurrentPlanTourParameters = new PlanTourParameters(); }
/// <summary> /// Shows "Plan tour" popup page and lets the user edit the tour location list. /// </summary> /// <param name="planTourParameters">tour planning parameters</param> /// <returns>task to wait for</returns> public static async Task ShowAsync(PlanTourParameters planTourParameters) { var popupPage = new PlanTourPopupPage(planTourParameters); await popupPage.Navigation.PushPopupAsync(popupPage); }