public GoogleDirectionsInput Create(string originId, string destinationId, GoogleTravelMode mode, DateTime departureTime) { LanguageType language = LanguageType.Pl; var startSeconds = GooglePlaceCalculator.ConvertToUnixTimestamp(departureTime); return(new GoogleDirectionsInput(originId, destinationId, mode, language, startSeconds)); }
public GoogleDirectionsInput Create(Location origin, Location destination, GoogleTravelMode mode, DateTime departureTime) { LanguageType language = LanguageType.Pl; var startSeconds = GooglePlaceCalculator.ConvertToUnixTimestamp(departureTime); if (startSeconds < 0) { return(new GoogleDirectionsInput(origin, destination, mode, language)); } else { return(new GoogleDirectionsInput(origin, destination, mode, language, startSeconds)); } }
public async Task <IList <int> > Optimize(DecisionArray decisionArray, Plan plan, int?elementsCount = null) { if (!elementsCount.HasValue) { elementsCount = decisionArray.DecisionRows.Count; } var waypoints = decisionArray.DecisionRows.Take(elementsCount.Value) .Select(x => x.Candidate.Location).ToList(); var startSeconds = GooglePlaceCalculator.ConvertToUnixTimestamp(plan.PlanForm.StartDateTime); GoogleTravelMode mode; if (plan.PlanForm.PreferedTravelModes.Contains(GoogleTravelMode.Driving)) { mode = GoogleTravelMode.Driving; } else if (plan.PlanForm.PreferedTravelModes.Contains(GoogleTravelMode.Walking)) { mode = GoogleTravelMode.Walking; } else if (plan.PlanForm.PreferedTravelModes.Contains(GoogleTravelMode.Bicycling)) { mode = GoogleTravelMode.Bicycling; } else { mode = GoogleTravelMode.Transit; } var optimizeApiInput = _googleDirectionsInputFactory.CreateOptimizedWaypoints(plan.StartLocation, plan.StartLocation, mode, waypoints, startSeconds); var result = await _googleDirectionsApiClient.GetAsync(optimizeApiInput); if (result.IsOk) { var optimizedOrder = result.routes.First(); return(optimizedOrder.waypoint_order); } else { throw new UserFriendlyException($"Nie udało się zoptymalizować kolejności elementów planu (Problem komiwojażera)!"); } }