Ejemplo n.º 1
0
        // Finds the closest stop for the given route name and gets arrival data for that stop
        // Returns a list of DateTimes for the timezone of the given lat/lon
        public async Task <List <double> > GetArrivalTimesForRouteName(string routeShortName, string lat, string lon, DateTime time)
        {
            // validate lat,lon inputs
            GeocodeHelpers.ValidateLatLon(lat, lon);

            // find the route object for the given name and the closest stop for that route
            // demo tuples
            (Route, Stop)info = await GetRouteAndStopForLocation(routeShortName, lat, lon);

            List <ArrivalsAndDeparture> arrivalData = await GetArrivalsAndDepartures(info.Item2.Id, info.Item1.ShortName);

            var universalTime            = time.ToUniversalTime();
            IEnumerable <DateTime> query = from a in arrivalData
                                           select BusHelpers.ConvertMillisecondsToUTC(a.PredictedArrivalTime);

            //demo sourcelink
            var busTimes = arrivalData.Select(a => BusHelpers.ConvertMillisecondsToUTC(a.PredictedArrivalTime)).Take(3);

            var timeUntil = new List <double>();

            foreach (var t in busTimes)
            {
                var delta = t - universalTime;
                //demo had to add in the Round bc was off in decimals
                var min = Math.Round(delta.TotalMinutes, 1);
                timeUntil.Add(min);
                //timeUntil.Add(delta.TotalMinutes);
            }
            return(timeUntil);
        }