/// <summary>
        /// Gets the ETA info for a set of stop IDS.
        /// The outer dictionary takes a route number and gives a dictionary that takes a stop ID to an ETA.
        /// </summary>
        public static async Task <BusArrivalEstimates> GetEtas(ITransitRepository repository, ITransitClient client, IEnumerable <int> stopIds)
        {
            var toPlatformTag = await repository.GetPlatformTagsAsync();

            Func <int, Task <Tuple <int, ConnexionzPlatformET> > > getEtaIfTagExists =
                async id => Tuple.Create(id, toPlatformTag.ContainsKey(id) ? await client.GetEta(toPlatformTag[id]) : null);

            var tasks   = stopIds.Select(getEtaIfTagExists);
            var results = await Task.WhenAll(tasks);

            return(results.ToDictionary(eta => eta.Item1,
                                        eta => eta.Item2?.RouteEstimatedArrivals
                                        ?.ToDictionary(routeEta => routeEta.RouteNo,
                                                       routeEta => routeEta.EstimatedArrivalTime)
                                        ?? new Dictionary <string, List <int> >()));
        }
Beispiel #2
0
        /// <summary>
        /// Gets the ETA info for a set of stop IDS.
        /// The outer dictionary takes a route number and gives a dictionary that takes a stop ID to an ETA.
        /// </summary>
        public static async Task <BusArrivalEstimates> GetEtas(ITransitRepository repository, ITransitClient client, IEnumerable <int> stopIds)
        {
            var toPlatformTag = await repository.GetPlatformTagsAsync();

            var tasks   = stopIds.Select(getEtaIfTagExists);
            var results = await Task.WhenAll(tasks);

            return(results.ToDictionary(eta => eta.stopId,
                                        eta => eta.platformET?.RouteEstimatedArrivals
                                        ?.ToDictionary(routeEta => routeEta.RouteNo,
                                                       routeEta => routeEta.EstimatedArrivalTime)
                                        ?? new Dictionary <string, List <int> >()));

            async Task <(int stopId, ConnexionzPlatformET?platformET)> getEtaIfTagExists(int id)
            => (id, toPlatformTag.TryGetValue(id, out int tag) ? await client.GetEta(tag) : null);
        }
        /// <summary>
        /// Gets the ETA info for a set of stop IDS.
        /// The outer dictionary takes a route number and gives a dictionary that takes a stop ID to an ETA.
        /// </summary>
        public static async Task<BusArrivalEstimates> GetEtas(ITransitRepository repository, ITransitClient client, IEnumerable<int> stopIds)
        {
            var toPlatformTag = await repository.GetPlatformTagsAsync();
            
            Func<int, Task<Tuple<int, ConnexionzPlatformET>>> getEtaIfTagExists =
                async id => Tuple.Create(id, toPlatformTag.ContainsKey(id) ? await client.GetEtaAsync(toPlatformTag[id]) : null);

            var tasks = stopIds.Select(getEtaIfTagExists);
            var results = await Task.WhenAll(tasks);

            return results.ToDictionary(eta => eta.Item1,
                eta => eta.Item2?.RouteEstimatedArrivals
                                ?.ToDictionary(routeEta => routeEta.RouteNo,
                                               routeEta => routeEta.EstimatedArrivalTime)
                       ?? new Dictionary<string, List<int>>());
        }