public BusRoute(ConnexionzRoute connectionzRoute, Dictionary <string, GoogleRoute> googleRoute)
        {
            RouteNo = connectionzRoute.RouteNo;

            Path = connectionzRoute.Path
                   .Select(platform => platform.PlatformId)
                   .ToList();

            Color    = googleRoute[RouteNo].Color;
            Url      = googleRoute[RouteNo].Url;
            Polyline = connectionzRoute.Polyline;
        }
Example #2
0
        public static BusRoute Create(ConnexionzRoute connectionzRoute, Dictionary <string, GoogleRoute> googleRoutes)
        {
            var routeNo     = connectionzRoute.RouteNo;
            var googleRoute = googleRoutes[routeNo];
            var path        = connectionzRoute.Path
                              .Select(platform => platform.PlatformId)
                              .ToList();

            var routeUrlSuffix = routeNo switch
            {
                "NON" => "night-owl-north",
                "NOSE" => "night-owl-southeast",
                "NOSW" => "night-owl-southwest",
                _ => routeNo
            };
            var url = "https://www.corvallisoregon.gov/cts/page/cts-route-" + routeUrlSuffix;

            return(new BusRoute(routeNo, path, googleRoute.Color, url, connectionzRoute.Polyline));
        }
Example #3
0
        /// <summary>
        /// Fabricates a bunch of schedule information for a route on a particular day.
        /// </summary>
        private static List <Tuple <int, List <TimeSpan> > > InterpolateSchedule(ConnexionzRoute connexionzRoute, List <GoogleStopSchedule> schedule)
        {
            var adherencePoints = connexionzRoute.Path
                                  .Select((val, idx) => new { value = val, index = idx })
                                  .Where(a => a.value.IsScheduleAdherancePoint)
                                  .ToList();

            // some invariants we can rely on:
            // the first stop is an adherence point.
            // the last stop is not listed as an adherence point, even though it has a schedule in google.
            // therefore, we're going to add the last stop in manually so we can use the last schedule and interpolate.
            adherencePoints.Add(new { value = connexionzRoute.Path.Last(), index = connexionzRoute.Path.Count });

            var results = new List <Tuple <int, List <TimeSpan> > >();

            for (int i = 0; i < adherencePoints.Count - 1; i++)
            {
                int sectionLength  = adherencePoints[i + 1].index - adherencePoints[i].index;
                var stopsInBetween = connexionzRoute.Path.GetRange(adherencePoints[i].index, sectionLength);

                var differences = schedule[i].Times.Zip(schedule[i + 1].Times,
                                                        (startTime, endTime) => endTime.Subtract(startTime));

                // we're simply going to add an even time span the schedules of consecutive stops.
                // there doesn't appear to be a more reliable way of estimating than this.
                var stepSizes = differences.Select(d => d.Ticks / sectionLength);

                results.AddRange(stopsInBetween.Select(
                                     (val, idx) => Tuple.Create(
                                         val.PlatformId,
                                         schedule[i].Times.Zip(stepSizes, (time, step) => RoundToNearestMinute(time.Add(TimeSpan.FromTicks(step * idx))))
                                         .ToList())));
            }

            return(results);
        }