Exemplo n.º 1
0
 private static void SetArrivalTime(int trolleyNumber, StopSummary stopSummary, DateTime timeAtStop)
 {
     if (stopSummary.NextTrolleyArrivalTime.ContainsKey(trolleyNumber))
     {
         stopSummary.NextTrolleyArrivalTime[trolleyNumber] = timeAtStop;
     }
     else
     {
         stopSummary.NextTrolleyArrivalTime.Add(trolleyNumber, timeAtStop);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Test that route path next to this stop is heading in the same direction as trolley,
        /// and not the return path
        /// </summary>
        /// <param name="trackingInfo">Tracking info - CurrentRouteStop and PreviousRouteStop will be assigned here</param>
        /// <param name="currentLocation"></param>
        /// <param name="stopSummary"></param>
        /// <returns></returns>
        private static bool StopIsOnRight(TrolleyTrackingInfo trackingInfo, Coordinate currentLocation, StopSummary stopSummary)
        {
            // Find route direction at our current location (stop)
            var routeStopIndex = FindRouteStopIndex(trackingInfo, stopSummary.ID);

            if (routeStopIndex < 0)
            {
                Debug.WriteLine($"Trolley {trackingInfo.CurrentTrolley.Number} Route Stop Index not found");
                return(false);
            }
            var routeStop = trackingInfo.CurrentRoute.RouteStops[routeStopIndex];
            var numStops  = trackingInfo.CurrentRoute.RouteStops.Count;

            trackingInfo.PreviousRouteStop     = trackingInfo.CurrentRoute.RouteStops[(routeStopIndex + numStops - 1) % numStops];
            trackingInfo.CurrentRouteStop      = routeStop;
            trackingInfo.CurrentRouteStopIndex = routeStopIndex;
            var routeSegmentIndex = routeStop.RouteSegmentIndex;

            if (routeSegmentIndex < 0)
            {
                Debug.WriteLine($"Trolley {trackingInfo.CurrentTrolley.Number} Route Stop Index not set");
                return(false);
            }

            var segmentCount      = trackingInfo.CurrentRoute.Shapes.Count;
            var segmentEnd        = trackingInfo.CurrentRoute.Shapes[routeSegmentIndex];
            var segmentStart      = trackingInfo.CurrentRoute.Shapes[(routeSegmentIndex + segmentCount - 1) % segmentCount];
            var routeSegmentStart = new Coordinate(segmentStart.Lat, segmentStart.Lon);
            var routeSegmentEnd   = new Coordinate(segmentEnd.Lat, segmentEnd.Lon);
            var routeDirection    = routeSegmentStart.DirectionToward(routeSegmentEnd);
            var trolleyDirection  = trackingInfo.CurrentHeading;

            // Convert directions from 0..360 to +/-180 for comparison
            if (routeDirection > 180)
            {
                routeDirection = routeDirection - 360;
            }
            if (trolleyDirection > 180)
            {
                trolleyDirection = trolleyDirection - 360;
            }


            Debug.WriteLine($"Trolley {trackingInfo.CurrentTrolley.Number} Route direction: {routeDirection}, trolley heading: {trolleyDirection}");
            if (Math.Abs((int)routeDirection - trolleyDirection) < 130)
            {
                return(true);
            }
            return(false);
        }