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);
        }
Ejemplo n.º 2
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 <DateTime> > GetArrivalTimesForRouteName(string routeShortName, string lat, string lon)
        {
            BusHelpers.ValidateLatLon(lat, lon);
            // find the route object for the given name and the closest stop for that route
            (Route route, Stop stop) = await GetRouteAndStopForLocation(routeShortName, lat, lon);

            List <ArrivalsAndDeparture> arrivalData = await GetArrivalsAndDepartures(stop.Id, route.ShortName);

            IEnumerable <DateTime> UtcData = arrivalData.Select(a => new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)
                                                                .AddMilliseconds(Convert.ToDouble(a.PredictedArrivalTime))).Take(3);
            // Convert from UTC to user's timezone
            TimeZoneInfo timeZoneInfo = await GetTimeZoneInfoAsync(lat, lon);

            IEnumerable <DateTime> UserTimeData = UtcData.Select(d => TimeZoneInfo.ConvertTimeFromUtc(d, timeZoneInfo));

            return(UserTimeData.ToList());
        }
Ejemplo n.º 3
0
        // Returns the arrivals and departure data if it contains the route name
        public List <ArrivalsAndDeparture> FindArrivalsForRoute(string routeShortName, string stopId, string json)
        {
            List <ArrivalsAndDeparture> arrivalsAndDeparture = new List <ArrivalsAndDeparture>();
            JObject jobject = JObject.Parse(json);

            if (jobject["code"].ToString() == "200")
            {
                List <JToken>        results      = jobject["data"]["entry"]["arrivalsAndDepartures"].Children().ToList();
                IEnumerable <JToken> searchResult = results.Where(x => BusHelpers.CleanRouteName(x["routeShortName"].ToString()) == routeShortName);
                if (searchResult.Count() > 0)
                {
                    foreach (JToken s in searchResult)
                    {
                        ArrivalsAndDeparture x = s.ToObject <ArrivalsAndDeparture>();
                        arrivalsAndDeparture.Add(x);
                    }
                }
            }
            return(arrivalsAndDeparture);
        }