private async Task initializeNearStops(StopParameter param) { if (param.Location == null || param.Location.IsNear) { this.ViewModel.NearStops = param.StopGroup .Transfers(300) .GroupBy(t => t.Target.Group) .Where(g => g.Key != param.StopGroup) .Select(g => new NearStopModel { Stop = g.Key, Distance = g.Average(t => t.Distance) }) .ToList(); } //else if (param.Location.IsNear) //{ // throw new NotImplementedException(); //} else if (param.Location.Stop != null) { var nearStops = await StopTransfers.NearStopsFrom(param.Location.Stop, 300); this.ViewModel.NearStops = nearStops .GroupBy(t => t.Stop.Group) .Where(g => g.Key != param.StopGroup) .Select(g => new NearStopModel { Stop = g.Key, Distance = g.Average(t => t.DistanceInMeters) }) .OrderBy(m => m.Distance) .ToList(); } else { throw new InvalidOperationException(); } }
private async Task setNextTrips(DateTime time) { if (Location != null) { if (Near) { var dist = await StopTransfers.WalkDistance(Location, CurrentStop.Coordinate); setDistanceText(Services.Resources.LocalizedStringOf("TripStopDistance"), Location, dist.DistanceInMeters); setNextTripsAtTime(time + dist.EstimatedDuration, time); var newLocation = await CurrentLocation.Get(); if (newLocation != null && newLocation != Location) { this.Location = newLocation; var dist1 = await StopTransfers.WalkDistance(Location, CurrentStop.Coordinate); setDistanceText(Services.Resources.LocalizedStringOf("TripStopDistance"), Location, dist1.DistanceInMeters); setNextTripsAtTime(time + dist1.EstimatedDuration, time); } } else { var dist = await StopTransfers.WalkDistance(SourceStop.Coordinate, CurrentStop.Coordinate); setDistanceText(Services.Resources.LocalizedStringOf("TripTransferDistance"), Location, dist.DistanceInMeters); setNextTripsAtTime(time + dist.EstimatedDuration, time); } } else { setNextTripsAtTime(time, time); } }
private async void SetBoundaries(IMapControl map, LocationRectangle boundaries, bool noStopInParameter) { await Task.Delay(250); await initializeMapLabels(map); await map.TrySetViewBoundsAsync(boundaries, false); //while (page.ZoomLevel < 15) //{ // page.SetView(boundaries, MapAnimationKind.None); // await Task.Delay(100); //} //while (page.IsMapEmpty) //{ // initializeMapLabels(page); // await Task.Delay(100); //} map.CenterChanged += async(sender, args) => { await mapFillingLock.WaitAsync(); if (map.ZoomLevel >= App.Config.LowStopsMapLevel) { await tryCreateStopLabelsAt(map, map.Center); } else if (map.ZoomLevel >= App.Config.HighStopsMapLevel) { await tryCreateHighStopLabelsAt(map, map.Center); clearMap(map, 2.1); } else { clearMap(map); } mapFillingLock.Release(); }; if (isNear && noStopInParameter && mainPoints.Length == 0) { var nearestResult = await StopTransfers.GetNearestStop(CurrentLocation.Last); if (nearestResult != null) { this.location = CurrentLocation.Last; this.mainPoints = nearestResult.Stop.Group.Stops.Select(s => s.Coordinate).ToArray(); var boundAddition = new GeoCoordinate[] { CurrentLocation.Last ?? App.Config.CenterLocation }; boundaries = calculateBoundaries(mainPoints.Concat(boundAddition)); await map.TrySetViewBoundsAsync(boundaries, false); await initializeMapLabels(map); } } }
//private AdControl AdControl; //public void SetPlanningSource(StopGroup stop) //{ //} //public void SetPlanningDestination(StopGroup stop) //{ //} private async void updateContent() { FavoritesPart.UpdateContent(); if (SettingsModel.AutomaticNearSearch) { var nearestStop = await StopTransfers.GetNearestStop(await CurrentLocation.Get()); if (nearestStop != null) { FavoritesPart.NearStop = nearestStop.Stop.Group; PlanningPart.SetNearStop(nearestStop.Stop.Group, nearestStop.EstimatedDuration); } } }
private async Task setMostNarrowRange() { StatusBar.GetForCurrentView().ProgressIndicator.ProgressValue = null; StatusBar.GetForCurrentView().ProgressIndicator.ShowAsync(); for (int i = 0; i < DistanceSelection.Length; i++) { radius = DistanceSelection[i]; var nearStops = (await StopTransfers.NearStops(await CurrentLocation.Get(), radius.Value)).ToList(); if (nearStops.Count > 0) { BtnDist.SelectedItem = radius; ListView.ItemsSource = nearStops.Select(s => new StopModel(s.StopGroup, true)).ToList(); break; } } StatusBar.GetForCurrentView().ProgressIndicator.HideAsync(); }
public async void SetListContent() { StatusBar.GetForCurrentView().ProgressIndicator.ProgressValue = null; StatusBar.GetForCurrentView().ProgressIndicator.ShowAsync(); var location = await CurrentLocation.Get(); //logging UniversalDirections.QueryTimes.Clear(); var sw = Stopwatch.StartNew(); var nearStops = await StopTransfers.NearStops(location, radius.Value); sw.Stop(); ListView.ItemsSource = nearStops.Select(s => new StopModel(s.StopGroup, true)).ToList(); ListView.Height = ListView.ItemsSource().Count > 0 ? double.NaN : 0; StatusBar.GetForCurrentView().ProgressIndicator.HideAsync(); PerfLogging.AddRow( "setListContent", sw.Elapsed, UniversalDirections.QueryTimes.Count, UniversalDirections.QueryTimes.Count > 0 ? UniversalDirections.QueryTimes.Average(x => x.TotalMilliseconds) : 0.0); }
public static async Task <List <RouteModel> > CalculateRoutes(IEnumerable <Stop> stops, DateTime startTime, GeoCoordinate location = null, Stop sourceStop = null, double distanceLimit = double.MaxValue) { //Kiszámolom az indulási időket az egyes stop-triptype párosokhoz bool isFar = false; var targetWalkStops = stops.Select(s => new StopDistanceResult { Stop = s }); if (location != null) { if (location.GetDistanceTo(stops.First().Coordinate) < distanceLimit) { if (sourceStop != null) { targetWalkStops = await StopTransfers.WalkDistances(sourceStop, stops); } else { targetWalkStops = await StopTransfers.WalkDistances(location, stops); } } else { isFar = true; } } return(await Task.Run(() => { //if (currentTime) startTime = DateTime.Now; List <RouteModel> routes = new List <RouteModel>(); int i = 0; foreach (var curWalkStop in targetWalkStops) { TimeSpan walkTime = location != null && curWalkStop.DistanceInMeters < distanceLimit ? curWalkStop.EstimatedDuration : TimeSpan.Zero; foreach (Route route in curWalkStop.Stop.Routes.Where(r => r.TravelRoute.Last().Stop != curWalkStop.Stop.Group)) //foreach (var routeAndIndex in curWalkStop.Stop.GetRoutes()) { var model = new RouteModel { //Route = routeAndIndex.Item1, //Position = routeAndIndex.Item2, Route = route, Stop = curWalkStop.Stop, WalkTime = walkTime, Distance = curWalkStop.DistanceInMeters, IsFar = isFar || curWalkStop.DistanceInMeters >= distanceLimit, NoLocation = (location == null) }; model.SetNextArrive(startTime); if (model.HasAnyTrip) { routes.Add(model); } } i++; } //összerántom az azonos és azonos célú route-okat var ret = routes .GroupBy(x => x.Route).Select(x => x.MinBy(e => e.NextTripTime ?? DateTime.MaxValue)) .OrderBy(r => r.NextTripTime ?? DateTime.MaxValue) .Distinct(new RouteEqualityComparer()); //Ha szentendrei a következő, akkor a következő békásit is ki kell írni (szentendreire kattintva nem látszanának) //ezért a szentendrére menő békási HÉV-et léptetem amíg békási nem lesz var grouped = ret.Where(x => x.NextTrip != null).GroupBy(x => x.NextTrip).Where(x => x.Count() > 1); foreach (var groupedRoute in grouped.SelectMany(x => x).Where(x => x.NextTrip.Route != x.Route)) { while (groupedRoute.HasAnyTrip && groupedRoute.NextTrip != null && groupedRoute.Route != groupedRoute.NextTrip.Route) { groupedRoute.SetNextArrive(startTime); } } return ret .Where(r => r.HasAnyTrip) .OrderByText(r => r.RouteGroup.Name + " " + r.Name) .OrderBy(r => r.RouteGroup.GetCustomTypePriority()) .OrderBy(r => r.NextTripTime ?? DateTime.MaxValue) .ToList(); })); }
public override async void Bind(MapPage page) { base.Bind(page); base.RegisterElementTypes(typeof(StopPushpin)); int stopGroupId = int.Parse(page.NavigationContext.QueryString["stopGroupID"]); if (stopGroupId != 0) { this.stopGroup = App.Model.GetStopGroupByID(stopGroupId); this.mainStops = new HashSet <Stop>(stopGroup.Stops); this.mainPoints = mainStops.Select(s => s.Coordinate).ToArray(); } else { this.fromMainPage = true; if (StopTransfers.LastNearestStop != null) { this.mainPoints = StopTransfers.LastNearestStop.Stop.Group.Stops.Select(s => s.Coordinate).ToArray(); } } string locationStr = null, dateTimeStr = null; if (page.NavigationContext.QueryString.TryGetValue("location", out locationStr)) { this.postQuery.Add("location", locationStr); if (locationStr != "near") { this.sourceStop = App.Model.GetStopByID(int.Parse(locationStr)); this.location = sourceStop.Coordinate; } else { this.location = CurrentLocation.Last; isNear = true; } } if (page.NavigationContext.QueryString.TryGetValue("dateTime", out dateTimeStr)) { this.postQuery.Add("dateTime", dateTimeStr); this.dateTime = System.Convert.ToDateTime(dateTimeStr); isNow = false; } if (isNow) { timeUpdaterTask = new PeriodicTask(DoTimeUpdate); timeUpdaterTask.RunEveryMinute(); page.Tasks.Add(timeUpdaterTask); } if (isNear) { locationUpdaterTask = new PeriodicTask(10000, DoLocationUpdate); locationUpdaterTask.Run(delay: 1000); page.Tasks.Add(locationUpdaterTask); } //foreach (var transfer in transfers) //{ // Microsoft.Phone.Maps.Controls.MapPolyline line = new Microsoft.Phone.Maps.Controls.MapPolyline // { // StrokeColor = Colors.Gray, // StrokeDashed = true, // StrokeThickness = 8 // }; // line.Path.Add(transfer.Origin.Coordinate); // line.Path.AddRange(transfer.InnerPoints.Select(p => new GeoCoordinate(p.Latitude, p.Longitude))); // line.Path.Add(transfer.Target.Coordinate); // Map.MapElements.Add(line); //} this.EmptyMapTap += (sender, args) => clearSelection(); this.MapElementTap += (sender, element) => tapActions[element].Invoke(); var boundAddition = isNear ? new GeoCoordinate[] { CurrentLocation.Last ?? App.Config.CenterLocation } : new GeoCoordinate[0]; var boundaries = calculateBoundaries(mainPoints.Concat(boundAddition)); //await Task.Delay(250); await initializeMapLabels(page); page.Map.SetView(boundaries, MapAnimationKind.None); while (page.Map.ZoomLevel < 15) { page.Map.SetView(boundaries, MapAnimationKind.None); await Task.Delay(100); } //while (page.IsMapEmpty) //{ // initializeMapLabels(page); // await Task.Delay(100); //} page.Map.CenterChanged += async(sender, args) => { await mapFillingLock.WaitAsync(); if (page.Map.ZoomLevel >= App.Config.LowStopsMapLevel) { var newLocation = page.Map.Center; await tryCreateStopLabelsAt(page, Convert(newLocation)); } else if (page.Map.ZoomLevel >= App.Config.HighStopsMapLevel) { var newLocation = page.Map.Center; await tryCreateHighStopLabelsAt(page, Convert(newLocation)); clearMap(page, 2.1); } else { clearMap(page); } mapFillingLock.Release(); }; if (isNear && stopGroupId == 0 && mainPoints.Length == 0) { var nearestResult = await StopTransfers.GetNearestStop(await CurrentLocation.Get()); if (nearestResult != null) { this.location = CurrentLocation.Last; this.mainPoints = nearestResult.Stop.Group.Stops.Select(s => s.Coordinate).ToArray(); boundAddition = new GeoCoordinate[] { CurrentLocation.Last ?? App.Config.CenterLocation }; boundaries = calculateBoundaries(mainPoints.Concat(boundAddition)); page.Map.SetView(boundaries, MapAnimationKind.None); await initializeMapLabels(page); } } }